feat: 添加出牌动画和牌型排序显示
- 修复 AI decide 方法参数类型为 Array[Card] - 添加 cards_played 和 player_passed 信号 - 出牌时在桌面中央显示排序后的卡牌 - 过牌时清除桌面牌 - 添加延迟动画效果(0.8秒显示,0.5秒清除) - 添加 TableLabel 作为出牌显示区域 - 出牌按 rank 排序显示 🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
extends Control
|
||||
|
||||
const CARD_NODE_SCENE := preload("res://src/ui/components/card_node.tscn")
|
||||
|
||||
var controller: TrainingController
|
||||
var table_cards: Array[CardNode] = []
|
||||
|
||||
@onready var hand_area := $ScrollContainer/HandArea as HandArea
|
||||
@onready var play_button: Button = $Buttons/PlayButton
|
||||
@@ -8,6 +11,7 @@ var controller: TrainingController
|
||||
@onready var hint_button: Button = $Buttons/HintButton
|
||||
@onready var status_label: Label = $StatusLabel
|
||||
@onready var guide_label: Label = $GuideLabel
|
||||
@onready var table_label: Label = $TableLabel
|
||||
|
||||
func _ready() -> void:
|
||||
if play_button:
|
||||
@@ -26,6 +30,8 @@ func start_training() -> void:
|
||||
controller.turn_ready.connect(_on_turn_ready)
|
||||
controller.state_changed.connect(_refresh_ui)
|
||||
controller.game_ended.connect(_on_game_ended)
|
||||
controller.cards_played.connect(_on_cards_played)
|
||||
controller.player_passed.connect(_on_player_passed)
|
||||
_update_guide_text()
|
||||
_refresh_ui()
|
||||
|
||||
@@ -58,17 +64,7 @@ func _on_play_pressed() -> void:
|
||||
status_label.text = "❌ %s" % error_msg
|
||||
return
|
||||
hand_area.clear_selection()
|
||||
if status_label:
|
||||
status_label.text = "✓ 出牌成功!"
|
||||
_refresh_ui()
|
||||
|
||||
func _get_error_message(error_code: int) -> String:
|
||||
match error_code:
|
||||
1: return "无效的牌型组合"
|
||||
2: return "不是你的回合"
|
||||
3: return "不能过牌(你是领出者)"
|
||||
4: return "牌不在手中"
|
||||
_: return "出牌失败"
|
||||
# 不立即刷新,等 cards_played 信号触发刷新
|
||||
|
||||
func _on_pass_pressed() -> void:
|
||||
var result := controller.handle_human_pass()
|
||||
@@ -79,8 +75,63 @@ func _on_pass_pressed() -> void:
|
||||
return
|
||||
if status_label:
|
||||
status_label.text = "✓ 已过牌"
|
||||
|
||||
func _on_cards_played(player_idx: int, play: HandEvaluator.EvaluatedPlay) -> void:
|
||||
# 显示出的牌
|
||||
_show_table_cards(play.cards)
|
||||
var player_name := controller.game_state.player_names[player_idx]
|
||||
var type_name := _get_type_name(play.type)
|
||||
if status_label:
|
||||
status_label.text = "%s 出了 %s(%d张)" % [player_name, type_name, play.cards.size()]
|
||||
|
||||
# 延迟刷新手牌,让玩家看到出牌效果
|
||||
await get_tree().create_timer(0.8).timeout
|
||||
_refresh_ui()
|
||||
|
||||
func _on_player_passed(player_idx: int) -> void:
|
||||
var player_name := controller.game_state.player_names[player_idx]
|
||||
if status_label:
|
||||
status_label.text = "%s 过牌" % player_name
|
||||
# 清除桌面牌
|
||||
_clear_table_cards()
|
||||
await get_tree().create_timer(0.5).timeout
|
||||
_refresh_ui()
|
||||
|
||||
func _show_table_cards(cards: Array[Card]) -> void:
|
||||
_clear_table_cards()
|
||||
# 按 rank 排序
|
||||
var sorted_cards: Array[Card] = cards.duplicate(false)
|
||||
sorted_cards.sort_custom(func(a: Card, b: Card): return a.compare_to(b) < 0)
|
||||
|
||||
var total_width := sorted_cards.size() * 60
|
||||
var start_x := (1280 - total_width) / 2
|
||||
|
||||
for i in range(sorted_cards.size()):
|
||||
var card: Card = sorted_cards[i]
|
||||
var node := CARD_NODE_SCENE.instantiate() as CardNode
|
||||
if node == null:
|
||||
continue
|
||||
table_label.add_child(node)
|
||||
node.setup(card)
|
||||
node.position = Vector2(start_x + i * 60, 80)
|
||||
node.custom_minimum_size = Vector2(55, 80)
|
||||
node.size = Vector2(55, 80)
|
||||
node.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
table_cards.append(node)
|
||||
|
||||
func _clear_table_cards() -> void:
|
||||
for cn in table_cards:
|
||||
cn.queue_free()
|
||||
table_cards.clear()
|
||||
|
||||
func _get_error_message(error_code: int) -> String:
|
||||
match error_code:
|
||||
1: return "无效的牌型组合"
|
||||
2: return "不是你的回合"
|
||||
3: return "不能过牌(你是领出者)"
|
||||
4: return "牌不在手中"
|
||||
_: return "出牌失败"
|
||||
|
||||
func _on_hint_pressed() -> void:
|
||||
var hint := controller.get_hint()
|
||||
if hint == null or hint.type == -1:
|
||||
@@ -114,10 +165,12 @@ func _get_type_name(type_idx: int) -> String:
|
||||
_: return "未知"
|
||||
|
||||
func _on_game_ended(winner_team: int, _reason: String) -> void:
|
||||
if status_label: status_label.text = "游戏结束! 队伍 %d 获胜" % winner_team
|
||||
if hand_area: hand_area.disable_input()
|
||||
if status_label:
|
||||
status_label.text = "游戏结束! 队伍 %d 获胜" % winner_team
|
||||
if hand_area:
|
||||
hand_area.disable_input()
|
||||
|
||||
func _refresh_ui() -> void:
|
||||
if controller and controller.game_state and hand_area:
|
||||
var hand: Array = controller.game_state.get_hand(0)
|
||||
var hand: Array[Card] = controller.game_state.get_hand(0)
|
||||
hand_area.update_hand(hand)
|
||||
|
||||
Reference in New Issue
Block a user