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