From 9eaf6f54ef60adb43f1000f6065b2f04d0f6519c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Wed, 1 Sep 2021 17:54:03 +0200 Subject: [PATCH] Add answer card --- .../components/questiondialog/AnswerBox.kt | 17 +++++ .../questiondialog/QuestionDialog.kt | 2 +- .../questiondialog/QuestionDialogContent.kt | 68 +++++++++++-------- 3 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 src/main/kotlin/components/questiondialog/AnswerBox.kt diff --git a/src/main/kotlin/components/questiondialog/AnswerBox.kt b/src/main/kotlin/components/questiondialog/AnswerBox.kt new file mode 100644 index 0000000..2beb81c --- /dev/null +++ b/src/main/kotlin/components/questiondialog/AnswerBox.kt @@ -0,0 +1,17 @@ +package components.questiondialog + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.unit.em + +@Composable +@Suppress("FunctionName") +fun AnswerBox(answer: String) { + Row() { + Column() { + Text(text = answer, fontSize = 3.em) + } + } +} diff --git a/src/main/kotlin/components/questiondialog/QuestionDialog.kt b/src/main/kotlin/components/questiondialog/QuestionDialog.kt index 220acf6..66552ad 100644 --- a/src/main/kotlin/components/questiondialog/QuestionDialog.kt +++ b/src/main/kotlin/components/questiondialog/QuestionDialog.kt @@ -29,7 +29,7 @@ fun QuestionDialogue( .fillMaxHeight(), onDismissRequest = { }, buttons = { - QuestionDialogButtons( + QuestionDialogContent( topic = topic.topic, topicColor = topic.color, questionData = questionData, diff --git a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt index 4166bc6..835a05f 100644 --- a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt +++ b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt @@ -12,11 +12,14 @@ import components.questiondialog.assets.HintText import components.questiondialog.buttons.DismissButton import components.questiondialog.player.DeferredDoubleQuestionDialogPlayer import components.questiondialog.player.QuestionDialogPlayer -import data.* +import data.ColorData +import data.Player +import data.QuestionData +import data.toColorOrDefault @Suppress("FunctionName") @Composable -fun QuestionDialogButtons( +fun QuestionDialogContent( topic: String, topicColor: ColorData?, questionData: QuestionData, @@ -26,6 +29,7 @@ fun QuestionDialogButtons( secondRoundDouble: Boolean ) { val fontSize = 5.em + var showAnswer by remember { mutableStateOf(false) } var questionAnswered by remember { mutableStateOf(QuestionResolution(false, null)) } BorderBox(borderColor = topicColor.toColorOrDefault()) { @@ -40,38 +44,46 @@ fun QuestionDialogButtons( deferredDouble = questionData.isDeferredDouble, hint = questionData.hint ) - for (player in players) { - if (questionData.isDeferredDouble) { - DeferredDoubleQuestionDialogPlayer( - player = player, - fontSize = fontSize, - allowedToAnswer = !(questionAnswered.answered) || player == questionAnswered.player, - onPointsChange = onPointsChange, - questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), - onQuestionDone = { onResolve(questionAnswered) }, - onQuestionAnswered = { questionAnswered = QuestionResolution(true, it) } - ) - } else { - QuestionDialogPlayer( - player = player, - fontSize = fontSize, - onPointsChange = onPointsChange, - questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), - onQuestionAnswered = { - val answer = QuestionResolution(true, it) - questionAnswered = answer - onResolve(answer) - } - ) + if (showAnswer) { + AnswerBox(questionData.answer) + } else { + for (player in players) { + if (questionData.isDeferredDouble) { + DeferredDoubleQuestionDialogPlayer( + player = player, + fontSize = fontSize, + allowedToAnswer = !(questionAnswered.answered) || player == questionAnswered.player, + onPointsChange = onPointsChange, + questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), + onQuestionDone = { showAnswer = true }, + onQuestionAnswered = { questionAnswered = QuestionResolution(true, it) } + ) + } else { + QuestionDialogPlayer( + player = player, + fontSize = fontSize, + onPointsChange = onPointsChange, + questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), + onQuestionAnswered = { + val answer = QuestionResolution(true, it) + questionAnswered = answer + showAnswer = true + } + ) + } } } Spacer(Modifier.height(20.dp)) DismissButton( fontSize = fontSize, onResolve = { - onResolve( - QuestionResolution(true, null) - ) + if (showAnswer) { + onResolve( + QuestionResolution(true, null) + ) + } else { + showAnswer = true + } } ) }