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 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.Column
import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -24,7 +23,6 @@ import com.pixelized.rplexicon.ui.theme.LexiconTheme
@Stable @Stable
data class PassivesUio( data class PassivesUio(
val speed: Int,
val perception: Int, val perception: Int,
val investigation: Int, val investigation: Int,
val insight: Int, val insight: Int,
@ -35,7 +33,7 @@ fun Passives(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
padding: PaddingValues = PaddingValues(all = 4.dp), padding: PaddingValues = PaddingValues(all = 4.dp),
titleStyle: TextStyle = MaterialTheme.typography.labelSmall, titleStyle: TextStyle = MaterialTheme.typography.labelSmall,
titleWeight: FontWeight = FontWeight.Light, titleWeight: FontWeight = FontWeight.Medium,
valueStyle: TextStyle = MaterialTheme.typography.headlineMedium, valueStyle: TextStyle = MaterialTheme.typography.headlineMedium,
valueWeight: FontWeight = FontWeight.Medium, valueWeight: FontWeight = FontWeight.Medium,
passives: PassivesUio, passives: PassivesUio,
@ -45,25 +43,9 @@ fun Passives(
.fillMaxWidth() .fillMaxWidth()
.padding(padding) .padding(padding)
.then(other = modifier), .then(other = modifier),
horizontalArrangement = Arrangement.SpaceAround,
verticalAlignment = Alignment.Bottom,
) { ) {
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.weight(weight = 1f),
) {
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(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
Text( Text(
@ -79,6 +61,7 @@ fun Passives(
) )
} }
Column( Column(
modifier = Modifier.weight(weight = 1f),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
Text( Text(
@ -94,6 +77,7 @@ fun Passives(
) )
} }
Column( Column(
modifier = Modifier.weight(weight = 1f),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
Text( Text(
@ -118,7 +102,6 @@ private fun PassivesPreview() {
Surface { Surface {
Passives( Passives(
passives = PassivesUio( passives = PassivesUio(
speed = 10,
perception = 19, perception = 19,
investigation = 8, investigation = 8,
insight = 14, insight = 14,

View file

@ -178,11 +178,14 @@ fun rememberCharacterSheetStatePreview() = remember {
), ),
), ),
passives = PassivesUio( passives = PassivesUio(
speed = 10,
perception = 19, perception = 19,
investigation = 9, investigation = 9,
insight = 14, insight = 14,
), ),
speed = LabelPointUio(
label = R.string.character_sheet_title_speed,
value = "10m",
),
masteries = MasteriesUio( masteries = MasteriesUio(
martial = listOf("Common & war weapons", "Light & Medium & Heavy Armors"), martial = listOf("Common & war weapons", "Light & Medium & Heavy Armors"),
languages = listOf("Common", "Orc", "Elvish"), 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.passivesBonus
import com.pixelized.rplexicon.utilitary.extentions.local.sum import com.pixelized.rplexicon.utilitary.extentions.local.sum
import com.pixelized.rplexicon.utilitary.extentions.modifier import com.pixelized.rplexicon.utilitary.extentions.modifier
import com.pixelized.rplexicon.utilitary.extentions.toLabel
import javax.inject.Inject import javax.inject.Inject
class CharacterSheetUioFactory @Inject constructor() { class CharacterSheetUioFactory @Inject constructor() {
@ -193,7 +192,6 @@ class CharacterSheetUioFactory @Inject constructor() {
), ),
), ),
passives = PassivesUio( passives = PassivesUio(
speed = sheet.speed,
perception = status[Property.PERCEPTION].let { perception = status[Property.PERCEPTION].let {
10 + wisdom.modifier + it.sum + sheet.perception * proficiency + it.passivesBonus 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 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( masteries = MasteriesUio(
martial = sheet.martial, martial = sheet.martial,
languages = sheet.languages, 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_NO
import android.content.res.Configuration.UI_MODE_NIGHT_YES import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.ScrollState import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn 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.layout.layoutId
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
@ -57,6 +58,7 @@ data class CharacterSheetUio(
val savingThrows: List<ProficiencyUio>, val savingThrows: List<ProficiencyUio>,
val proficiencies: List<ProficiencyUio>, val proficiencies: List<ProficiencyUio>,
val masteries: MasteriesUio, val masteries: MasteriesUio,
val speed: LabelPointUio,
val passives: PassivesUio, val passives: PassivesUio,
) )
@ -153,6 +155,19 @@ fun ProficiencyPageContent(
text = stringResource(id = R.string.character_sheet_title_proficiencies) 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( Passives(
passives = sheet.passives, passives = sheet.passives,
@ -181,6 +196,7 @@ private fun ProficiencyLayout(
stats: @Composable ColumnScope.() -> Unit, stats: @Composable ColumnScope.() -> Unit,
savingThrows: @Composable ColumnScope.() -> Unit, savingThrows: @Composable ColumnScope.() -> Unit,
proficiencies: @Composable ColumnScope.() -> Unit, proficiencies: @Composable ColumnScope.() -> Unit,
speed: @Composable ColumnScope.() -> Unit,
passives: @Composable ColumnScope.() -> Unit, passives: @Composable ColumnScope.() -> Unit,
masteries: @Composable ColumnScope.() -> Unit, masteries: @Composable ColumnScope.() -> Unit,
) { ) {
@ -207,6 +223,13 @@ private fun ProficiencyLayout(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
content = proficiencies, content = proficiencies,
) )
Column(
modifier = Modifier
.layoutId("SpeedId")
.ddBorder(inner = inner, outline = outline),
content = speed,
horizontalAlignment = Alignment.CenterHorizontally,
)
Column( Column(
modifier = Modifier modifier = Modifier
.layoutId("PassivesId") .layoutId("PassivesId")
@ -225,31 +248,42 @@ private fun ProficiencyLayout(
val spacingPx = with(density) { spacing.toPx().toInt() } val spacingPx = with(density) { spacing.toPx().toInt() }
val statsWidth = with(density) { 100.dp.toPx().toInt() } val statsWidth = with(density) { 100.dp.toPx().toInt() }
val passivesMeasure = measurables.passives.measure(
constraints = constraints
)
val proficienciesWidth = constraints.maxWidth - statsWidth - spacingPx val proficienciesWidth = constraints.maxWidth - statsWidth - spacingPx
val passivesMeasure = measurables.passives.measure(
constraints = constraints.copy(
minWidth = proficienciesWidth,
maxWidth = proficienciesWidth,
)
)
val savingThrowsMeasure = measurables.savingThrows.measure( val savingThrowsMeasure = measurables.savingThrows.measure(
constraints.copy( constraints = constraints.copy(
minWidth = proficienciesWidth, minWidth = proficienciesWidth,
maxWidth = proficienciesWidth, maxWidth = proficienciesWidth,
) )
) )
val proficienciesMeasure = measurables.proficiencies.measure( val proficienciesMeasure = measurables.proficiencies.measure(
constraints.copy( constraints = constraints.copy(
minWidth = proficienciesWidth, minWidth = proficienciesWidth,
maxWidth = proficienciesWidth, maxWidth = proficienciesWidth,
) )
) )
val statsHeight = savingThrowsMeasure.height + proficienciesMeasure.height + spacingPx val statsHeight = savingThrowsMeasure.height + proficienciesMeasure.height + spacingPx
val statsMeasure = measurables.stats.measure( val statsMeasure = measurables.stats.measure(
constraints.copy( constraints = constraints.copy(
minWidth = statsWidth, minWidth = statsWidth,
maxWidth = statsWidth, maxWidth = statsWidth,
minHeight = statsHeight, minHeight = statsHeight,
maxHeight = 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) val masteriesMeasure = measurables.masteries.measure(constraints)
layout( layout(
@ -268,10 +302,14 @@ private fun ProficiencyLayout(
x = statsWidth + spacingPx, x = statsWidth + spacingPx,
y = savingThrowsMeasure.height + spacingPx, y = savingThrowsMeasure.height + spacingPx,
) )
passivesMeasure.place( speedMeasure.place(
x = 0, x = 0,
y = statsHeight + spacingPx, y = statsHeight + spacingPx,
) )
passivesMeasure.place(
x = statsWidth + spacingPx,
y = savingThrowsMeasure.height + proficienciesMeasure.height + spacingPx * 2,
)
masteriesMeasure.place( masteriesMeasure.place(
x = 0, x = 0,
y = passivesMeasure.height + statsHeight + spacingPx * 2, 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>.stats get() = first { it.layoutId == "StatsId" }
val List<Measurable>.savingThrows get() = first { it.layoutId == "SavingThrowsId" } val List<Measurable>.savingThrows get() = first { it.layoutId == "SavingThrowsId" }
val List<Measurable>.proficiencies get() = first { it.layoutId == "ProficienciesId" } 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>.passives get() = first { it.layoutId == "PassivesId" }
val List<Measurable>.masteries get() = first { it.layoutId == "MasteriesId" }
@Composable @Composable
@Preview(uiMode = UI_MODE_NIGHT_NO, heightDp = 1300) @Preview(uiMode = UI_MODE_NIGHT_NO, heightDp = 1300)