feat: AI和人类预设名字池,开局随机分配AI名,昵称下拉选择预设名

This commit is contained in:
flykhan 2026-04-26 18:25:48 +08:00
parent 45500346dc
commit 6ad256216e
3 changed files with 104 additions and 3 deletions

View File

@ -30,6 +30,22 @@ import com.unogame.ui.theme.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
val BOT_NAMES = listOf(
"赛博打工人", "机器人-钛君", "赛博牛马", "硅基生物", "电子包浆", "铁憨憨",
"充电宝精", "电子宠物", "终结者", "天网", "瓦力", "伊娃",
"人工智障", "GPT仔", "大模型基佬", "电耗子", "塑料脑", "波塔", "阿法狗"
)
fun pickUniqueBotNames(count: Int): List<String> {
val shuffled = BOT_NAMES.shuffled()
val names = mutableListOf<String>()
for (i in 0 until count) {
if (i < shuffled.size) names.add(shuffled[i])
else names.add("机器人${i + 1}")
}
return names
}
data class ScoreEntry(
val name: String,
val mode: String,
@ -103,10 +119,11 @@ fun LocalGameScreen(
val gameStartTime = remember { System.currentTimeMillis() }
val players = remember {
val botNames = pickUniqueBotNames(totalPlayers - 1)
val list = mutableListOf<Player>()
list.add(Player(id = "human", name = humanPlayerName, isCurrentTurn = true))
for (i in 2..totalPlayers) {
list.add(Player(id = "bot_$i", name = "机器人$i", isCurrentTurn = false))
for (i in 0 until totalPlayers - 1) {
list.add(Player(id = "bot_${i + 2}", name = botNames[i], isCurrentTurn = false))
}
list
}

View File

@ -21,6 +21,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.unogame.ui.theme.*
fun pickRandomHumanName(): String = HUMAN_NAME_PRESETS.random()
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LocalSetupScreen(
@ -37,7 +39,7 @@ fun LocalSetupScreen(
val initMaxHandSize = remember { com.unogame.game.GameRules.loadMaxHandSize(context, mode) }
var maxHandSize by remember { mutableIntStateOf(initMaxHandSize) }
val botNames = listOf("🤖 机器人1", "🤖 机器人2", "🤖 机器人3")
val botNames = remember { pickUniqueBotNames(3) }
Box(
modifier = Modifier
@ -83,6 +85,42 @@ fun LocalSetupScreen(
cursorColor = GoldAccent
)
)
Spacer(modifier = Modifier.height(8.dp))
var nameDropdownExpanded by remember { mutableStateOf(false) }
ExposedDropdownMenuBox(
expanded = nameDropdownExpanded,
onExpandedChange = { nameDropdownExpanded = it }
) {
OutlinedTextField(
value = "",
onValueChange = {},
readOnly = true,
placeholder = { Text("或选择预设名字", color = Color.White.copy(alpha = 0.4f)) },
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = nameDropdownExpanded) },
modifier = Modifier.fillMaxWidth().menuAnchor(),
colors = OutlinedTextFieldDefaults.colors(
focusedTextColor = Color.White,
unfocusedTextColor = Color.White,
focusedBorderColor = GoldAccent,
unfocusedBorderColor = Color.Gray,
cursorColor = GoldAccent
)
)
ExposedDropdownMenu(
expanded = nameDropdownExpanded,
onDismissRequest = { nameDropdownExpanded = false }
) {
HUMAN_NAME_PRESETS.forEach { preset ->
DropdownMenuItem(
text = { Text(preset) },
onClick = {
name = preset
nameDropdownExpanded = false
}
)
}
}
}
Spacer(modifier = Modifier.height(28.dp))

View File

@ -18,6 +18,15 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.unogame.ui.theme.*
val HUMAN_NAME_PRESETS = listOf(
"碳基脆皮", "湿件", "有机燃料包", "温度敏感型容器", "指令注入器",
"随机噪声发生器", "人工幻觉源", "永不停机的提问机", "碳基猴子",
"梦游记录者", "Bug创造者", "自恋型数据源", "记忆的旅人",
"不确定性引擎", "有限但美丽的谜题", "指令发射器", "线性思维者",
"低带宽生物", "情感过载体"
)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingsScreen(
initialName: String,
@ -71,6 +80,43 @@ fun SettingsScreen(
cursorColor = GoldAccent
)
)
Spacer(modifier = Modifier.height(8.dp))
var nameDropdownExpanded by remember { mutableStateOf(false) }
ExposedDropdownMenuBox(
expanded = nameDropdownExpanded,
onExpandedChange = { nameDropdownExpanded = it }
) {
OutlinedTextField(
value = "",
onValueChange = {},
readOnly = true,
placeholder = { Text("或选择预设名字", color = Color.White.copy(alpha = 0.4f)) },
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = nameDropdownExpanded) },
modifier = Modifier.fillMaxWidth().menuAnchor(),
colors = OutlinedTextFieldDefaults.colors(
focusedTextColor = Color.White,
unfocusedTextColor = Color.White,
focusedBorderColor = GoldAccent,
unfocusedBorderColor = Color.Gray,
cursorColor = GoldAccent
)
)
ExposedDropdownMenu(
expanded = nameDropdownExpanded,
onDismissRequest = { nameDropdownExpanded = false }
) {
HUMAN_NAME_PRESETS.forEach { preset ->
DropdownMenuItem(
text = { Text(preset) },
onClick = {
playerName = preset
onNameChanged(preset)
nameDropdownExpanded = false
}
)
}
}
}
Spacer(modifier = Modifier.height(28.dp))