fix: 扩展至8人局、修复多机器人名字崩溃、自动滚动当前玩家、金色粗边框高亮

This commit is contained in:
flykhan 2026-04-26 20:04:11 +08:00
parent 8f843a4e6f
commit 536fbb4918
3 changed files with 33 additions and 9 deletions

View File

@ -6,7 +6,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@ -30,12 +30,13 @@ fun PlayerAvatar(
val avatar = if (isBot) getBotAvatar(player.name) else null
val playerColor = avatar?.color ?: GoldAccent
val borderColor = if (player.isCurrentTurn) GoldAccent else playerColor
val borderWidth = if (player.isCurrentTurn) 3.dp else 2.dp
Row(
modifier = modifier
.clip(RoundedCornerShape(12.dp))
.background(if (isYou) DarkSurface.copy(alpha = 0.8f) else DarkCard)
.border(2.dp, borderColor, RoundedCornerShape(12.dp))
.border(borderWidth, borderColor, RoundedCornerShape(12.dp))
.padding(horizontal = 12.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically
) {

View File

@ -4,6 +4,7 @@ import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
@ -140,13 +141,25 @@ fun GameScreen(
}
// Other players
val otherPlayers = remember(gameState.players, myPlayerId) {
gameState.players.filter { it.id != myPlayerId }
}
val listState = rememberLazyListState()
LaunchedEffect(gameState.currentPlayerIndex, otherPlayers) {
val current = gameState.currentPlayer
if (current.id != myPlayerId) {
val idx = otherPlayers.indexOfFirst { it.id == current.id }
if (idx >= 0) listState.animateScrollToItem(idx)
}
}
LazyRow(
state = listState,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
items(gameState.players.filter { it.id != myPlayerId }) { player ->
items(otherPlayers) { player ->
PlayerAvatar(
player = player,
isYou = false,

View File

@ -2,6 +2,7 @@ package com.unogame.ui.screens
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
@ -40,7 +41,16 @@ fun LocalSetupScreen(
val initMaxHandSize = remember { com.unogame.game.GameRules.loadMaxHandSize(context, mode) }
var maxHandSize by remember { mutableIntStateOf(initMaxHandSize) }
var botNames by remember { mutableStateOf(pickUniqueBotNames(3).toMutableList()) }
var botNames by remember { mutableStateOf(pickUniqueBotNames(7).toMutableList()) }
// Ensure we have enough names when player count changes
LaunchedEffect(totalPlayers) {
val needed = totalPlayers - 1
if (botNames.size < needed) {
val currentSet = botNames.toSet()
val allNames = pickUniqueBotNames(7 + needed).filter { it !in currentSet }
botNames = (botNames + allNames.take(needed - botNames.size)).toMutableList()
}
}
Box(
modifier = Modifier
@ -129,14 +139,14 @@ fun LocalSetupScreen(
Text("总玩家数", color = Color.White.copy(alpha = 0.6f), fontSize = 14.sp)
Spacer(modifier = Modifier.height(12.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
modifier = Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
listOf(2, 3, 4).forEach { count ->
listOf(2, 3, 4, 5, 6, 7, 8).forEach { count ->
val isSelected = totalPlayers == count
Card(
modifier = Modifier
.size(90.dp)
.size(72.dp)
.clickable { totalPlayers = count },
shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors(
@ -331,7 +341,7 @@ fun LocalSetupScreen(
colors = CardDefaults.cardColors(containerColor = DarkSurface.copy(alpha = 0.5f))
) {
Text(
"• 1位真人 + ${totalPlayers - 1}个机器人\n• 支持2-4人局\n• 机器人会自动出牌,无需等待",
"• 1位真人 + ${totalPlayers - 1}个机器人\n• 支持2-8人局\n• 机器人会自动出牌,无需等待",
color = Color.White.copy(alpha = 0.5f),
fontSize = 12.sp,
lineHeight = 20.sp,