feat: 积分榜详情增加查看出牌记录按钮
This commit is contained in:
parent
145a432f7d
commit
33dad2192a
@ -67,7 +67,8 @@ data class ScoreEntry(
|
||||
val turnNumber: Int,
|
||||
val date: Long,
|
||||
val scoreDetail: String? = "",
|
||||
val opponentDetail: String? = ""
|
||||
val opponentDetail: String? = "",
|
||||
val gameLogJson: String? = ""
|
||||
)
|
||||
|
||||
object Scoreboard {
|
||||
@ -97,7 +98,8 @@ object Scoreboard {
|
||||
playerCount: Int,
|
||||
turnNumber: Int,
|
||||
scoreDetail: String = "",
|
||||
opponentDetail: String = ""
|
||||
opponentDetail: String = "",
|
||||
gameLogJson: String = ""
|
||||
) {
|
||||
val scores = loadScores(context).toMutableList()
|
||||
scores.add(
|
||||
@ -111,7 +113,8 @@ object Scoreboard {
|
||||
turnNumber = turnNumber,
|
||||
date = System.currentTimeMillis(),
|
||||
scoreDetail = scoreDetail,
|
||||
opponentDetail = opponentDetail
|
||||
opponentDetail = opponentDetail,
|
||||
gameLogJson = gameLogJson
|
||||
)
|
||||
)
|
||||
saveScores(context, scores.sortedByDescending { it.points }.take(50))
|
||||
@ -222,7 +225,8 @@ fun LocalGameScreen(
|
||||
playerCount = totalPlayers,
|
||||
turnNumber = gameTurnNumber,
|
||||
scoreDetail = detailStr,
|
||||
opponentDetail = opponentDetails
|
||||
opponentDetail = opponentDetails,
|
||||
gameLogJson = Gson().toJson(gameLog)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.unogame.game.GameMode
|
||||
import com.unogame.ui.theme.*
|
||||
import java.text.SimpleDateFormat
|
||||
@ -44,6 +45,8 @@ fun ScoreboardScreen(onBack: () -> Unit) {
|
||||
|
||||
var showDetailDialog by remember { mutableStateOf(false) }
|
||||
var detailEntry by remember { mutableStateOf<ScoreEntry?>(null) }
|
||||
var showLogViewDialog by remember { mutableStateOf(false) }
|
||||
var logViewEntry by remember { mutableStateOf<ScoreEntry?>(null) }
|
||||
var showImportDialog by remember { mutableStateOf(false) }
|
||||
var importJson by remember { mutableStateOf("") }
|
||||
var showMenu by remember { mutableStateOf(false) }
|
||||
@ -338,14 +341,64 @@ fun ScoreboardScreen(onBack: () -> Unit) {
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
Row {
|
||||
// 查看出牌记录
|
||||
val hasLog = (detailEntry?.gameLogJson ?: "").isNotEmpty()
|
||||
if (hasLog) {
|
||||
TextButton(onClick = {
|
||||
showDetailDialog = false
|
||||
logViewEntry = detailEntry
|
||||
showLogViewDialog = true
|
||||
}) { Text("出牌记录", color = GoldAccent, fontSize = 13.sp) }
|
||||
}
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
TextButton(onClick = { showDetailDialog = false }) {
|
||||
Text("关闭", color = GoldAccent)
|
||||
}
|
||||
}
|
||||
},
|
||||
containerColor = DarkSurface
|
||||
)
|
||||
}
|
||||
|
||||
// 出牌记录查看弹窗
|
||||
if (showLogViewDialog && logViewEntry != null) {
|
||||
val entry = logViewEntry!!
|
||||
val logMsgs: List<String> = try {
|
||||
val listType = object : TypeToken<List<String>>() {}.type
|
||||
gson.fromJson((entry.gameLogJson ?: ""), listType) ?: emptyList()
|
||||
} catch (_: Exception) { emptyList() }
|
||||
val creamBg = Color(0xFFFFF8E1)
|
||||
|
||||
AlertDialog(
|
||||
modifier = Modifier.fillMaxWidth(0.95f),
|
||||
onDismissRequest = { showLogViewDialog = false },
|
||||
title = { Text("${entry.name} — 出牌记录", color = Color(0xFF333333), fontWeight = FontWeight.Bold) },
|
||||
text = {
|
||||
if (logMsgs.isEmpty()) {
|
||||
Text("无记录", color = Color(0xFF555555), fontSize = 13.sp)
|
||||
} else {
|
||||
LazyColumn(modifier = Modifier.height(440.dp)) {
|
||||
itemsIndexed(logMsgs) { index, msg ->
|
||||
Text(
|
||||
"${logMsgs.size - index}. $msg",
|
||||
color = Color(0xFF555555),
|
||||
fontSize = 13.sp,
|
||||
modifier = Modifier.padding(vertical = 2.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = { showLogViewDialog = false }) {
|
||||
Text("关闭", color = Color(0xFF333333))
|
||||
}
|
||||
},
|
||||
containerColor = creamBg
|
||||
)
|
||||
}
|
||||
|
||||
// Import dialog
|
||||
if (showImportDialog) {
|
||||
AlertDialog(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user