85 lines
2.6 KiB
Kotlin
85 lines
2.6 KiB
Kotlin
package components
|
|
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.material.*
|
|
import androidx.compose.runtime.*
|
|
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 components.questiondialog.QuestionDialogue
|
|
import data.Player
|
|
import data.QuestionData
|
|
import data.Topic
|
|
|
|
private fun Modifier.setButtonSize(heightFraction: Float) = this.fillMaxWidth(1f)
|
|
.fillMaxHeight(heightFraction)
|
|
.padding(5.dp)
|
|
|
|
@Composable
|
|
@Suppress("FunctionName")
|
|
fun Question(
|
|
questionData: QuestionData,
|
|
doublePoints: Boolean,
|
|
players: List<Player>,
|
|
topic: Topic,
|
|
heightFraction: Float,
|
|
color: Color,
|
|
onPointsChange: (Player, Long) -> Unit,
|
|
onResolve: () -> Unit
|
|
) {
|
|
var questionVisible by remember { mutableStateOf(false) }
|
|
var questionResolved by remember { mutableStateOf(false) }
|
|
var pointsButtonActive by remember { mutableStateOf(false) }
|
|
|
|
if (questionResolved) {
|
|
Surface(
|
|
shape = MaterialTheme.shapes.small,
|
|
modifier = Modifier
|
|
.setButtonSize(heightFraction),
|
|
color = Color.LightGray
|
|
) { }
|
|
} 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(doublePoints)}",
|
|
color = if (pointsButtonActive) Color.Gray else Color.LightGray
|
|
)
|
|
}
|
|
}
|
|
if (questionVisible) {
|
|
QuestionDialogue(
|
|
topic = topic,
|
|
questionData = questionData,
|
|
players = players,
|
|
doublePoints = doublePoints,
|
|
onResolve = {
|
|
questionResolved = true
|
|
questionVisible = false
|
|
onResolve()
|
|
},
|
|
onPointsChange = onPointsChange
|
|
)
|
|
}
|
|
}
|