diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 9f86969..a3bd286 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -103,7 +103,7 @@ fun main() = application { val playerPointMap: MutableMap = game.players.map { it to 0L }.toMutableStateMap() var questionsPlayed by remember { mutableStateOf(0) } - val doublePoints by remember { derivedStateOf { questionsPlayed >= game.doubleAfter } } + val secondRoundDouble by remember { derivedStateOf { questionsPlayed >= game.doubleAfter } } val gameEnded by remember { derivedStateOf { questionsPlayed >= game.endGameAfter } } if (!gameEnded) { @@ -123,10 +123,10 @@ fun main() = application { Column(Modifier.fillMaxWidth(0.8f)) { QuestionGrid( game, - doublePoints, + secondRoundDouble, onResolveQuestion = { questionsPlayed++ - println("Questions: $questionsPlayed, Double: $doublePoints") + println("Questions: $questionsPlayed, Double: $secondRoundDouble") }, onPointsChange = { player, points -> playerPointMap[player] = playerPointMap[player]?.plus(points) ?: 0 diff --git a/src/main/kotlin/components/Question.kt b/src/main/kotlin/components/Question.kt index 02510ae..eb869a8 100644 --- a/src/main/kotlin/components/Question.kt +++ b/src/main/kotlin/components/Question.kt @@ -22,7 +22,7 @@ private fun Modifier.setButtonSize(heightFraction: Float) = this.fillMaxWidth(1f @Suppress("FunctionName") fun Question( questionData: QuestionData, - doublePoints: Boolean, + secondRoundDouble: Boolean, players: List, topic: Topic, heightFraction: Float, @@ -62,7 +62,7 @@ fun Question( ) ) { Text( - text = "${questionData.actualDisplayPoints(doublePoints)}", + text = "${questionData.actualDisplayPoints(secondRoundDouble)}", color = if (pointsButtonActive) Color.Gray else Color.LightGray ) } @@ -72,7 +72,7 @@ fun Question( topic = topic, questionData = questionData, players = players, - doublePoints = doublePoints, + secondRoundDouble = secondRoundDouble, onResolve = { questionResolved = true questionVisible = false diff --git a/src/main/kotlin/components/QuestionGrid.kt b/src/main/kotlin/components/QuestionGrid.kt index b4b50bf..e112a78 100644 --- a/src/main/kotlin/components/QuestionGrid.kt +++ b/src/main/kotlin/components/QuestionGrid.kt @@ -9,7 +9,7 @@ import data.Player @Composable fun QuestionGrid( game: Game, - doublePoints: Boolean, + secondRoundDouble: Boolean, onPointsChange: (player: Player, points: Long) -> Unit, onResolveQuestion: () -> Unit ) { @@ -21,7 +21,7 @@ fun QuestionGrid( val maxColumnFraction = 1f / (numberOfColumns - index) TopicRow( topic = topic, - doublePoints = doublePoints, + secondRoundDouble = secondRoundDouble, users = users, columnFraction = maxColumnFraction, onPointsChange = onPointsChange, diff --git a/src/main/kotlin/components/TopicRow.kt b/src/main/kotlin/components/TopicRow.kt index 07b626f..db91948 100644 --- a/src/main/kotlin/components/TopicRow.kt +++ b/src/main/kotlin/components/TopicRow.kt @@ -17,7 +17,7 @@ import data.toColor @Suppress("FunctionName") fun TopicRow( topic: Topic, - doublePoints: Boolean, + secondRoundDouble: Boolean, users: List, columnFraction: Float, onPointsChange: (Player, Long) -> Unit, @@ -49,7 +49,7 @@ fun TopicRow( Question( questionData = question, topic = topic, - doublePoints = doublePoints, + secondRoundDouble = secondRoundDouble, players = users, heightFraction = buttonHeightFraction, color = topicColor, diff --git a/src/main/kotlin/components/questiondialog/QuestionDialog.kt b/src/main/kotlin/components/questiondialog/QuestionDialog.kt index 464bc86..cdbaa0a 100644 --- a/src/main/kotlin/components/questiondialog/QuestionDialog.kt +++ b/src/main/kotlin/components/questiondialog/QuestionDialog.kt @@ -7,7 +7,6 @@ import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.UndecoratedWindowAlertDialogProvider import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import components.QuestionDialogButtons import data.Player import data.QuestionData import data.Topic @@ -19,7 +18,7 @@ fun QuestionDialogue( topic: Topic, questionData: QuestionData, players: List, - doublePoints: Boolean, + secondRoundDouble: Boolean, onResolve: () -> Unit, onPointsChange: (Player, Long) -> Unit ) { @@ -35,7 +34,7 @@ fun QuestionDialogue( players = players, onPointsChange = onPointsChange, onResolve = onResolve, - doublePoints = doublePoints + secondRoundDouble = secondRoundDouble ) } ) diff --git a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt new file mode 100644 index 0000000..d69bb19 --- /dev/null +++ b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt @@ -0,0 +1,74 @@ +package components.questiondialog + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.* +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.em +import components.questiondialog.assets.HintText +import components.questiondialog.buttons.DismissButton +import components.questiondialog.player.DeferredDoubleQuestionDialogPlayer +import components.questiondialog.player.QuestionDialogPlayer +import data.Player +import data.QuestionData +import data.Topic +import data.toColor + +@Suppress("FunctionName") +@Composable +fun QuestionDialogButtons( + topic: Topic, + questionData: QuestionData, + players: List, + onPointsChange: (Player, Long) -> Unit, + onResolve: () -> Unit, + secondRoundDouble: Boolean +) { + val fontSize = 5.em + + Box( + modifier = Modifier.fillMaxHeight().fillMaxWidth() + .border( + border = BorderStroke(150.dp, topic.color.toColor()) + ) + .padding(150.dp), + contentAlignment = Alignment.Center, + ) { + Column( + modifier = Modifier.fillMaxWidth().fillMaxHeight(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.SpaceAround + ) { + HintText( + topicName = topic.topic, + points = questionData.actualUsagePoints(secondRoundDouble), + deferredDouble = questionData.isDeferredDouble, + hint = questionData.hint + ) + for (player in players) { + if (questionData.isDeferredDouble) { + DeferredDoubleQuestionDialogPlayer( + player = player, + fontSize = fontSize, + onPointsChange = onPointsChange, + questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), + onQuestionAnswered = onResolve + ) + } else { + QuestionDialogPlayer( + player = player, + fontSize = fontSize, + onPointsChange = onPointsChange, + questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), + onQuestionAnswered = onResolve + ) + } + Spacer(Modifier.height(20.dp)) + } + DismissButton(onResolve, fontSize) + } + } +} diff --git a/src/main/kotlin/components/questiondialog/QuestionDialogPlayer.kt b/src/main/kotlin/components/questiondialog/QuestionDialogPlayer.kt deleted file mode 100644 index 964380b..0000000 --- a/src/main/kotlin/components/questiondialog/QuestionDialogPlayer.kt +++ /dev/null @@ -1,74 +0,0 @@ -package components.questiondialog - -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.width -import androidx.compose.material.Button -import androidx.compose.material.ButtonDefaults -import androidx.compose.material.Text -import androidx.compose.runtime.* -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.TextUnit -import androidx.compose.ui.unit.dp -import components.common.DisabledButton -import data.Player -import data.QuestionData - -@Suppress("FunctionName") -@Composable -fun QuestionDialogPlayer( - player: Player, - fontSize: TextUnit, - questionData: QuestionData, - onPointsChange: (Player, Long) -> Unit, - questionPoints: Long -) { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically - ) { - var hadSuccess by remember { mutableStateOf(false) } - var hadFail by remember { mutableStateOf(false) } - Text( - text = player.name, - modifier = Modifier.fillMaxWidth(0.6f), - fontSize = fontSize - ) - Spacer(modifier = Modifier.width(5.dp)) - if (hadFail || (hadSuccess && !questionData.isDeferredDouble)) { - DisabledButton(maxWidthFraction = 1f, fontSize = fontSize) - } else { - if (hadSuccess && questionData.isDeferredDouble) { - DisabledButton(0.7f, fontSize) - } else { - Button( - modifier = Modifier.fillMaxWidth(0.7f), - onClick = { - hadFail = true - onPointsChange( - player, - -questionPoints - ) - }, - colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red) - ) { - Text("Wrong", color = Color.White, fontSize = fontSize) - } - } - Spacer(modifier = Modifier.width(5.dp)) - Button( - modifier = Modifier.fillMaxWidth(), - onClick = { - hadSuccess = true - onPointsChange(player, questionPoints) - }, - colors = ButtonDefaults.buttonColors(backgroundColor = Color.Green) - ) { - Text("OK", color = Color.White, fontSize = fontSize) - } - } - } -} diff --git a/src/main/kotlin/components/questiondialog/assets/HintText.kt b/src/main/kotlin/components/questiondialog/assets/HintText.kt new file mode 100644 index 0000000..5895269 --- /dev/null +++ b/src/main/kotlin/components/questiondialog/assets/HintText.kt @@ -0,0 +1,36 @@ +package components.questiondialog.assets + +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.unit.em + +@Composable +@Suppress("FunctionName") +fun HintText( + topicName: String, + points: UInt, + hint: String, + deferredDouble: Boolean = false, + doubleJeopardy: Boolean = false +) { + Text( + text = """"$topicName" for $points Pts.""", + fontSize = 2.em + ) + if (deferredDouble) { + Text( + text = """Deferred Double!""", + fontSize = 3.em + ) + } + if (doubleJeopardy) { + Text( + text = """Double Jeopardy!""", + fontSize = 3.em + ) + } + Text( + text = hint, + fontSize = 5.em + ) +} diff --git a/src/main/kotlin/components/questiondialog/buttons/BadAnswerButton.kt b/src/main/kotlin/components/questiondialog/buttons/BadAnswerButton.kt new file mode 100644 index 0000000..f66b668 --- /dev/null +++ b/src/main/kotlin/components/questiondialog/buttons/BadAnswerButton.kt @@ -0,0 +1,22 @@ +package components.questiondialog.buttons + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.Button +import androidx.compose.material.ButtonDefaults +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.TextUnit + +@Suppress("FunctionName") +@Composable +fun BadAnswerButton(onClick: () -> Unit, fontSize: TextUnit) { + Button( + modifier = Modifier.fillMaxWidth(0.7f), + onClick = onClick, + colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red) + ) { + Text("Wrong", color = Color.White, fontSize = fontSize) + } +} diff --git a/src/main/kotlin/components/questiondialog/buttons/ButtonSpacer.kt b/src/main/kotlin/components/questiondialog/buttons/ButtonSpacer.kt new file mode 100644 index 0000000..73cf089 --- /dev/null +++ b/src/main/kotlin/components/questiondialog/buttons/ButtonSpacer.kt @@ -0,0 +1,13 @@ +package components.questiondialog.buttons + +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp + +@Suppress("FunctionName") +@Composable +fun ButtonSpacer() { + Spacer(modifier = Modifier.width(5.dp)) +} diff --git a/src/main/kotlin/components/questiondialog/buttons/DismissButton.kt b/src/main/kotlin/components/questiondialog/buttons/DismissButton.kt new file mode 100644 index 0000000..1d4e7eb --- /dev/null +++ b/src/main/kotlin/components/questiondialog/buttons/DismissButton.kt @@ -0,0 +1,27 @@ +package components.questiondialog.buttons + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.material.Button +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.TextUnit + +@Suppress("FunctionName") +@Composable +fun DismissButton(onResolve: () -> Unit, fontSize: TextUnit) { + Row( + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + Button( + onClick = { + onResolve() + } + ) { + Text("Dismiss Question", color = Color.LightGray, fontSize = fontSize) + } + } +} diff --git a/src/main/kotlin/components/questiondialog/buttons/GoodAnswerButton.kt b/src/main/kotlin/components/questiondialog/buttons/GoodAnswerButton.kt new file mode 100644 index 0000000..f496c59 --- /dev/null +++ b/src/main/kotlin/components/questiondialog/buttons/GoodAnswerButton.kt @@ -0,0 +1,22 @@ +package components.questiondialog.buttons + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.Button +import androidx.compose.material.ButtonDefaults +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.TextUnit + +@Suppress("FunctionName") +@Composable +fun GoodAnswerButton(onClick: () -> Unit, fontSize: TextUnit) { + Button( + modifier = Modifier.fillMaxWidth(), + onClick = onClick, + colors = ButtonDefaults.buttonColors(backgroundColor = Color.Green) + ) { + Text("OK", color = Color.White, fontSize = fontSize) + } +} diff --git a/src/main/kotlin/components/questiondialog/buttons/QuestionDialogButtons.kt b/src/main/kotlin/components/questiondialog/buttons/QuestionDialogButtons.kt deleted file mode 100644 index 8026336..0000000 --- a/src/main/kotlin/components/questiondialog/buttons/QuestionDialogButtons.kt +++ /dev/null @@ -1,83 +0,0 @@ -package components - -import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.border -import androidx.compose.foundation.layout.* -import androidx.compose.material.Button -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.em -import components.questiondialog.QuestionDialogPlayer -import data.Player -import data.QuestionData -import data.Topic -import data.toColor - -@Suppress("FunctionName") -@Composable -fun QuestionDialogButtons( - topic: Topic, - questionData: QuestionData, - players: List, - onPointsChange: (Player, Long) -> Unit, - onResolve: () -> Unit, - doublePoints: Boolean -) { - val fontSize = 5.em - - Box( - modifier = Modifier.fillMaxHeight().fillMaxWidth() - .border( - border = BorderStroke(150.dp, topic.color.toColor()) - ) - .padding(150.dp), - contentAlignment = Alignment.Center, - ) { - Column( - modifier = Modifier.fillMaxWidth().fillMaxHeight(), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.SpaceAround - ) { - Text( - text = """"${topic.topic}" for ${questionData.actualUsagePoints(doublePoints)} Pts.""", - fontSize = 2.em - ) - if (questionData.isDeferredDouble) { - Text( - text = """Deferred Double!""", - fontSize = 3.em - ) - } - Text( - text = questionData.hint, - fontSize = 5.em - ) - for (player in players) { - QuestionDialogPlayer( - player = player, - fontSize = fontSize, - questionData = questionData, - onPointsChange = onPointsChange, - questionPoints = questionData.actualUsagePoints(doublePoints).toLong() - ) - Spacer(Modifier.height(20.dp)) - } - Row( - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically - ) { - Button( - onClick = { - onResolve() - } - ) { - Text("Dismiss", color = Color.LightGray, fontSize = fontSize) - } - } - } - } -} diff --git a/src/main/kotlin/components/questiondialog/buttons/QuestionDialogDeferredButtons.kt b/src/main/kotlin/components/questiondialog/buttons/QuestionDialogDeferredButtons.kt deleted file mode 100644 index 0acc7e0..0000000 --- a/src/main/kotlin/components/questiondialog/buttons/QuestionDialogDeferredButtons.kt +++ /dev/null @@ -1,83 +0,0 @@ -package components.questiondialog.buttons - -import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.border -import androidx.compose.foundation.layout.* -import androidx.compose.material.Button -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.em -import components.questiondialog.QuestionDialogPlayer -import data.Player -import data.QuestionData -import data.Topic -import data.toColor - -@Suppress("FunctionName") -@Composable -fun QuestionDialogDeferredButtons( - topic: Topic, - questionData: QuestionData, - players: List, - onPointsChange: (Player, Long) -> Unit, - onResolve: () -> Unit, - doublePoints: Boolean -) { - val fontSize = 5.em - - Box( - modifier = Modifier.fillMaxHeight().fillMaxWidth() - .border( - border = BorderStroke(150.dp, topic.color.toColor()) - ) - .padding(150.dp), - contentAlignment = Alignment.Center, - ) { - Column( - modifier = Modifier.fillMaxWidth().fillMaxHeight(), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.SpaceAround - ) { - Text( - text = """"${topic.topic}" for ${questionData.actualUsagePoints(doublePoints)} Pts.""", - fontSize = 2.em - ) - if (questionData.isDeferredDouble) { - Text( - text = """Deferred Double!""", - fontSize = 3.em - ) - } - Text( - text = questionData.hint, - fontSize = 5.em - ) - for (player in players) { - QuestionDialogPlayer( - player = player, - fontSize = fontSize, - questionData = questionData, - onPointsChange = onPointsChange, - questionPoints = questionData.actualUsagePoints(doublePoints).toLong() - ) - Spacer(Modifier.height(20.dp)) - } - Row( - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically - ) { - Button( - onClick = { - onResolve() - } - ) { - Text("Dismiss", color = Color.LightGray, fontSize = fontSize) - } - } - } - } -} diff --git a/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt b/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt new file mode 100644 index 0000000..9a64226 --- /dev/null +++ b/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt @@ -0,0 +1,75 @@ +package components.questiondialog.player + +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.TextUnit +import components.common.DisabledButton +import components.questiondialog.buttons.BadAnswerButton +import components.questiondialog.buttons.ButtonSpacer +import components.questiondialog.buttons.GoodAnswerButton +import data.Player + +@Suppress("FunctionName") +@Composable +fun DeferredDoubleQuestionDialogPlayer( + player: Player, + fontSize: TextUnit, + onPointsChange: (Player, Long) -> Unit, + onQuestionAnswered: () -> Unit, + questionPoints: Long +) { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically + ) { + var deferredGuess by remember { mutableStateOf(false) } + var hadFail by remember { mutableStateOf(false) } + + Text( + text = player.name, + modifier = Modifier.fillMaxWidth(0.6f), + fontSize = fontSize + ) + ButtonSpacer() + if (hadFail) { + DisabledButton(maxWidthFraction = 1f, fontSize = fontSize) + } else { + if (deferredGuess) { + DisabledButton(0.7f, fontSize) + } else { + BadAnswerButton( + fontSize = fontSize, + onClick = { + hadFail = true + onPointsChange( + player, + -questionPoints + ) + } + ) + } + ButtonSpacer() + if (!deferredGuess) { + GoodAnswerButton( + fontSize = fontSize, + onClick = { + deferredGuess = true + onPointsChange(player, questionPoints) + } + ) + } else { + GoodAnswerButton( + fontSize = fontSize, + onClick = { + onPointsChange(player, questionPoints) + onQuestionAnswered() + } + ) + } + } + } +} diff --git a/src/main/kotlin/components/questiondialog/player/QuestionDialogPlayer.kt b/src/main/kotlin/components/questiondialog/player/QuestionDialogPlayer.kt new file mode 100644 index 0000000..dcc4d7f --- /dev/null +++ b/src/main/kotlin/components/questiondialog/player/QuestionDialogPlayer.kt @@ -0,0 +1,59 @@ +package components.questiondialog.player + +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.TextUnit +import components.common.DisabledButton +import components.questiondialog.buttons.BadAnswerButton +import components.questiondialog.buttons.ButtonSpacer +import components.questiondialog.buttons.GoodAnswerButton +import data.Player + +@Suppress("FunctionName") +@Composable +fun QuestionDialogPlayer( + player: Player, + fontSize: TextUnit, + onPointsChange: (Player, Long) -> Unit, + questionPoints: Long, + onQuestionAnswered: () -> Unit +) { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically + ) { + var hadFail by remember { mutableStateOf(false) } + Text( + text = player.name, + modifier = Modifier.fillMaxWidth(0.6f), + fontSize = fontSize + ) + ButtonSpacer() + if (hadFail) { + DisabledButton(maxWidthFraction = 1f, fontSize = fontSize) + } else { + BadAnswerButton( + fontSize = fontSize, + onClick = { + hadFail = true + onPointsChange( + player, + -questionPoints + ) + } + ) + ButtonSpacer() + GoodAnswerButton( + fontSize = fontSize, + onClick = { + onPointsChange(player, questionPoints) + onQuestionAnswered() + } + ) + } + } +}