Show player who solved a question

This commit is contained in:
Oliver Rümpelein 2021-08-17 22:47:55 +02:00
parent 0221a43a72
commit 6d9d4a0e3b
5 changed files with 47 additions and 18 deletions

View File

@ -16,6 +16,7 @@ fun EndCard(
playerPointMap: MutableMap<Player, Long>,
close: () -> Unit
) {
// TODO: Style
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxWidth()

View File

@ -1,10 +1,9 @@
package components
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerMoveFilter
@ -18,6 +17,11 @@ private fun Modifier.setButtonSize(heightFraction: Float) = this.fillMaxWidth(1f
.fillMaxHeight(heightFraction)
.padding(5.dp)
data class QuestionResolution(
val answered: Boolean,
val player: Player?
)
@Composable
@Suppress("FunctionName")
fun Question(
@ -30,17 +34,30 @@ fun Question(
onPointsChange: (Player, Long) -> Unit,
onResolve: () -> Unit
) {
// TODO: Indicate who answered the question
var questionVisible by remember { mutableStateOf(false) }
var questionResolved by remember { mutableStateOf(false) }
var questionResolution by remember { mutableStateOf(QuestionResolution(false, null)) }
var pointsButtonActive by remember { mutableStateOf(false) }
if (questionResolved) {
if (questionResolution.answered) {
Surface(
shape = MaterialTheme.shapes.small,
modifier = Modifier
.setButtonSize(heightFraction),
color = Color.LightGray
) { }
color = Color.LightGray,
) {
val player = questionResolution.player
if (player != null) {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(text = "Answered by")
Text(text = player.name)
}
}
}
} else {
Button(
shape = MaterialTheme.shapes.small,
@ -74,7 +91,7 @@ fun Question(
players = players,
secondRoundDouble = secondRoundDouble,
onResolve = {
questionResolved = true
questionResolution = it
questionVisible = false
onResolve()
},

View File

@ -7,6 +7,7 @@ import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.UndecoratedWindowAlertDialogProvider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import components.QuestionResolution
import data.Player
import data.QuestionData
import data.Topic
@ -19,7 +20,7 @@ fun QuestionDialogue(
questionData: QuestionData,
players: List<Player>,
secondRoundDouble: Boolean,
onResolve: () -> Unit,
onResolve: (QuestionResolution) -> Unit,
onPointsChange: (Player, Long) -> Unit
) {
AlertDialog(

View File

@ -8,6 +8,7 @@ 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.questiondialog.assets.HintText
import components.questiondialog.buttons.DismissButton
import components.questiondialog.player.DeferredDoubleQuestionDialogPlayer
@ -24,11 +25,11 @@ fun QuestionDialogButtons(
questionData: QuestionData,
players: List<Player>,
onPointsChange: (Player, Long) -> Unit,
onResolve: () -> Unit,
onResolve: (QuestionResolution) -> Unit,
secondRoundDouble: Boolean
) {
val fontSize = 5.em
var questionAnswered by remember { mutableStateOf<Pair<Boolean, Player?>>(false to null) }
var questionAnswered by remember { mutableStateOf(QuestionResolution(false, null)) }
Box(
modifier = Modifier.fillMaxHeight().fillMaxWidth()
@ -54,11 +55,11 @@ fun QuestionDialogButtons(
DeferredDoubleQuestionDialogPlayer(
player = player,
fontSize = fontSize,
allowedToAnswer = !(questionAnswered.first) || player == questionAnswered.second,
allowedToAnswer = !(questionAnswered.answered) || player == questionAnswered.player,
onPointsChange = onPointsChange,
questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(),
onQuestionDone = onResolve,
onQuestionAnswered = { questionAnswered = true to it }
onQuestionDone = { onResolve(questionAnswered) },
onQuestionAnswered = { questionAnswered = QuestionResolution(true, it) }
)
} else {
QuestionDialogPlayer(
@ -67,14 +68,23 @@ fun QuestionDialogButtons(
onPointsChange = onPointsChange,
questionPoints = questionData.actualUsagePoints(secondRoundDouble).toLong(),
onQuestionAnswered = {
questionAnswered = true to it
onResolve()
val answer = QuestionResolution(true, it)
questionAnswered = answer
onResolve(answer)
}
)
}
}
Spacer(Modifier.height(20.dp))
DismissButton(onResolve, fontSize)
DismissButton(
fontSize = fontSize,
onResolve = {
onResolve(
QuestionResolution(true, null)
)
}
)
}
}
}

View File

@ -18,8 +18,8 @@ import data.Player
fun DeferredDoubleQuestionDialogPlayer(
player: Player,
fontSize: TextUnit,
onPointsChange: (Player, Long) -> Unit,
allowedToAnswer: Boolean,
onPointsChange: (Player, Long) -> Unit,
onQuestionDone: () -> Unit,
onQuestionAnswered: (Player) -> Unit,
questionPoints: Long