Add alteration support for diminished status.
This commit is contained in:
parent
17b7b06ec8
commit
51a477bb58
5 changed files with 66 additions and 29 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<String, List<FieldAlteration>> = 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)}" }
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue