feat: add basic UI scenes (card, hand, training room, main menu)

This commit is contained in:
xiaji
2026-05-29 09:14:42 +08:00
parent 6886af1de7
commit 3272e3dc0a
8 changed files with 248 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
extends Control
func _ready() -> void:
var start_btn := $VBoxContainer/StartButton as Button
var quit_btn := $VBoxContainer/QuitButton as Button
start_btn.pressed.connect(_on_start_pressed)
quit_btn.pressed.connect(_on_quit_pressed)
func _on_start_pressed() -> void:
get_tree().change_scene_to_file("res://src/ui/scenes/training_room.tscn")
func _on_quit_pressed() -> void:
get_tree().quit()

View File

@@ -0,0 +1,17 @@
[gd_scene load_steps=2 format=3 uid="uid://main_menu"]
[ext_resource type="Script" path="res://src/ui/scenes/main_menu.gd" id="1_script"]
[node name="MainMenu" type="Control"]
layout_mode = 3
anchors_preset = 15
script = ExtResource("1_script")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
offset_left = 300.0
offset_top = 200.0
offset_right = 500.0
offset_bottom = 400.0
[node name="StartButton" type="Button" parent="VBoxContainer"]
text = "开始训练"
[node name="QuitButton" type="Button" parent="VBoxContainer"]
text = "退出"

View File

@@ -0,0 +1,70 @@
extends Control
var controller: TrainingController
@onready var hand_area: Node = $HandArea
@onready var play_button: Button = $Buttons/PlayButton
@onready var pass_button: Button = $Buttons/PassButton
@onready var hint_button: Button = $Buttons/HintButton
@onready var status_label: Label = $StatusLabel
func _ready() -> void:
hand_area.training_controller = controller
play_button.pressed.connect(_on_play_pressed)
pass_button.pressed.connect(_on_pass_pressed)
hint_button.pressed.connect(_on_hint_pressed)
func start_training() -> void:
controller = TrainingController.new()
controller.start_game(Config.rule_config, 0)
controller.turn_ready.connect(_on_turn_ready)
controller.state_changed.connect(_refresh_ui)
controller.game_ended.connect(_on_game_ended)
_refresh_ui()
func _on_turn_ready(player_idx: int, is_human: bool) -> void:
if is_human:
hand_area.enable_input()
status_label.text = "你的回合"
else:
hand_area.disable_input()
status_label.text = "%s 思考中..." % controller.game_state.player_names[player_idx]
func _on_play_pressed() -> void:
var selected := hand_area.selected_cards
if selected.is_empty():
return
var result := controller.handle_human_play(selected)
if not result.ok:
status_label.text = "无效出牌"
return
hand_area.clear_selection()
_refresh_ui()
func _on_pass_pressed() -> void:
var result := controller.handle_human_pass()
if not result.ok:
status_label.text = "不能过牌"
return
_refresh_ui()
func _on_hint_pressed() -> void:
var hint := controller.get_hint()
if hint == null or hint.type == -1:
status_label.text = "建议:过牌"
return
hand_area.clear_selection()
for card in hint.cards:
for cn in hand_area.card_nodes:
if cn.card_data != null and cn.card_data.card_id == card.card_id:
cn.set_selected(true)
hand_area.selected_cards.append(card)
status_label.text = "建议牌型: %s (rank=%d)" % [hint.type, hint.primary_rank]
func _on_game_ended(winner_team: int, reason: String) -> void:
status_label.text = "游戏结束! 队伍 %d 获胜" % winner_team
hand_area.disable_input()
func _refresh_ui() -> void:
if controller and controller.game_state:
hand_area.update_hand(controller.game_state.get_hand(0))

View File

@@ -0,0 +1,28 @@
[gd_scene load_steps=2 format=3 uid="uid://training_room"]
[ext_resource type="Script" path="res://src/ui/scenes/training_room.gd" id="1_script"]
[node name="TrainingRoom" type="Control"]
layout_mode = 3
anchors_preset = 15
script = ExtResource("1_script")
[node name="StatusLabel" type="Label" parent="."]
layout_mode = 0
offset_right = 400.0
offset_bottom = 50.0
text = "掼蛋训练模式"
horizontal_alignment = 1
[node name="HandArea" type="HBoxContainer" parent="."]
layout_mode = 0
offset_top = 500.0
offset_right = 800.0
offset_bottom = 650.0
[node name="Buttons" type="HBoxContainer" parent="."]
layout_mode = 0
offset_top = 660.0
offset_right = 800.0
offset_bottom = 720.0
[node name="PlayButton" type="Button" parent="Buttons"]
text = "出牌"
[node name="PassButton" type="Button" parent="Buttons"]
text = "过牌"
[node name="HintButton" type="Button" parent="Buttons"]
text = "提示"