1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00

feat: 添加角色选择系统及相关功能

新增角色卡片组件和角色选择逻辑
实现角色卡片动画效果和交互功能
添加初始角色数据配置
修改启动面板以支持角色选择
更新主题样式和UI布局
This commit is contained in:
2026-05-04 19:52:04 +08:00
parent e8ee2932bb
commit 492373a48e
13 changed files with 415 additions and 46 deletions
+20 -1
View File
@@ -11,6 +11,8 @@ class_name StarterPanel
@onready var crystalShow: ItemShow = $%crystal
@onready var diamondShow: ItemShow = $%diamond
@onready var charactersBox: Control = $%characters
@onready var startSingleplayerBtn: Button = $%startSingleplayerBtn
@onready var startMultiplayerBtn: Button = $%startMultiplayerBtn
@onready var levelShow: Label = $%levelShow
@@ -27,9 +29,11 @@ class_name StarterPanel
var historyStack
static var GAMEMODE_MAP_WAVE = [Wave.WAVE_NORMAL, Wave.WAVE_BOSSRUSH, Wave.WAVE_MOWING]
static var START_CHARACTERS = ["MuyangDog", "Lynx", "HCN"]
static var buildingShader: bool = true
static var selectingFeed: bool = true
static var GAMEMODE_MAP_WAVE = [Wave.WAVE_NORMAL, Wave.WAVE_BOSSRUSH, Wave.WAVE_MOWING]
static var selectedCharacter: String = START_CHARACTERS[1]
@rpc("any_peer")
func mutexPlayer(player: String):
@@ -159,6 +163,9 @@ func getPlayerNames() -> Array[String]:
result.append(i.text)
return result
func getCurrentSelectedCharacter() -> CharacterCard:
return charactersBox.get_node(selectedCharacter as NodePath)
func beforeOpen(_args: Array = []):
diffEdit.min_value = GameRule.difficultyRange.x
diffEdit.max_value = GameRule.difficultyRange.y
@@ -191,3 +198,15 @@ func rebuildInfo():
rebuildInfo()
)
upgradeFieldsBox.add_child(fieldShow)
for child in charactersBox.get_children():
charactersBox.remove_child(child)
for character in START_CHARACTERS:
var card = ComponentManager.getCharacterCard(character).instantiate() as CharacterCard
card.select.connect(
func():
if card.name == selectedCharacter: return
getCurrentSelectedCharacter().animator.play("hide")
selectedCharacter = card.name
getCurrentSelectedCharacter().animator.play("show")
)
charactersBox.add_child(card)
+13
View File
@@ -0,0 +1,13 @@
class_name Watcher
signal changed()
var currentState = null
func _init(initialState):
currentState = initialState
func setState(newState):
if newState != currentState:
currentState = newState
changed.emit()
+1
View File
@@ -0,0 +1 @@
uid://7uhyhrta5ld1
+54
View File
@@ -0,0 +1,54 @@
@tool
extends Control
class_name CharacterCard
signal select()
@export var displayName: String = "Unknown Character"
@export var avatar: Texture2D = null
@export_multiline var description: String = ""
@export var fields: Array[FieldStore.Entity] = []
@export var fieldValues: Array[float] = []
@export var clickToRebuild: bool = false
@export var borderOpacity: float = 0
@onready var panel: PanelContainer = $%panel
@onready var avatarTexture: TextureRect = $%avatarTexture
@onready var nameLebel: Label = $%nameLabel
@onready var descriptionLabel: Label = $%descriptionLabel
@onready var fieldsBox: Control = $%fields
@onready var animator: AnimationPlayer = $%animator
var watcher: Watcher = Watcher.new(false)
@onready var panelStyleBox: StyleBoxFlat = panel.get_theme_stylebox("panel").duplicate()
func _ready():
panel.add_theme_stylebox_override("panel", panelStyleBox)
watcher.changed.connect(rebuildInfo)
gui_input.connect(
func(event):
if event is InputEventMouseButton:
if !(event.pressed && event.button_index == MouseButton.MOUSE_BUTTON_LEFT): return
if animator.is_playing(): return
select.emit()
)
rebuildInfo()
func _process(_delta):
watcher.setState(clickToRebuild)
panelStyleBox.border_width_top = int(10 * borderOpacity)
panelStyleBox.border_width_bottom = int(10 * borderOpacity)
func rebuildInfo():
avatarTexture.texture = avatar
nameLebel.text = displayName
descriptionLabel.text = description
for child in fieldsBox.get_children():
fieldsBox.remove_child(child)
for index in len(fields):
var field = fields[index]
var value = fieldValues[index]
var fieldShow = ComponentManager.getUIComponent("FieldShow").instantiate() as FieldShow
fieldShow.field = field
fieldShow.showAdvantage = true
fieldShow.value = value
fieldsBox.add_child(fieldShow)
+1
View File
@@ -0,0 +1 @@
uid://cd1xb8m6rvoph
@@ -4,6 +4,7 @@ class_name ComponentManager
static var abstracts = {}
static var bullets = {}
static var characterCards = {}
static var characters = {}
static var weapons = {}
static var summons = {}
@@ -21,6 +22,8 @@ static func init():
abstracts[DirTool.getBasenameWithoutExtension(i)] = load(i)
for i in DirTool.listdir("res://components/Bullets"):
bullets[DirTool.getBasenameWithoutExtension(i)] = load(i)
for i in DirTool.listdir("res://components/CharacterCards"):
characterCards[DirTool.getBasenameWithoutExtension(i)] = load(i)
for i in DirTool.listdir("res://components/Characters"):
characters[DirTool.getBasenameWithoutExtension(i)] = load(i)
for i in DirTool.listdir("res://components/Weapons"):
@@ -48,6 +51,8 @@ static func getAbstract(t: String) -> PackedScene:
return MathTool.priority(abstracts.get(t, false), load("res://components/Abstracts/%s.tscn" % t))
static func getBullet(t: String) -> PackedScene:
return MathTool.priority(bullets.get(t, false), load("res://components/Bullets/%s.tscn" % t))
static func getCharacterCard(t: String) -> PackedScene:
return MathTool.priority(characterCards.get(t, false), load("res://components/CharacterCards/%s.tscn" % t))
static func getCharacter(t: String) -> PackedScene:
return MathTool.priority(characters.get(t, false), load("res://components/Characters/%s.tscn" % t))
static func getWeapon(t: String) -> PackedScene: