From 0221a43a725a1117513051bff7eb2ec3a48a3e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Tue, 17 Aug 2021 22:11:33 +0200 Subject: [PATCH] Deferred Questions disable players for second guess. --- .../questiondialog/QuestionDialogContent.kt | 14 ++++++++++---- .../player/DeferredDoubleQuestionDialogPlayer.kt | 9 ++++++--- .../questiondialog/player/QuestionDialogPlayer.kt | 6 ++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt index d69bb19..dedd8cb 100644 --- a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt +++ b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt @@ -3,7 +3,7 @@ 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.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @@ -28,6 +28,7 @@ fun QuestionDialogButtons( secondRoundDouble: Boolean ) { val fontSize = 5.em + var questionAnswered by remember { mutableStateOf>(false to null) } Box( modifier = Modifier.fillMaxHeight().fillMaxWidth() @@ -53,9 +54,11 @@ fun QuestionDialogButtons( DeferredDoubleQuestionDialogPlayer( player = player, fontSize = fontSize, + allowedToAnswer = !(questionAnswered.first) || player == questionAnswered.second, onPointsChange = onPointsChange, questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), - onQuestionAnswered = onResolve + onQuestionDone = onResolve, + onQuestionAnswered = { questionAnswered = true to it } ) } else { QuestionDialogPlayer( @@ -63,11 +66,14 @@ fun QuestionDialogButtons( fontSize = fontSize, onPointsChange = onPointsChange, questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), - onQuestionAnswered = onResolve + onQuestionAnswered = { + questionAnswered = true to it + onResolve() + } ) } - Spacer(Modifier.height(20.dp)) } + Spacer(Modifier.height(20.dp)) DismissButton(onResolve, fontSize) } } diff --git a/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt b/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt index 9a64226..187882c 100644 --- a/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt +++ b/src/main/kotlin/components/questiondialog/player/DeferredDoubleQuestionDialogPlayer.kt @@ -19,7 +19,9 @@ fun DeferredDoubleQuestionDialogPlayer( player: Player, fontSize: TextUnit, onPointsChange: (Player, Long) -> Unit, - onQuestionAnswered: () -> Unit, + allowedToAnswer: Boolean, + onQuestionDone: () -> Unit, + onQuestionAnswered: (Player) -> Unit, questionPoints: Long ) { Row( @@ -35,7 +37,7 @@ fun DeferredDoubleQuestionDialogPlayer( fontSize = fontSize ) ButtonSpacer() - if (hadFail) { + if (hadFail || !allowedToAnswer) { DisabledButton(maxWidthFraction = 1f, fontSize = fontSize) } else { if (deferredGuess) { @@ -59,6 +61,7 @@ fun DeferredDoubleQuestionDialogPlayer( onClick = { deferredGuess = true onPointsChange(player, questionPoints) + onQuestionAnswered(player) } ) } else { @@ -66,7 +69,7 @@ fun DeferredDoubleQuestionDialogPlayer( fontSize = fontSize, onClick = { onPointsChange(player, questionPoints) - onQuestionAnswered() + onQuestionDone() } ) } diff --git a/src/main/kotlin/components/questiondialog/player/QuestionDialogPlayer.kt b/src/main/kotlin/components/questiondialog/player/QuestionDialogPlayer.kt index dcc4d7f..36642c1 100644 --- a/src/main/kotlin/components/questiondialog/player/QuestionDialogPlayer.kt +++ b/src/main/kotlin/components/questiondialog/player/QuestionDialogPlayer.kt @@ -20,13 +20,14 @@ fun QuestionDialogPlayer( fontSize: TextUnit, onPointsChange: (Player, Long) -> Unit, questionPoints: Long, - onQuestionAnswered: () -> Unit + onQuestionAnswered: (Player) -> Unit ) { Row( modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically ) { var hadFail by remember { mutableStateOf(false) } + Text( text = player.name, modifier = Modifier.fillMaxWidth(0.6f), @@ -36,6 +37,7 @@ fun QuestionDialogPlayer( if (hadFail) { DisabledButton(maxWidthFraction = 1f, fontSize = fontSize) } else { + // TODO: Implement "answer" view BadAnswerButton( fontSize = fontSize, onClick = { @@ -51,7 +53,7 @@ fun QuestionDialogPlayer( fontSize = fontSize, onClick = { onPointsChange(player, questionPoints) - onQuestionAnswered() + onQuestionAnswered(player) } ) }