106 lines
3.3 KiB
Kotlin
106 lines
3.3 KiB
Kotlin
package components
|
|
|
|
import androidx.compose.foundation.BorderStroke
|
|
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
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.em
|
|
import components.questiondialog.QuestionDialogue
|
|
import data.Player
|
|
import data.QuestionData
|
|
import data.Topic
|
|
import data.toColorOrDefault
|
|
|
|
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(
|
|
questionData: QuestionData,
|
|
secondRoundDouble: Boolean,
|
|
players: List<Player>,
|
|
topic: Topic,
|
|
questionResolved: QuestionResolution,
|
|
heightFraction: Float,
|
|
color: Color,
|
|
onPointsChange: (Player, Long) -> Unit,
|
|
onResolve: (QuestionData, QuestionResolution) -> Unit,
|
|
) {
|
|
var questionVisible by remember { mutableStateOf(false) }
|
|
var pointsButtonActive by remember { mutableStateOf(false) }
|
|
|
|
if (questionResolved.answered) {
|
|
val player = questionResolved.player
|
|
val borderStroke = player?.let { it.color.toColorOrDefault() } ?: Color.LightGray
|
|
Surface(
|
|
shape = MaterialTheme.shapes.small,
|
|
modifier = Modifier
|
|
.setButtonSize(heightFraction),
|
|
color = Color.LightGray,
|
|
border = BorderStroke(10.dp, borderStroke)
|
|
) {
|
|
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,
|
|
colors = ButtonDefaults.buttonColors(
|
|
backgroundColor = color
|
|
),
|
|
onClick = { questionVisible = true },
|
|
modifier = Modifier
|
|
.setButtonSize(heightFraction)
|
|
.pointerMoveFilter(
|
|
onEnter = {
|
|
pointsButtonActive = true
|
|
false
|
|
},
|
|
onExit = {
|
|
pointsButtonActive = false
|
|
false
|
|
}
|
|
)
|
|
) {
|
|
Text(
|
|
text = "${questionData.actualDisplayPoints(secondRoundDouble)}",
|
|
fontSize = 3.em,
|
|
color = if (pointsButtonActive) Color.Gray else Color.White
|
|
)
|
|
}
|
|
}
|
|
if (questionVisible) {
|
|
QuestionDialogue(
|
|
topic = topic,
|
|
questionData = questionData,
|
|
players = players,
|
|
secondRoundDouble = secondRoundDouble,
|
|
onResolve = {
|
|
questionVisible = false
|
|
onResolve(questionData, it)
|
|
},
|
|
onPointsChange = onPointsChange
|
|
)
|
|
}
|
|
}
|