Add answer card

This commit is contained in:
Oliver Rümpelein 2021-09-01 17:54:03 +02:00
parent 6fb0bf1885
commit 9eaf6f54ef
3 changed files with 58 additions and 29 deletions

View File

@ -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)
}
}
}

View File

@ -29,7 +29,7 @@ fun QuestionDialogue(
.fillMaxHeight(), .fillMaxHeight(),
onDismissRequest = { }, onDismissRequest = { },
buttons = { buttons = {
QuestionDialogButtons( QuestionDialogContent(
topic = topic.topic, topic = topic.topic,
topicColor = topic.color, topicColor = topic.color,
questionData = questionData, questionData = questionData,

View File

@ -12,11 +12,14 @@ 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.* import data.ColorData
import data.Player
import data.QuestionData
import data.toColorOrDefault
@Suppress("FunctionName") @Suppress("FunctionName")
@Composable @Composable
fun QuestionDialogButtons( fun QuestionDialogContent(
topic: String, topic: String,
topicColor: ColorData?, topicColor: ColorData?,
questionData: QuestionData, questionData: QuestionData,
@ -26,6 +29,7 @@ fun QuestionDialogButtons(
secondRoundDouble: Boolean secondRoundDouble: Boolean
) { ) {
val fontSize = 5.em val fontSize = 5.em
var showAnswer by remember { mutableStateOf(false) }
var questionAnswered by remember { mutableStateOf(QuestionResolution(false, null)) } var questionAnswered by remember { mutableStateOf(QuestionResolution(false, null)) }
BorderBox(borderColor = topicColor.toColorOrDefault()) { BorderBox(borderColor = topicColor.toColorOrDefault()) {
@ -40,38 +44,46 @@ fun QuestionDialogButtons(
deferredDouble = questionData.isDeferredDouble, deferredDouble = questionData.isDeferredDouble,
hint = questionData.hint hint = questionData.hint
) )
for (player in players) { if (showAnswer) {
if (questionData.isDeferredDouble) { AnswerBox(questionData.answer)
DeferredDoubleQuestionDialogPlayer( } else {
player = player, for (player in players) {
fontSize = fontSize, if (questionData.isDeferredDouble) {
allowedToAnswer = !(questionAnswered.answered) || player == questionAnswered.player, DeferredDoubleQuestionDialogPlayer(
onPointsChange = onPointsChange, player = player,
questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), fontSize = fontSize,
onQuestionDone = { onResolve(questionAnswered) }, allowedToAnswer = !(questionAnswered.answered) || player == questionAnswered.player,
onQuestionAnswered = { questionAnswered = QuestionResolution(true, it) } onPointsChange = onPointsChange,
) questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(),
} else { onQuestionDone = { showAnswer = true },
QuestionDialogPlayer( onQuestionAnswered = { questionAnswered = QuestionResolution(true, it) }
player = player, )
fontSize = fontSize, } else {
onPointsChange = onPointsChange, QuestionDialogPlayer(
questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(), player = player,
onQuestionAnswered = { fontSize = fontSize,
val answer = QuestionResolution(true, it) onPointsChange = onPointsChange,
questionAnswered = answer questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(),
onResolve(answer) onQuestionAnswered = {
} val answer = QuestionResolution(true, it)
) questionAnswered = answer
showAnswer = true
}
)
}
} }
} }
Spacer(Modifier.height(20.dp)) Spacer(Modifier.height(20.dp))
DismissButton( DismissButton(
fontSize = fontSize, fontSize = fontSize,
onResolve = { onResolve = {
onResolve( if (showAnswer) {
QuestionResolution(true, null) onResolve(
) QuestionResolution(true, null)
)
} else {
showAnswer = true
}
} }
) )
} }