feat: 积分榜详情增加查看出牌记录按钮
This commit is contained in:
parent
145a432f7d
commit
33dad2192a
@ -67,7 +67,8 @@ data class ScoreEntry(
|
|||||||
val turnNumber: Int,
|
val turnNumber: Int,
|
||||||
val date: Long,
|
val date: Long,
|
||||||
val scoreDetail: String? = "",
|
val scoreDetail: String? = "",
|
||||||
val opponentDetail: String? = ""
|
val opponentDetail: String? = "",
|
||||||
|
val gameLogJson: String? = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
object Scoreboard {
|
object Scoreboard {
|
||||||
@ -97,7 +98,8 @@ object Scoreboard {
|
|||||||
playerCount: Int,
|
playerCount: Int,
|
||||||
turnNumber: Int,
|
turnNumber: Int,
|
||||||
scoreDetail: String = "",
|
scoreDetail: String = "",
|
||||||
opponentDetail: String = ""
|
opponentDetail: String = "",
|
||||||
|
gameLogJson: String = ""
|
||||||
) {
|
) {
|
||||||
val scores = loadScores(context).toMutableList()
|
val scores = loadScores(context).toMutableList()
|
||||||
scores.add(
|
scores.add(
|
||||||
@ -111,7 +113,8 @@ object Scoreboard {
|
|||||||
turnNumber = turnNumber,
|
turnNumber = turnNumber,
|
||||||
date = System.currentTimeMillis(),
|
date = System.currentTimeMillis(),
|
||||||
scoreDetail = scoreDetail,
|
scoreDetail = scoreDetail,
|
||||||
opponentDetail = opponentDetail
|
opponentDetail = opponentDetail,
|
||||||
|
gameLogJson = gameLogJson
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
saveScores(context, scores.sortedByDescending { it.points }.take(50))
|
saveScores(context, scores.sortedByDescending { it.points }.take(50))
|
||||||
@ -222,7 +225,8 @@ fun LocalGameScreen(
|
|||||||
playerCount = totalPlayers,
|
playerCount = totalPlayers,
|
||||||
turnNumber = gameTurnNumber,
|
turnNumber = gameTurnNumber,
|
||||||
scoreDetail = detailStr,
|
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.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.unogame.game.GameMode
|
import com.unogame.game.GameMode
|
||||||
import com.unogame.ui.theme.*
|
import com.unogame.ui.theme.*
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@ -44,6 +45,8 @@ fun ScoreboardScreen(onBack: () -> Unit) {
|
|||||||
|
|
||||||
var showDetailDialog by remember { mutableStateOf(false) }
|
var showDetailDialog by remember { mutableStateOf(false) }
|
||||||
var detailEntry by remember { mutableStateOf<ScoreEntry?>(null) }
|
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 showImportDialog by remember { mutableStateOf(false) }
|
||||||
var importJson by remember { mutableStateOf("") }
|
var importJson by remember { mutableStateOf("") }
|
||||||
var showMenu by remember { mutableStateOf(false) }
|
var showMenu by remember { mutableStateOf(false) }
|
||||||
@ -338,14 +341,64 @@ fun ScoreboardScreen(onBack: () -> Unit) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
confirmButton = {
|
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 }) {
|
TextButton(onClick = { showDetailDialog = false }) {
|
||||||
Text("关闭", color = GoldAccent)
|
Text("关闭", color = GoldAccent)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
containerColor = DarkSurface
|
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
|
// Import dialog
|
||||||
if (showImportDialog) {
|
if (showImportDialog) {
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user