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

View File

@ -4,6 +4,7 @@ import androidx.compose.foundation.*
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
@ -140,13 +141,25 @@ fun GameScreen(
} }
// Other players // 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( LazyRow(
state = listState,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp), .padding(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp) horizontalArrangement = Arrangement.spacedBy(8.dp)
) { ) {
items(gameState.players.filter { it.id != myPlayerId }) { player -> items(otherPlayers) { player ->
PlayerAvatar( PlayerAvatar(
player = player, player = player,
isYou = false, isYou = false,

View File

@ -2,6 +2,7 @@ package com.unogame.ui.screens
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
@ -40,7 +41,16 @@ fun LocalSetupScreen(
val initMaxHandSize = remember { com.unogame.game.GameRules.loadMaxHandSize(context, mode) } val initMaxHandSize = remember { com.unogame.game.GameRules.loadMaxHandSize(context, mode) }
var maxHandSize by remember { mutableIntStateOf(initMaxHandSize) } 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( Box(
modifier = Modifier modifier = Modifier
@ -129,14 +139,14 @@ fun LocalSetupScreen(
Text("总玩家数", color = Color.White.copy(alpha = 0.6f), fontSize = 14.sp) Text("总玩家数", color = Color.White.copy(alpha = 0.6f), fontSize = 14.sp)
Spacer(modifier = Modifier.height(12.dp)) Spacer(modifier = Modifier.height(12.dp))
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()),
horizontalArrangement = Arrangement.SpaceEvenly 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 val isSelected = totalPlayers == count
Card( Card(
modifier = Modifier modifier = Modifier
.size(90.dp) .size(72.dp)
.clickable { totalPlayers = count }, .clickable { totalPlayers = count },
shape = RoundedCornerShape(16.dp), shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors( colors = CardDefaults.cardColors(
@ -331,7 +341,7 @@ fun LocalSetupScreen(
colors = CardDefaults.cardColors(containerColor = DarkSurface.copy(alpha = 0.5f)) colors = CardDefaults.cardColors(containerColor = DarkSurface.copy(alpha = 0.5f))
) { ) {
Text( Text(
"• 1位真人 + ${totalPlayers - 1}个机器人\n• 支持2-4人局\n• 机器人会自动出牌,无需等待", "• 1位真人 + ${totalPlayers - 1}个机器人\n• 支持2-8人局\n• 机器人会自动出牌,无需等待",
color = Color.White.copy(alpha = 0.5f), color = Color.White.copy(alpha = 0.5f),
fontSize = 12.sp, fontSize = 12.sp,
lineHeight = 20.sp, lineHeight = 20.sp,