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(),
onDismissRequest = { },
buttons = {
QuestionDialogButtons(
QuestionDialogContent(
topic = topic.topic,
topicColor = topic.color,
questionData = questionData,

View File

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