Add answer card
This commit is contained in:
parent
6fb0bf1885
commit
9eaf6f54ef
3 changed files with 58 additions and 29 deletions
17
src/main/kotlin/components/questiondialog/AnswerBox.kt
Normal file
17
src/main/kotlin/components/questiondialog/AnswerBox.kt
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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,
|
||||||
|
|
|
@ -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,6 +44,9 @@ fun QuestionDialogButtons(
|
||||||
deferredDouble = questionData.isDeferredDouble,
|
deferredDouble = questionData.isDeferredDouble,
|
||||||
hint = questionData.hint
|
hint = questionData.hint
|
||||||
)
|
)
|
||||||
|
if (showAnswer) {
|
||||||
|
AnswerBox(questionData.answer)
|
||||||
|
} else {
|
||||||
for (player in players) {
|
for (player in players) {
|
||||||
if (questionData.isDeferredDouble) {
|
if (questionData.isDeferredDouble) {
|
||||||
DeferredDoubleQuestionDialogPlayer(
|
DeferredDoubleQuestionDialogPlayer(
|
||||||
|
@ -48,7 +55,7 @@ fun QuestionDialogButtons(
|
||||||
allowedToAnswer = !(questionAnswered.answered) || player == questionAnswered.player,
|
allowedToAnswer = !(questionAnswered.answered) || player == questionAnswered.player,
|
||||||
onPointsChange = onPointsChange,
|
onPointsChange = onPointsChange,
|
||||||
questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(),
|
questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(),
|
||||||
onQuestionDone = { onResolve(questionAnswered) },
|
onQuestionDone = { showAnswer = true },
|
||||||
onQuestionAnswered = { questionAnswered = QuestionResolution(true, it) }
|
onQuestionAnswered = { questionAnswered = QuestionResolution(true, it) }
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -60,18 +67,23 @@ fun QuestionDialogButtons(
|
||||||
onQuestionAnswered = {
|
onQuestionAnswered = {
|
||||||
val answer = QuestionResolution(true, it)
|
val answer = QuestionResolution(true, it)
|
||||||
questionAnswered = answer
|
questionAnswered = answer
|
||||||
onResolve(answer)
|
showAnswer = true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Spacer(Modifier.height(20.dp))
|
Spacer(Modifier.height(20.dp))
|
||||||
DismissButton(
|
DismissButton(
|
||||||
fontSize = fontSize,
|
fontSize = fontSize,
|
||||||
onResolve = {
|
onResolve = {
|
||||||
|
if (showAnswer) {
|
||||||
onResolve(
|
onResolve(
|
||||||
QuestionResolution(true, null)
|
QuestionResolution(true, null)
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
showAnswer = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue