Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compact header #303

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.material.icons.rounded.Edit
import androidx.compose.material.icons.rounded.ExpandMore
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
Expand All @@ -28,6 +29,7 @@ import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.screen.Screen
import cz.frantisekmasa.wfrp_master.common.Str
import cz.frantisekmasa.wfrp_master.common.character.characteristics.CharacteristicsScreen
import cz.frantisekmasa.wfrp_master.common.character.characteristics.CompendiumCareer
import cz.frantisekmasa.wfrp_master.common.character.combat.CharacterCombatScreen
import cz.frantisekmasa.wfrp_master.common.character.conditions.ConditionsScreen
import cz.frantisekmasa.wfrp_master.common.character.notes.NotesScreen
Expand Down Expand Up @@ -105,7 +107,8 @@ data class CharacterDetailScreen(
title = {
CharacterTitle(
partyId = state.characterId.partyId,
partyName = state.partyName,
// TODO: Use separate field in top level state
career = state.characteristicsScreenState.compendiumCareer,
character = state.character,
currentTab = currentTab,
isGameMaster = state.isGameMaster,
Expand Down Expand Up @@ -141,9 +144,9 @@ data class CharacterDetailScreen(
@Composable
private fun CharacterTitle(
partyId: PartyId,
partyName: String,
state: CharacterPickerState,
character: Character,
career: CompendiumCareer?,
assignCharacter: suspend (Character, UserId) -> Unit,
currentTab: CharacterTab?,
isGameMaster: Boolean,
Expand All @@ -152,6 +155,9 @@ data class CharacterDetailScreen(
val canAddCharacters = !isGameMaster
val navigation = LocalNavigationTransaction.current

val subtitle = ((character.race?.let { "${it.localizedName} " } ?: "") +
careerName(career, character)).takeIf { it.isNotBlank() }

if (state.allCharacters.isNotEmpty() || canAddCharacters) {
var unassignedCharactersDialogOpened by remember { mutableStateOf(false) }

Expand Down Expand Up @@ -187,7 +193,7 @@ data class CharacterDetailScreen(
) {
Column {
Text(character.name)
Subtitle(partyName)
subtitle?.let { Subtitle(it) }
}

if (state.allCharacters.size > 1 || canAddCharacters) {
Expand Down Expand Up @@ -255,7 +261,7 @@ data class CharacterDetailScreen(
} else {
Column {
Text(character.name)
Subtitle(partyName)
subtitle?.let { Subtitle(it) }
}
}
}
Expand Down Expand Up @@ -398,3 +404,15 @@ private fun SkeletonScaffold() {
FullScreenProgress()
}
}

@Stable
private fun careerName(
career: CompendiumCareer?,
character: Character,
): String {
if (career == null) {
return character.career
}

return career.level.name
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import cz.frantisekmasa.wfrp_master.common.core.domain.Characteristic
import cz.frantisekmasa.wfrp_master.common.core.domain.Expression
import cz.frantisekmasa.wfrp_master.common.core.domain.Stats
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Character
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CurrentConditions
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Points
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Points.PointPool
import cz.frantisekmasa.wfrp_master.common.core.domain.identifiers.CharacterId
Expand Down Expand Up @@ -196,20 +197,6 @@ private fun CharacterTopPanel(
Modifier.padding(start = Spacing.medium),
horizontalAlignment = Alignment.End,
) {
Text(
character.name,
style = MaterialTheme.typography.h6,
softWrap = false,
overflow = TextOverflow.Ellipsis,
)
Text(
(character.race?.let { "${it.localizedName} " } ?: "") +
careerName(career, character),
style = MaterialTheme.typography.caption,
softWrap = false,
overflow = TextOverflow.Ellipsis,
)

WoundsBadge(character, points, update = onUpdate)
}
}
Expand All @@ -220,18 +207,6 @@ private fun CharacterTopPanel(
}
}

@Stable
private fun careerName(
career: CompendiumCareer?,
character: Character,
): String {
if (career == null) {
return character.career
}

return career.level.name
}

@Composable
private fun WoundsBadge(
character: Character,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -64,8 +65,8 @@ fun ItemIcon(
VISUAL_ONLY_ICON_DESCRIPTION,
modifier =
modifier
.clip(CircleShape)
.background(backgroundColor, CircleShape)
.clip(RoundedCornerShape(Spacing.small))
.background(backgroundColor, RoundedCornerShape(Spacing.small))
.width(dimensions)
.height(dimensions),
)
Expand Down Expand Up @@ -109,7 +110,7 @@ private fun ItemIcon(
colorFilter = ColorFilter.tint(tint),
modifier =
Modifier
.background(backgroundColor, CircleShape)
.background(backgroundColor, RoundedCornerShape(Spacing.small))
.padding(size.padding)
.width(size.dimensions)
.height(size.dimensions),
Expand Down
Loading