Change the layout of the passive data in the character sheet.

This commit is contained in:
Thomas Andres Gomez 2023-12-22 11:38:44 +01:00
parent 35fcb23028
commit cc9c0460f0
4 changed files with 60 additions and 33 deletions

View file

@ -1,6 +1,5 @@
package com.pixelized.rplexicon.ui.screens.character.composable.character
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
@ -24,7 +23,6 @@ import com.pixelized.rplexicon.ui.theme.LexiconTheme
@Stable
data class PassivesUio(
val speed: Int,
val perception: Int,
val investigation: Int,
val insight: Int,
@ -35,7 +33,7 @@ fun Passives(
modifier: Modifier = Modifier,
padding: PaddingValues = PaddingValues(all = 4.dp),
titleStyle: TextStyle = MaterialTheme.typography.labelSmall,
titleWeight: FontWeight = FontWeight.Light,
titleWeight: FontWeight = FontWeight.Medium,
valueStyle: TextStyle = MaterialTheme.typography.headlineMedium,
valueWeight: FontWeight = FontWeight.Medium,
passives: PassivesUio,
@ -45,25 +43,9 @@ fun Passives(
.fillMaxWidth()
.padding(padding)
.then(other = modifier),
horizontalArrangement = Arrangement.SpaceAround,
verticalAlignment = Alignment.Bottom,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
style = titleStyle,
fontWeight = titleWeight,
textAlign = TextAlign.Center,
text = stringResource(id = R.string.character_sheet_title_speed),
)
Text(
style = valueStyle,
fontWeight = valueWeight,
text = "${passives.speed}m"
)
}
Column(
modifier = Modifier.weight(weight = 1f),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
@ -79,6 +61,7 @@ fun Passives(
)
}
Column(
modifier = Modifier.weight(weight = 1f),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
@ -94,6 +77,7 @@ fun Passives(
)
}
Column(
modifier = Modifier.weight(weight = 1f),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(
@ -118,7 +102,6 @@ private fun PassivesPreview() {
Surface {
Passives(
passives = PassivesUio(
speed = 10,
perception = 19,
investigation = 8,
insight = 14,

View file

@ -178,11 +178,14 @@ fun rememberCharacterSheetStatePreview() = remember {
),
),
passives = PassivesUio(
speed = 10,
perception = 19,
investigation = 9,
insight = 14,
),
speed = LabelPointUio(
label = R.string.character_sheet_title_speed,
value = "10m",
),
masteries = MasteriesUio(
martial = listOf("Common & war weapons", "Light & Medium & Heavy Armors"),
languages = listOf("Common", "Orc", "Elvish"),

View file

@ -13,7 +13,6 @@ import com.pixelized.rplexicon.ui.screens.character.pages.proficiency.CharacterS
import com.pixelized.rplexicon.utilitary.extentions.local.passivesBonus
import com.pixelized.rplexicon.utilitary.extentions.local.sum
import com.pixelized.rplexicon.utilitary.extentions.modifier
import com.pixelized.rplexicon.utilitary.extentions.toLabel
import javax.inject.Inject
class CharacterSheetUioFactory @Inject constructor() {
@ -193,7 +192,6 @@ class CharacterSheetUioFactory @Inject constructor() {
),
),
passives = PassivesUio(
speed = sheet.speed,
perception = status[Property.PERCEPTION].let {
10 + wisdom.modifier + it.sum + sheet.perception * proficiency + it.passivesBonus
},
@ -204,6 +202,10 @@ class CharacterSheetUioFactory @Inject constructor() {
10 + wisdom.modifier + it.sum + sheet.insight * proficiency + it.passivesBonus
},
),
speed = LabelPointUio(
label = R.string.character_sheet_title_speed,
value = "${sheet.speed}m",
),
masteries = MasteriesUio(
martial = sheet.martial,
languages = sheet.languages,

View file

@ -3,11 +3,11 @@ package com.pixelized.rplexicon.ui.screens.character.pages.proficiency
import android.content.res.Configuration.UI_MODE_NIGHT_NO
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn
@ -30,6 +30,7 @@ import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
@ -57,6 +58,7 @@ data class CharacterSheetUio(
val savingThrows: List<ProficiencyUio>,
val proficiencies: List<ProficiencyUio>,
val masteries: MasteriesUio,
val speed: LabelPointUio,
val passives: PassivesUio,
)
@ -153,6 +155,19 @@ fun ProficiencyPageContent(
text = stringResource(id = R.string.character_sheet_title_proficiencies)
)
},
speed = {
Text(
modifier = Modifier.padding(top = 4.dp),
style = MaterialTheme.typography.labelSmall,
textAlign = TextAlign.Center,
text = sheet.speed.label?.let { stringResource(id = it) } ?: ""
)
Text(
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Medium,
text = sheet.speed.value ?: ""
)
},
passives = {
Passives(
passives = sheet.passives,
@ -181,6 +196,7 @@ private fun ProficiencyLayout(
stats: @Composable ColumnScope.() -> Unit,
savingThrows: @Composable ColumnScope.() -> Unit,
proficiencies: @Composable ColumnScope.() -> Unit,
speed: @Composable ColumnScope.() -> Unit,
passives: @Composable ColumnScope.() -> Unit,
masteries: @Composable ColumnScope.() -> Unit,
) {
@ -207,6 +223,13 @@ private fun ProficiencyLayout(
horizontalAlignment = Alignment.CenterHorizontally,
content = proficiencies,
)
Column(
modifier = Modifier
.layoutId("SpeedId")
.ddBorder(inner = inner, outline = outline),
content = speed,
horizontalAlignment = Alignment.CenterHorizontally,
)
Column(
modifier = Modifier
.layoutId("PassivesId")
@ -225,31 +248,42 @@ private fun ProficiencyLayout(
val spacingPx = with(density) { spacing.toPx().toInt() }
val statsWidth = with(density) { 100.dp.toPx().toInt() }
val passivesMeasure = measurables.passives.measure(
constraints = constraints
)
val proficienciesWidth = constraints.maxWidth - statsWidth - spacingPx
val passivesMeasure = measurables.passives.measure(
constraints = constraints.copy(
minWidth = proficienciesWidth,
maxWidth = proficienciesWidth,
)
)
val savingThrowsMeasure = measurables.savingThrows.measure(
constraints.copy(
constraints = constraints.copy(
minWidth = proficienciesWidth,
maxWidth = proficienciesWidth,
)
)
val proficienciesMeasure = measurables.proficiencies.measure(
constraints.copy(
constraints = constraints.copy(
minWidth = proficienciesWidth,
maxWidth = proficienciesWidth,
)
)
val statsHeight = savingThrowsMeasure.height + proficienciesMeasure.height + spacingPx
val statsMeasure = measurables.stats.measure(
constraints.copy(
constraints = constraints.copy(
minWidth = statsWidth,
maxWidth = statsWidth,
minHeight = statsHeight,
maxHeight = statsHeight,
)
)
val speedMeasure = measurables.speed.measure(
constraints = constraints.copy(
minWidth = statsWidth,
maxWidth = statsWidth,
minHeight = passivesMeasure.height,
maxHeight = passivesMeasure.height,
)
)
val masteriesMeasure = measurables.masteries.measure(constraints)
layout(
@ -268,10 +302,14 @@ private fun ProficiencyLayout(
x = statsWidth + spacingPx,
y = savingThrowsMeasure.height + spacingPx,
)
passivesMeasure.place(
speedMeasure.place(
x = 0,
y = statsHeight + spacingPx,
)
passivesMeasure.place(
x = statsWidth + spacingPx,
y = savingThrowsMeasure.height + proficienciesMeasure.height + spacingPx * 2,
)
masteriesMeasure.place(
x = 0,
y = passivesMeasure.height + statsHeight + spacingPx * 2,
@ -284,8 +322,9 @@ private fun ProficiencyLayout(
val List<Measurable>.stats get() = first { it.layoutId == "StatsId" }
val List<Measurable>.savingThrows get() = first { it.layoutId == "SavingThrowsId" }
val List<Measurable>.proficiencies get() = first { it.layoutId == "ProficienciesId" }
val List<Measurable>.masteries get() = first { it.layoutId == "MasteriesId" }
val List<Measurable>.speed get() = first { it.layoutId == "SpeedId" }
val List<Measurable>.passives get() = first { it.layoutId == "PassivesId" }
val List<Measurable>.masteries get() = first { it.layoutId == "MasteriesId" }
@Composable
@Preview(uiMode = UI_MODE_NIGHT_NO, heightDp = 1300)