From 6fb0bf188573bc256eccc5c45aa516bd0a5b0cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Sun, 29 Aug 2021 17:30:34 +0200 Subject: [PATCH] Answered Questions are marked with color of player --- game.json | 11 ++++++++--- src/main/kotlin/components/GameHeader.kt | 4 ++-- src/main/kotlin/components/PlayerCard.kt | 4 ++-- src/main/kotlin/components/Question.kt | 6 +++++- src/main/kotlin/components/TopicRow.kt | 7 ++----- src/main/kotlin/components/endcard/EndCard.kt | 6 +++--- .../questiondialog/QuestionDialogContent.kt | 7 ++----- src/main/kotlin/data/ColorData.kt | 5 ++++- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/game.json b/game.json index 8b84dc0..cba23c5 100644 --- a/game.json +++ b/game.json @@ -90,7 +90,12 @@ ], "players": [ { - "name": "P1" + "name": "P1", + "color": { + "red": 255, + "green": 0, + "blue": 0 + } }, { "name": "Playerererer" @@ -99,6 +104,6 @@ "name": "P3" } ], - "doubleAfter": 2, - "endGameAfter": 1 + "doubleAfter": 4, + "endGameAfter": 4 } diff --git a/src/main/kotlin/components/GameHeader.kt b/src/main/kotlin/components/GameHeader.kt index 6bfc4ec..a7e55d2 100644 --- a/src/main/kotlin/components/GameHeader.kt +++ b/src/main/kotlin/components/GameHeader.kt @@ -11,7 +11,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.em import data.ColorData -import data.toColor +import data.toColorOrDefault @Suppress("FunctionName") @Composable @@ -21,7 +21,7 @@ fun GameHeader(title: String, color: ColorData?, onExit: () -> Unit) { .fillMaxWidth() ) { Surface( - color = color.toColor(), + color = color.toColorOrDefault(), modifier = Modifier.fillMaxSize(1f) ) { Column( diff --git a/src/main/kotlin/components/PlayerCard.kt b/src/main/kotlin/components/PlayerCard.kt index 0b8c196..3afdcb6 100644 --- a/src/main/kotlin/components/PlayerCard.kt +++ b/src/main/kotlin/components/PlayerCard.kt @@ -11,7 +11,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.em import data.Player -import data.toColor +import data.toColorOrDefault @Suppress("FunctionName") @Composable @@ -21,7 +21,7 @@ fun PlayerCard( points: Long ) { Surface( - color = player.color.toColor(), + color = player.color.toColorOrDefault(), modifier = Modifier.fillMaxHeight(maxHeightFraction) .fillMaxWidth() .padding(5.dp), diff --git a/src/main/kotlin/components/Question.kt b/src/main/kotlin/components/Question.kt index 93c1f32..57e4ec5 100644 --- a/src/main/kotlin/components/Question.kt +++ b/src/main/kotlin/components/Question.kt @@ -1,5 +1,6 @@ package components +import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.layout.* import androidx.compose.material.* import androidx.compose.runtime.* @@ -13,6 +14,7 @@ import components.questiondialog.QuestionDialogue import data.Player import data.QuestionData import data.Topic +import data.toColorOrDefault private fun Modifier.setButtonSize(heightFraction: Float) = this.fillMaxWidth(1f) .fillMaxHeight(heightFraction) @@ -40,13 +42,15 @@ fun Question( var pointsButtonActive by remember { mutableStateOf(false) } if (questionResolved.answered) { + val player = questionResolved.player + val borderStroke = player?.let { it.color.toColorOrDefault() } ?: Color.LightGray Surface( shape = MaterialTheme.shapes.small, modifier = Modifier .setButtonSize(heightFraction), color = Color.LightGray, + border = BorderStroke(10.dp, borderStroke) ) { - val player = questionResolved.player if (player != null) { Column( modifier = Modifier.fillMaxSize(), diff --git a/src/main/kotlin/components/TopicRow.kt b/src/main/kotlin/components/TopicRow.kt index 80b2798..57432d2 100644 --- a/src/main/kotlin/components/TopicRow.kt +++ b/src/main/kotlin/components/TopicRow.kt @@ -9,10 +9,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.em -import data.Player -import data.QuestionData -import data.Topic -import data.toColor +import data.* @Composable @Suppress("FunctionName") @@ -25,7 +22,7 @@ fun TopicRow( onPointsChange: (Player, Long) -> Unit, onResolveQuestion: (QuestionData, QuestionResolution) -> Unit ) { - val topicColor = topic.color.toColor() + val topicColor = topic.color.toColorOrDefault() Column( modifier = Modifier.fillMaxHeight() .fillMaxWidth(columnFraction) diff --git a/src/main/kotlin/components/endcard/EndCard.kt b/src/main/kotlin/components/endcard/EndCard.kt index 8b86d01..0135737 100644 --- a/src/main/kotlin/components/endcard/EndCard.kt +++ b/src/main/kotlin/components/endcard/EndCard.kt @@ -15,7 +15,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.em import components.common.BorderBox import data.Player -import data.toColor +import data.toColorOrDefault @Suppress("FunctionName") @Composable @@ -29,7 +29,7 @@ fun EndCard( val firstPlayer = sortedPlayersPoints.first() .key BorderBox( - borderColor = firstPlayer.color.toColor() + borderColor = firstPlayer.color.toColorOrDefault() ) { Column( horizontalAlignment = Alignment.CenterHorizontally, @@ -71,7 +71,7 @@ fun HighScoreListEntry( fontSize: TextUnit ) { Box( - modifier = Modifier.border(border = BorderStroke(5.dp, player.color.toColor())) + modifier = Modifier.border(border = BorderStroke(5.dp, player.color.toColorOrDefault())) .padding(10.dp), contentAlignment = Alignment.Center ) { diff --git a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt index 4f3e23a..4166bc6 100644 --- a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt +++ b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt @@ -12,10 +12,7 @@ import components.questiondialog.assets.HintText import components.questiondialog.buttons.DismissButton import components.questiondialog.player.DeferredDoubleQuestionDialogPlayer import components.questiondialog.player.QuestionDialogPlayer -import data.ColorData -import data.Player -import data.QuestionData -import data.toColor +import data.* @Suppress("FunctionName") @Composable @@ -31,7 +28,7 @@ fun QuestionDialogButtons( val fontSize = 5.em var questionAnswered by remember { mutableStateOf(QuestionResolution(false, null)) } - BorderBox(borderColor = topicColor.toColor()) { + BorderBox(borderColor = topicColor.toColorOrDefault()) { Column( modifier = Modifier.fillMaxWidth().fillMaxHeight(), horizontalAlignment = Alignment.CenterHorizontally, diff --git a/src/main/kotlin/data/ColorData.kt b/src/main/kotlin/data/ColorData.kt index c6728c6..8ea657b 100644 --- a/src/main/kotlin/data/ColorData.kt +++ b/src/main/kotlin/data/ColorData.kt @@ -11,4 +11,7 @@ class ColorData( val alpha: Int = 0xFF ) -fun ColorData?.toColor() = this?.let { Color(it.red, it.green, it.blue, it.alpha) } ?: Color.Blue +fun ColorData?.toColorOrNull() = this?.toColor() +fun ColorData?.toColorOrDefault() = this?.toColor() ?: Color.Blue + +fun ColorData.toColor() = Color(red, green, blue, alpha)