92 lines
3.5 KiB
Kotlin
92 lines
3.5 KiB
Kotlin
package components.questiondialog
|
|
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.runtime.*
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.em
|
|
import components.QuestionResolution
|
|
import components.common.BorderBox
|
|
import components.questiondialog.assets.HintText
|
|
import components.questiondialog.buttons.DismissButton
|
|
import components.questiondialog.player.DeferredDoubleQuestionDialogPlayer
|
|
import components.questiondialog.player.QuestionDialogPlayer
|
|
import data.ColorData
|
|
import data.Player
|
|
import data.QuestionData
|
|
import data.toColorOrDefault
|
|
|
|
@Suppress("FunctionName")
|
|
@Composable
|
|
fun QuestionDialogContent(
|
|
topic: String,
|
|
topicColor: ColorData?,
|
|
questionData: QuestionData,
|
|
players: List<Player>,
|
|
onPointsChange: (Player, Long) -> Unit,
|
|
onResolve: (QuestionResolution) -> Unit,
|
|
secondRoundDouble: Boolean
|
|
) {
|
|
val fontSize = 5.em
|
|
var showAnswer by remember { mutableStateOf(false) }
|
|
var questionAnswered by remember { mutableStateOf(QuestionResolution(false, null)) }
|
|
|
|
BorderBox(borderColor = topicColor.toColorOrDefault()) {
|
|
Column(
|
|
modifier = Modifier.fillMaxWidth().fillMaxHeight(),
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
verticalArrangement = Arrangement.SpaceAround
|
|
) {
|
|
HintText(
|
|
topicName = topic,
|
|
points = questionData.actualUsagePoints(secondRoundDouble),
|
|
deferredDouble = questionData.isDeferredDouble,
|
|
hint = questionData.hint
|
|
)
|
|
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 = {
|
|
if (showAnswer) {
|
|
onResolve(
|
|
QuestionResolution(true, null)
|
|
)
|
|
} else {
|
|
showAnswer = true
|
|
}
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|