diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/diminished/CharacterSheetDiminishedDialog.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/diminished/CharacterSheetDiminishedDialog.kt index 9ca3d7b..b1ed627 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/diminished/CharacterSheetDiminishedDialog.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/diminished/CharacterSheetDiminishedDialog.kt @@ -23,6 +23,7 @@ import androidx.compose.runtime.State import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.SolidColor @@ -45,6 +46,7 @@ data class CharacterSheetDiminishedDialogUio( val label: String, val value: () -> TextFieldValue, val onValueChange: (TextFieldValue) -> Unit, + val additional: String?, ) @Composable @@ -76,6 +78,14 @@ private fun CharacterSheetDiminishedContent( val typography = MaterialTheme.typography val colors = MaterialTheme.colors + val valueTypography = remember { + typography.h5.copy( + color = colors.primary, + textAlign = TextAlign.Center, + fontWeight = FontWeight.Bold + ) + } + val focusRequester = remember { FocusRequester() } LaunchedEffect(Unit) { focusRequester.requestFocus() @@ -107,24 +117,32 @@ private fun CharacterSheetDiminishedContent( style = MaterialTheme.typography.caption, text = dialog.label, ) - BasicTextField( - modifier = Modifier - .focusRequester(focusRequester = focusRequester) - .width(width = 120.dp), - textStyle = remember { - typography.h5.copy( - color = colors.primary, - textAlign = TextAlign.Center, - fontWeight = FontWeight.Bold + Row( + horizontalArrangement = Arrangement.spacedBy( + space = 8.dp, + alignment = Alignment.CenterHorizontally + ) + ) { + BasicTextField( + modifier = Modifier + .focusRequester(focusRequester = focusRequester) + .width(width = 120.dp), + textStyle = valueTypography, + cursorBrush = SolidColor(MaterialTheme.colors.primary), + singleLine = true, + keyboardActions = KeyboardActions { onConfirm(dialog) }, + keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done), + value = dialog.value(), + onValueChange = dialog.onValueChange, + ) + dialog.additional?.let { + Text( + modifier = Modifier.alpha(alpha = 0.66f), + style = valueTypography, + text = it ) - }, - cursorBrush = SolidColor(MaterialTheme.colors.primary), - singleLine = true, - keyboardActions = KeyboardActions { onConfirm(dialog) }, - keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done), - value = dialog.value(), - onValueChange = dialog.onValueChange, - ) + } + } Row( modifier = Modifier .padding(top = 4.dp) diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/diminished/CharacterSheetDiminishedDialogFactory.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/diminished/CharacterSheetDiminishedDialogFactory.kt index 918ca5f..d4baf8c 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/diminished/CharacterSheetDiminishedDialogFactory.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/ui/composable/character/diminished/CharacterSheetDiminishedDialogFactory.kt @@ -6,11 +6,12 @@ import androidx.compose.ui.text.input.TextFieldValue import com.pixelized.desktop.lwa.repository.alteration.AlterationRepository import com.pixelized.desktop.lwa.repository.characterSheet.CharacterSheetRepository import com.pixelized.shared.lwa.model.AlteredCharacterSheetFactory -import com.pixelized.shared.lwa.model.alteration.FieldAlteration import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet +import com.pixelized.shared.lwa.utils.signLabel import lwacharactersheet.composeapp.generated.resources.Res import lwacharactersheet.composeapp.generated.resources.character_sheet__diminished__label import org.jetbrains.compose.resources.getString +import kotlin.math.abs class CharacterSheetDiminishedDialogFactory( private val characterSheetRepository: CharacterSheetRepository, @@ -19,7 +20,7 @@ class CharacterSheetDiminishedDialogFactory( ) { suspend fun convertToDialogUio( characterSheetId: String?, - ) : CharacterSheetDiminishedDialogUio? { + ): CharacterSheetDiminishedDialogUio? { if (characterSheetId == null) return null @@ -29,21 +30,19 @@ class CharacterSheetDiminishedDialogFactory( if (characterSheet == null) return null - val alterations: Map> = alterationRepository.activeFieldAlterations( - characterSheetId = characterSheetId, - ) - val alteredCharacterSheet = alteredCharacterSheetFactory.sheet( characterSheet = characterSheet, - alterations = alterations, + alterations = alterationRepository.activeFieldAlterations( + characterSheetId = characterSheetId + ), ) - val textFieldValue = mutableStateOf( TextFieldValue( - text = "${alteredCharacterSheet.diminished}", + text = "${characterSheet.diminished}", selection = TextRange(index = 0), ) ) + return CharacterSheetDiminishedDialogUio( characterSheetId = characterSheetId, label = getString(resource = Res.string.character_sheet__diminished__label), @@ -54,6 +53,9 @@ class CharacterSheetDiminishedDialogFactory( else -> value } }, + additional = (alteredCharacterSheet.diminishedAlterations) + .takeIf { it != 0 } + ?.let { "${it.signLabel}${abs(it)}" } ) } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/model/AlteredCharacterSheet.kt b/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/model/AlteredCharacterSheet.kt index 3845259..85d5a32 100644 --- a/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/model/AlteredCharacterSheet.kt +++ b/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/model/AlteredCharacterSheet.kt @@ -21,11 +21,11 @@ import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.Characterist import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.CharacteristicId.REFLEX import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.CharacteristicId.STR import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.CharacteristicId.THUMBNAIL -import com.pixelized.shared.lwa.model.inventory.Inventory -import com.pixelized.shared.lwa.model.inventory.Inventory.Item +import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet.StatusId.DIMINISHED import com.pixelized.shared.lwa.parser.expression.Expression import com.pixelized.shared.lwa.usecase.CharacterSheetUseCase import com.pixelized.shared.lwa.usecase.ExpressionUseCase +import kotlin.math.max class AlteredCharacterSheetFactory( private val sheetUseCase: CharacterSheetUseCase, @@ -109,7 +109,10 @@ class AlteredCharacterSheet( get() = sheet.fatigue val diminished: Int - get() = sheet.diminished + get() = max(0, sheet.diminished + diminishedAlterations) + + val diminishedAlterations: Int + get() = fieldAlterations[DIMINISHED].sum() val alterations: List get() = sheet.alterations diff --git a/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/model/characterSheet/CharacterSheet.kt b/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/model/characterSheet/CharacterSheet.kt index d389595..3d5fe99 100644 --- a/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/model/characterSheet/CharacterSheet.kt +++ b/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/model/characterSheet/CharacterSheet.kt @@ -56,6 +56,10 @@ data class CharacterSheet( val critical: String?, ) + object StatusId { + const val DIMINISHED = "DIMINISHED" + } + object CharacteristicId { const val PORTRAIT = "PORTRAIT" const val THUMBNAIL = "THUMBNAIL" diff --git a/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/utils/IntEx+signLabel.kt b/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/utils/IntEx+signLabel.kt new file mode 100644 index 0000000..7e36767 --- /dev/null +++ b/shared/src/commonMain/kotlin/com/pixelized/shared/lwa/utils/IntEx+signLabel.kt @@ -0,0 +1,10 @@ +package com.pixelized.shared.lwa.utils + +import kotlin.math.sign + +val Int.signLabel: Char + get() = when (this.sign) { + 1 -> '+' + -1 -> '-' + else -> ' ' + } \ No newline at end of file