Added proper styling for winners
This commit is contained in:
@@ -41,7 +41,6 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.atridad.magiccounter.ui.state.GameState
|
||||
import com.atridad.magiccounter.ui.state.PlayerState
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
@@ -83,9 +82,6 @@ fun GameScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// Single column for maximum width
|
||||
val numColumns = 1
|
||||
|
||||
fun snapshotState(): GameState = state.copy(
|
||||
players = state.players.map { p ->
|
||||
PlayerState(
|
||||
@@ -104,11 +100,14 @@ fun GameScreen(
|
||||
Column(modifier = modifier.padding(12.dp)) {
|
||||
// Lock game when only one active player remains
|
||||
val aliveCount = state.players.count { eliminated[it.id] != true }
|
||||
if (aliveCount == 1) {
|
||||
val winnerId = state.players.first { eliminated[it.id] != true }.id
|
||||
val currentWinnerId: Int? = if (aliveCount == 1) {
|
||||
state.players.first { eliminated[it.id] != true }.id
|
||||
} else null
|
||||
|
||||
if (currentWinnerId != null) {
|
||||
if (gameLocked["locked"] != true) {
|
||||
gameLocked["locked"] = true
|
||||
onWinner?.invoke(winnerId, snapshotState())
|
||||
onWinner?.invoke(currentWinnerId, snapshotState())
|
||||
}
|
||||
}
|
||||
val displayPlayers = state.players.sortedBy { eliminated[it.id] == true }
|
||||
@@ -169,6 +168,7 @@ fun GameScreen(
|
||||
rotation = 0f,
|
||||
accentColor = accent,
|
||||
isEliminated = eliminated[player.id] == true,
|
||||
isWinner = currentWinnerId == player.id,
|
||||
onScoop = {
|
||||
if (gameLocked["locked"] != true) {
|
||||
eliminated[player.id] = true
|
||||
@@ -211,11 +211,13 @@ private fun PlayerCard(
|
||||
rotation: Float,
|
||||
accentColor: Color,
|
||||
isEliminated: Boolean,
|
||||
isWinner: Boolean,
|
||||
onScoop: () -> Unit
|
||||
) {
|
||||
val targetContainer = if (isEliminated) MaterialTheme.colorScheme.errorContainer else MaterialTheme.colorScheme.surfaceVariant
|
||||
val containerColor = animateColorAsState(targetValue = targetContainer, label = "eliminationColor")
|
||||
val overlayAlpha = animateFloatAsState(targetValue = if (isEliminated) 1f else 0f, label = "overlayAlpha")
|
||||
val controlsEnabled = !isEliminated && !isWinner
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
@@ -224,23 +226,23 @@ private fun PlayerCard(
|
||||
.graphicsLayer { rotationZ = rotation },
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = containerColor.value),
|
||||
border = BorderStroke(2.dp, accentColor)
|
||||
border = BorderStroke(3.dp, if (isWinner) Color(0xFF2E7D32) else accentColor)
|
||||
) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Column(modifier = Modifier.padding(12.dp).alpha(if (isEliminated) 0.45f else 1f), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(player.name, style = MaterialTheme.typography.titleMedium, color = accentColor)
|
||||
TextButton(onClick = onScoop, enabled = !isEliminated) {
|
||||
Text(player.name, style = MaterialTheme.typography.titleMedium, color = if (isWinner) Color(0xFF2E7D32) else accentColor)
|
||||
TextButton(onClick = onScoop, enabled = controlsEnabled) {
|
||||
Icon(Icons.Default.Flag, contentDescription = "Scoop")
|
||||
Text("Scoop")
|
||||
}
|
||||
}
|
||||
|
||||
BigLifeRow(value = life, onChange = onLifeChange, enabled = !isEliminated)
|
||||
BigLifeRow(value = life, onChange = onLifeChange, enabled = controlsEnabled)
|
||||
|
||||
if (trackPoison) ChipRow(label = "Poison", value = poison, onChange = onPoisonChange, enabled = !isEliminated)
|
||||
if (trackEnergy) ChipRow(label = "Energy", value = energy, onChange = onEnergyChange, enabled = !isEliminated)
|
||||
if (trackExperience) ChipRow(label = "Experience", value = experience, onChange = onExperienceChange, enabled = !isEliminated)
|
||||
if (trackPoison) ChipRow(label = "Poison", value = poison, onChange = onPoisonChange, enabled = controlsEnabled)
|
||||
if (trackEnergy) ChipRow(label = "Energy", value = energy, onChange = onEnergyChange, enabled = controlsEnabled)
|
||||
if (trackExperience) ChipRow(label = "Experience", value = experience, onChange = onExperienceChange, enabled = controlsEnabled)
|
||||
|
||||
if (trackCommanderDamage) {
|
||||
Divider()
|
||||
@@ -248,7 +250,7 @@ private fun PlayerCard(
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
opponents.forEach { fromId ->
|
||||
val value = commanderDamages[fromId] ?: 0
|
||||
ChipRow(label = "From P${fromId + 1}", value = value, onChange = { onCommanderDamageChange(fromId, it) }, enabled = !isEliminated)
|
||||
ChipRow(label = "From P${fromId + 1}", value = value, onChange = { onCommanderDamageChange(fromId, it) }, enabled = controlsEnabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user