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>, playerPointMap: MutableMap<Player, Long>,
close: () -> Unit close: () -> Unit
) { ) {
// TODO: Style
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()

View file

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

View file

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

View file

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