diff --git a/src/main/kotlin/components/EndCard.kt b/src/main/kotlin/components/EndCard.kt index 6413806..87ef895 100644 --- a/src/main/kotlin/components/EndCard.kt +++ b/src/main/kotlin/components/EndCard.kt @@ -16,6 +16,7 @@ fun EndCard( playerPointMap: MutableMap, close: () -> Unit ) { + // TODO: Style Box( contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth() diff --git a/src/main/kotlin/components/Question.kt b/src/main/kotlin/components/Question.kt index eb869a8..2dfc8a0 100644 --- a/src/main/kotlin/components/Question.kt +++ b/src/main/kotlin/components/Question.kt @@ -1,10 +1,9 @@ package components -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.material.* import androidx.compose.runtime.* +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerMoveFilter @@ -18,6 +17,11 @@ private fun Modifier.setButtonSize(heightFraction: Float) = this.fillMaxWidth(1f .fillMaxHeight(heightFraction) .padding(5.dp) +data class QuestionResolution( + val answered: Boolean, + val player: Player? +) + @Composable @Suppress("FunctionName") fun Question( @@ -30,17 +34,30 @@ fun Question( onPointsChange: (Player, Long) -> Unit, onResolve: () -> Unit ) { + // TODO: Indicate who answered the question var questionVisible by remember { mutableStateOf(false) } - var questionResolved by remember { mutableStateOf(false) } + var questionResolution by remember { mutableStateOf(QuestionResolution(false, null)) } var pointsButtonActive by remember { mutableStateOf(false) } - if (questionResolved) { + if (questionResolution.answered) { Surface( shape = MaterialTheme.shapes.small, modifier = Modifier .setButtonSize(heightFraction), - color = Color.LightGray - ) { } + color = Color.LightGray, + ) { + val player = questionResolution.player + if (player != null) { + Column( + modifier = Modifier.fillMaxSize(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Text(text = "Answered by") + Text(text = player.name) + } + } + } } else { Button( shape = MaterialTheme.shapes.small, @@ -74,7 +91,7 @@ fun Question( players = players, secondRoundDouble = secondRoundDouble, onResolve = { - questionResolved = true + questionResolution = it questionVisible = false onResolve() }, diff --git a/src/main/kotlin/components/questiondialog/QuestionDialog.kt b/src/main/kotlin/components/questiondialog/QuestionDialog.kt index cdbaa0a..ef547d0 100644 --- a/src/main/kotlin/components/questiondialog/QuestionDialog.kt +++ b/src/main/kotlin/components/questiondialog/QuestionDialog.kt @@ -7,6 +7,7 @@ import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.UndecoratedWindowAlertDialogProvider import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import components.QuestionResolution import data.Player import data.QuestionData import data.Topic @@ -19,7 +20,7 @@ fun QuestionDialogue( questionData: QuestionData, players: List, secondRoundDouble: Boolean, - onResolve: () -> Unit, + onResolve: (QuestionResolution) -> Unit, onPointsChange: (Player, Long) -> Unit ) { AlertDialog( diff --git a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt index dedd8cb..0341946 100644 --- a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt +++ b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt @@ -8,6 +8,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.em +import components.QuestionResolution import components.questiondialog.assets.HintText import components.questiondialog.buttons.DismissButton import components.questiondialog.player.DeferredDoubleQuestionDialogPlayer @@ -24,11 +25,11 @@ fun QuestionDialogButtons( questionData: QuestionData, players: List, onPointsChange: (Player, Long) -> Unit, - onResolve: () -> Unit, + onResolve: (QuestionResolution) -> Unit, secondRoundDouble: Boolean ) { val fontSize = 5.em - var questionAnswered by remember { mutableStateOf>(false to null) } + var questionAnswered by remember { mutableStateOf(QuestionResolution(false, null)) } Box( modifier = Modifier.fillMaxHeight().fillMaxWidth() @@ -54,11 +55,11 @@ fun QuestionDialogButtons( DeferredDoubleQuestionDialogPlayer( player = player, fontSize = fontSize, - allowedToAnswer = !(questionAnswered.first) || player == questionAnswered.second, + allowedToAnswer = !(questionAnswered.answered) || player == questionAnswered.player, onPointsChange = onPointsChange, questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), - onQuestionDone = onResolve, - onQuestionAnswered = { questionAnswered = true to it } + onQuestionDone = { onResolve(questionAnswered) }, + onQuestionAnswered = { questionAnswered = QuestionResolution(true, it) } ) } else { QuestionDialogPlayer( @@ -67,14 +68,23 @@ fun QuestionDialogButtons( onPointsChange = onPointsChange, questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), onQuestionAnswered = { - questionAnswered = true to it - onResolve() + val answer = QuestionResolution(true, it) + questionAnswered = answer + onResolve(answer) } ) } } Spacer(Modifier.height(20.dp)) - DismissButton(onResolve, fontSize) + DismissButton( + fontSize = fontSize, + onResolve = { + onResolve( + QuestionResolution(true, null) + ) + } + ) } } } + diff --git a/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt b/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt index 187882c..5c49197 100644 --- a/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt +++ b/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt @@ -18,8 +18,8 @@ import data.Player fun DeferredDoubleQuestionDialogPlayer( player: Player, fontSize: TextUnit, - onPointsChange: (Player, Long) -> Unit, allowedToAnswer: Boolean, + onPointsChange: (Player, Long) -> Unit, onQuestionDone: () -> Unit, onQuestionAnswered: (Player) -> Unit, questionPoints: Long