75 lines
2.5 KiB
Kotlin
75 lines
2.5 KiB
Kotlin
package components.questiondialog
|
|
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.Spacer
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.width
|
|
import androidx.compose.material.Button
|
|
import androidx.compose.material.ButtonDefaults
|
|
import androidx.compose.material.Text
|
|
import androidx.compose.runtime.*
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.unit.TextUnit
|
|
import androidx.compose.ui.unit.dp
|
|
import components.common.DisabledButton
|
|
import data.Player
|
|
import data.QuestionData
|
|
|
|
@Suppress("FunctionName")
|
|
@Composable
|
|
fun QuestionDialogPlayer(
|
|
player: Player,
|
|
fontSize: TextUnit,
|
|
questionData: QuestionData,
|
|
onPointsChange: (Player, Long) -> Unit,
|
|
questionPoints: Long
|
|
) {
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
verticalAlignment = Alignment.CenterVertically
|
|
) {
|
|
var hadSuccess by remember { mutableStateOf(false) }
|
|
var hadFail by remember { mutableStateOf(false) }
|
|
Text(
|
|
text = player.name,
|
|
modifier = Modifier.fillMaxWidth(0.6f),
|
|
fontSize = fontSize
|
|
)
|
|
Spacer(modifier = Modifier.width(5.dp))
|
|
if (hadFail || (hadSuccess && !questionData.isDeferredDouble)) {
|
|
DisabledButton(maxWidthFraction = 1f, fontSize = fontSize)
|
|
} else {
|
|
if (hadSuccess && questionData.isDeferredDouble) {
|
|
DisabledButton(0.7f, fontSize)
|
|
} else {
|
|
Button(
|
|
modifier = Modifier.fillMaxWidth(0.7f),
|
|
onClick = {
|
|
hadFail = true
|
|
onPointsChange(
|
|
player,
|
|
-questionPoints
|
|
)
|
|
},
|
|
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red)
|
|
) {
|
|
Text("Wrong", color = Color.White, fontSize = fontSize)
|
|
}
|
|
}
|
|
Spacer(modifier = Modifier.width(5.dp))
|
|
Button(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
onClick = {
|
|
hadSuccess = true
|
|
onPointsChange(player, questionPoints)
|
|
},
|
|
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Green)
|
|
) {
|
|
Text("OK", color = Color.White, fontSize = fontSize)
|
|
}
|
|
}
|
|
}
|
|
}
|