Answered Questions are marked with color of player

This commit is contained in:
Oliver Rümpelein 2021-08-29 17:30:34 +02:00
parent 6d5a150ee4
commit 6fb0bf1885
8 changed files with 28 additions and 22 deletions

View file

@ -90,7 +90,12 @@
], ],
"players": [ "players": [
{ {
"name": "P1" "name": "P1",
"color": {
"red": 255,
"green": 0,
"blue": 0
}
}, },
{ {
"name": "Playerererer" "name": "Playerererer"
@ -99,6 +104,6 @@
"name": "P3" "name": "P3"
} }
], ],
"doubleAfter": 2, "doubleAfter": 4,
"endGameAfter": 1 "endGameAfter": 4
} }

View file

@ -11,7 +11,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.em import androidx.compose.ui.unit.em
import data.ColorData import data.ColorData
import data.toColor import data.toColorOrDefault
@Suppress("FunctionName") @Suppress("FunctionName")
@Composable @Composable
@ -21,7 +21,7 @@ fun GameHeader(title: String, color: ColorData?, onExit: () -> Unit) {
.fillMaxWidth() .fillMaxWidth()
) { ) {
Surface( Surface(
color = color.toColor(), color = color.toColorOrDefault(),
modifier = Modifier.fillMaxSize(1f) modifier = Modifier.fillMaxSize(1f)
) { ) {
Column( Column(

View file

@ -11,7 +11,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em import androidx.compose.ui.unit.em
import data.Player import data.Player
import data.toColor import data.toColorOrDefault
@Suppress("FunctionName") @Suppress("FunctionName")
@Composable @Composable
@ -21,7 +21,7 @@ fun PlayerCard(
points: Long points: Long
) { ) {
Surface( Surface(
color = player.color.toColor(), color = player.color.toColorOrDefault(),
modifier = Modifier.fillMaxHeight(maxHeightFraction) modifier = Modifier.fillMaxHeight(maxHeightFraction)
.fillMaxWidth() .fillMaxWidth()
.padding(5.dp), .padding(5.dp),

View file

@ -1,5 +1,6 @@
package components package components
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
@ -13,6 +14,7 @@ import components.questiondialog.QuestionDialogue
import data.Player import data.Player
import data.QuestionData import data.QuestionData
import data.Topic import data.Topic
import data.toColorOrDefault
private fun Modifier.setButtonSize(heightFraction: Float) = this.fillMaxWidth(1f) private fun Modifier.setButtonSize(heightFraction: Float) = this.fillMaxWidth(1f)
.fillMaxHeight(heightFraction) .fillMaxHeight(heightFraction)
@ -40,13 +42,15 @@ fun Question(
var pointsButtonActive by remember { mutableStateOf(false) } var pointsButtonActive by remember { mutableStateOf(false) }
if (questionResolved.answered) { if (questionResolved.answered) {
val player = questionResolved.player
val borderStroke = player?.let { it.color.toColorOrDefault() } ?: Color.LightGray
Surface( Surface(
shape = MaterialTheme.shapes.small, shape = MaterialTheme.shapes.small,
modifier = Modifier modifier = Modifier
.setButtonSize(heightFraction), .setButtonSize(heightFraction),
color = Color.LightGray, color = Color.LightGray,
border = BorderStroke(10.dp, borderStroke)
) { ) {
val player = questionResolved.player
if (player != null) { if (player != null) {
Column( Column(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),

View file

@ -9,10 +9,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.em import androidx.compose.ui.unit.em
import data.Player import data.*
import data.QuestionData
import data.Topic
import data.toColor
@Composable @Composable
@Suppress("FunctionName") @Suppress("FunctionName")
@ -25,7 +22,7 @@ fun TopicRow(
onPointsChange: (Player, Long) -> Unit, onPointsChange: (Player, Long) -> Unit,
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit onResolveQuestion: (QuestionData, QuestionResolution) -> Unit
) { ) {
val topicColor = topic.color.toColor() val topicColor = topic.color.toColorOrDefault()
Column( Column(
modifier = Modifier.fillMaxHeight() modifier = Modifier.fillMaxHeight()
.fillMaxWidth(columnFraction) .fillMaxWidth(columnFraction)

View file

@ -15,7 +15,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em import androidx.compose.ui.unit.em
import components.common.BorderBox import components.common.BorderBox
import data.Player import data.Player
import data.toColor import data.toColorOrDefault
@Suppress("FunctionName") @Suppress("FunctionName")
@Composable @Composable
@ -29,7 +29,7 @@ fun EndCard(
val firstPlayer = sortedPlayersPoints.first() val firstPlayer = sortedPlayersPoints.first()
.key .key
BorderBox( BorderBox(
borderColor = firstPlayer.color.toColor() borderColor = firstPlayer.color.toColorOrDefault()
) { ) {
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
@ -71,7 +71,7 @@ fun HighScoreListEntry(
fontSize: TextUnit fontSize: TextUnit
) { ) {
Box( Box(
modifier = Modifier.border(border = BorderStroke(5.dp, player.color.toColor())) modifier = Modifier.border(border = BorderStroke(5.dp, player.color.toColorOrDefault()))
.padding(10.dp), .padding(10.dp),
contentAlignment = Alignment.Center contentAlignment = Alignment.Center
) { ) {

View file

@ -12,10 +12,7 @@ import components.questiondialog.assets.HintText
import components.questiondialog.buttons.DismissButton import components.questiondialog.buttons.DismissButton
import components.questiondialog.player.DeferredDoubleQuestionDialogPlayer import components.questiondialog.player.DeferredDoubleQuestionDialogPlayer
import components.questiondialog.player.QuestionDialogPlayer import components.questiondialog.player.QuestionDialogPlayer
import data.ColorData import data.*
import data.Player
import data.QuestionData
import data.toColor
@Suppress("FunctionName") @Suppress("FunctionName")
@Composable @Composable
@ -31,7 +28,7 @@ fun QuestionDialogButtons(
val fontSize = 5.em val fontSize = 5.em
var questionAnswered by remember { mutableStateOf(QuestionResolution(false, null)) } var questionAnswered by remember { mutableStateOf(QuestionResolution(false, null)) }
BorderBox(borderColor = topicColor.toColor()) { BorderBox(borderColor = topicColor.toColorOrDefault()) {
Column( Column(
modifier = Modifier.fillMaxWidth().fillMaxHeight(), modifier = Modifier.fillMaxWidth().fillMaxHeight(),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,

View file

@ -11,4 +11,7 @@ class ColorData(
val alpha: Int = 0xFF 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)