Small UI adjustment for the alteration edit GM.
This commit is contained in:
parent
2eabb4f5e4
commit
3182d2b595
4 changed files with 32 additions and 29 deletions
|
|
@ -24,43 +24,45 @@ class GMAlterationEditFactory(
|
||||||
alteration: Alteration?,
|
alteration: Alteration?,
|
||||||
tags: Collection<Tag>,
|
tags: Collection<Tag>,
|
||||||
): GMAlterationEditPageUio {
|
): GMAlterationEditPageUio {
|
||||||
val id = MutableStateFlow(alteration?.id ?: "")
|
val idFlow = MutableStateFlow(alteration?.id ?: "")
|
||||||
val label = MutableStateFlow(alteration?.metadata?.name ?: "")
|
val labelFlow = MutableStateFlow(alteration?.metadata?.name ?: "")
|
||||||
val description = MutableStateFlow(alteration?.metadata?.description ?: "")
|
val descriptionFlow = MutableStateFlow(alteration?.metadata?.description ?: "")
|
||||||
val fields = MutableStateFlow(alteration?.fields?.map { createField(it) } ?: listOf(
|
val tagFlow = MutableStateFlow(
|
||||||
createField(null)
|
tagFactory.convertToGMTagItemUio(
|
||||||
))
|
tags = tags,
|
||||||
|
selectedTagIds = alteration?.tags ?: emptyList(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val fieldsFlow = MutableStateFlow(alteration?.fields?.map { createField(it) }
|
||||||
|
?: listOf(createField(null)))
|
||||||
|
|
||||||
return GMAlterationEditPageUio(
|
return GMAlterationEditPageUio(
|
||||||
id = LwaTextFieldUio(
|
id = LwaTextFieldUio(
|
||||||
enable = originId == null,
|
enable = originId == null,
|
||||||
isError = MutableStateFlow(false),
|
isError = MutableStateFlow(false),
|
||||||
labelFlow = MutableStateFlow(getString(Res.string.game_master__alteration__edit_id)),
|
labelFlow = MutableStateFlow(getString(Res.string.game_master__alteration__edit_id)),
|
||||||
valueFlow = id,
|
valueFlow = idFlow,
|
||||||
placeHolderFlow = null,
|
placeHolderFlow = null,
|
||||||
onValueChange = { id.value = it },
|
onValueChange = { idFlow.value = it },
|
||||||
),
|
),
|
||||||
label = LwaTextFieldUio(
|
label = LwaTextFieldUio(
|
||||||
enable = true,
|
enable = true,
|
||||||
isError = MutableStateFlow(false),
|
isError = MutableStateFlow(false),
|
||||||
labelFlow = MutableStateFlow(getString(Res.string.game_master__alteration__edit_label)),
|
labelFlow = MutableStateFlow(getString(Res.string.game_master__alteration__edit_label)),
|
||||||
valueFlow = label,
|
valueFlow = labelFlow,
|
||||||
placeHolderFlow = null,
|
placeHolderFlow = null,
|
||||||
onValueChange = { label.value = it },
|
onValueChange = { labelFlow.value = it },
|
||||||
),
|
),
|
||||||
description = LwaTextFieldUio(
|
description = LwaTextFieldUio(
|
||||||
enable = true,
|
enable = true,
|
||||||
isError = MutableStateFlow(false),
|
isError = MutableStateFlow(false),
|
||||||
labelFlow = MutableStateFlow(getString(Res.string.game_master__alteration__edit_description)),
|
labelFlow = MutableStateFlow(getString(Res.string.game_master__alteration__edit_description)),
|
||||||
valueFlow = description,
|
valueFlow = descriptionFlow,
|
||||||
placeHolderFlow = null,
|
placeHolderFlow = null,
|
||||||
onValueChange = { description.value = it },
|
onValueChange = { descriptionFlow.value = it },
|
||||||
),
|
),
|
||||||
tags = tagFactory.convertToGMTagItemUio(
|
tags = tagFlow,
|
||||||
tags = tags,
|
fields = fieldsFlow,
|
||||||
selectedTagIds = alteration?.tags ?: emptyList(),
|
|
||||||
),
|
|
||||||
fields = fields,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,7 +104,9 @@ class GMAlterationEditFactory(
|
||||||
name = form.label.valueFlow.value,
|
name = form.label.valueFlow.value,
|
||||||
description = form.description.valueFlow.value,
|
description = form.description.valueFlow.value,
|
||||||
),
|
),
|
||||||
tags = form.tags.filter { it.highlight }.map { it.id },
|
tags = form.tags.value
|
||||||
|
.filter { it.highlight }
|
||||||
|
.map { it.id },
|
||||||
fields = form.fields.value.mapNotNull { field ->
|
fields = form.fields.value.mapNotNull { field ->
|
||||||
expressionParser.parse(input = field.expression.valueFlow.value)?.let {
|
expressionParser.parse(input = field.expression.valueFlow.value)?.let {
|
||||||
Alteration.Field(
|
Alteration.Field(
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ import androidx.compose.ui.input.key.key
|
||||||
import androidx.compose.ui.input.key.type
|
import androidx.compose.ui.input.key.type
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import com.pixelized.desktop.lwa.ui.composable.error.ErrorSnackHandler
|
import com.pixelized.desktop.lwa.ui.composable.error.ErrorSnackHandler
|
||||||
import com.pixelized.desktop.lwa.ui.composable.key.KeyHandler
|
import com.pixelized.desktop.lwa.ui.composable.key.KeyHandler
|
||||||
|
|
@ -82,7 +81,7 @@ data class GMAlterationEditPageUio(
|
||||||
val id: LwaTextFieldUio,
|
val id: LwaTextFieldUio,
|
||||||
val label: LwaTextFieldUio,
|
val label: LwaTextFieldUio,
|
||||||
val description: LwaTextFieldUio,
|
val description: LwaTextFieldUio,
|
||||||
val tags: List<GMTagUio>,
|
val tags: MutableStateFlow<List<GMTagUio>>,
|
||||||
val fields: MutableStateFlow<List<SkillUio>>,
|
val fields: MutableStateFlow<List<SkillUio>>,
|
||||||
) {
|
) {
|
||||||
@Stable
|
@Stable
|
||||||
|
|
@ -210,6 +209,7 @@ private fun GMAlterationEditContent(
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
|
val tags = it.tags.collectAsState()
|
||||||
val fields = it.fields.collectAsState()
|
val fields = it.fields.collectAsState()
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
|
|
@ -266,7 +266,7 @@ private fun GMAlterationEditContent(
|
||||||
horizontalArrangement = Arrangement.spacedBy(space = 8.dp),
|
horizontalArrangement = Arrangement.spacedBy(space = 8.dp),
|
||||||
) {
|
) {
|
||||||
items(
|
items(
|
||||||
items = it.tags,
|
items = tags.value,
|
||||||
) { tag ->
|
) { tag ->
|
||||||
GMTagButton(
|
GMTagButton(
|
||||||
modifier = Modifier.height(48.dp),
|
modifier = Modifier.height(48.dp),
|
||||||
|
|
|
||||||
|
|
@ -81,14 +81,13 @@ class GMAlterationEditViewModel(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addTag(tag: GMTagUio) {
|
fun addTag(tag: GMTagUio) {
|
||||||
_form.update {
|
_form.value?.tags?.update { tags ->
|
||||||
it?.copy(
|
tags.toMutableList().also {
|
||||||
tags = it.tags.toMutableList().also { tags ->
|
val index = it.indexOf(tag)
|
||||||
val index = tags.indexOf(tag)
|
if (index > -1) {
|
||||||
if (index > -1)
|
it[index] = tag.copy(highlight = tag.highlight.not())
|
||||||
tags[index] = tag.copy(highlight = tag.highlight.not())
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +29,7 @@ data class GMTagUio(
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
object GmTagDefault {
|
object GmTagDefault {
|
||||||
val padding = PaddingValues(horizontal = 8.dp, vertical = 2.dp)
|
val padding = PaddingValues(horizontal = 8.dp, vertical = 4.dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue