From 11c1fcb13ab15be57be4e0d06c3f08f1c536e66d Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 7 May 2026 13:38:19 -0400 Subject: [PATCH] Refactor game HUD scenes and harden attack checks --- .../origin-client/scenes/game/GameScreen.tscn | 508 +----------------- .../components/board/tile_target_resolver.gd | 12 +- .../components/camera/camera_controller.gd | 29 +- .../game/components/hud/hud_controller.gd | 163 +++--- .../game/components/hud/hud_controller.tscn | 407 ++++++++++++++ .../components/overlays/game_over_overlay.gd | 28 +- .../overlays/game_over_overlay.tscn | 43 ++ .../origin-client/scenes/game/game_screen.gd | 256 +++------ Server/src/SOR.Game/GameEngine.cs | 17 +- 9 files changed, 688 insertions(+), 775 deletions(-) create mode 100644 Client/origin-client/scenes/game/components/hud/hud_controller.tscn create mode 100644 Client/origin-client/scenes/game/components/overlays/game_over_overlay.tscn diff --git a/Client/origin-client/scenes/game/GameScreen.tscn b/Client/origin-client/scenes/game/GameScreen.tscn index 2fb4874..3e3d20b 100644 --- a/Client/origin-client/scenes/game/GameScreen.tscn +++ b/Client/origin-client/scenes/game/GameScreen.tscn @@ -1,37 +1,10 @@ -[gd_scene load_steps=20 format=3 uid="uid://b17evi1hw4dqu"] +[gd_scene load_steps=6 format=3 uid="uid://b17evi1hw4dqu"] [ext_resource type="Script" uid="uid://b8x84lb58h6gx" path="res://scenes/game/game_screen.gd" id="1_gscr"] -[ext_resource type="Texture2D" uid="uid://dvmripj4jux0b" path="res://icons/SP-Symbol-White.png" id="2_056su"] [ext_resource type="PackedScene" path="res://scenes/game/InGameSettings.tscn" id="2_igs"] -[ext_resource type="Texture2D" uid="uid://csvmdo2kwnh7c" path="res://icons/ST-Symbol-White.png" id="3_wukpb"] -[ext_resource type="Texture2D" uid="uid://beyeu0y34m3v4" path="res://ui/icons/Deck Icon.png" id="4_ld7sk"] -[ext_resource type="Texture2D" uid="uid://c65s8sn4p7s37" path="res://ui/icons/Discard Icon.png" id="5_pryjh"] -[ext_resource type="Texture2D" uid="uid://psjb7swm36jx" path="res://ui/icons/Green_Gem_Arrow_Button_Click.png" id="6_pryjh"] - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_wukpb"] - -[sub_resource type="Theme" id="Theme_056su"] - -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ld7sk"] -bg_color = Color(0.38039216, 0.38039216, 0.38039216, 0.58431375) - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xjmfi"] - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_pryjh"] - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_pnc6c"] - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_2dkum"] - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_7me7j"] - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_msfbn"] - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ld7sk"] - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_w2jaq"] - -[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_fuou0"] +[ext_resource type="PackedScene" path="res://scenes/game/components/hud/hud_controller.tscn" id="3_hudctrl"] +[ext_resource type="PackedScene" uid="uid://cowqg2xdx0x7g" path="res://scenes/game/components/hud/hand_manager.tscn" id="4_handmgr"] +[ext_resource type="PackedScene" path="res://scenes/game/components/overlays/game_over_overlay.tscn" id="5_goo"] [node name="GameScreen" type="Node3D"] script = ExtResource("1_gscr") @@ -59,368 +32,13 @@ transform = Transform3D(1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, [node name="HUD" type="CanvasLayer" parent="."] layer = 10 -[node name="TopBar" type="HBoxContainer" parent="HUD"] -anchors_preset = 10 -anchor_right = 1.0 -offset_bottom = 48.0 -theme_override_constants/separation = 0 - -[node name="PhaseLabel" type="Label" parent="HUD/TopBar"] +[node name="HudController" parent="HUD" instance=ExtResource("3_hudctrl")] unique_name_in_owner = true -custom_minimum_size = Vector2(140, 48) -layout_mode = 2 -theme_override_font_sizes/font_size = 13 -text = "Phase: —" -vertical_alignment = 1 +layout_mode = 3 -[node name="TurnLabel" type="Label" parent="HUD/TopBar"] +[node name="HandManager" parent="HUD" instance=ExtResource("4_handmgr")] unique_name_in_owner = true -layout_mode = 2 -size_flags_horizontal = 3 -theme_override_font_sizes/font_size = 13 -text = "Turn 1 — Your turn" -horizontal_alignment = 1 -vertical_alignment = 1 - -[node name="TurnOrderStrip" type="HBoxContainer" parent="HUD/TopBar"] -unique_name_in_owner = true -visible = false -layout_mode = 2 -size_flags_horizontal = 3 -theme_override_constants/separation = 4 - -[node name="OpponentPanel" type="HBoxContainer" parent="HUD/TopBar"] -unique_name_in_owner = true -custom_minimum_size = Vector2(240, 48) -layout_mode = 2 -theme_override_constants/separation = 8 - -[node name="OppNameLabel" type="Label" parent="HUD/TopBar/OpponentPanel"] -unique_name_in_owner = true -modulate = Color(1, 0.5, 0.5, 1) -layout_mode = 2 -theme_override_font_sizes/font_size = 12 -text = "Opponent" -vertical_alignment = 1 - -[node name="OppHandLabel" type="Label" parent="HUD/TopBar/OpponentPanel"] -unique_name_in_owner = true -layout_mode = 2 -theme_override_font_sizes/font_size = 12 -text = "Hand: 0" -vertical_alignment = 1 - -[node name="OppDeckLabel" type="Label" parent="HUD/TopBar/OpponentPanel"] -unique_name_in_owner = true -layout_mode = 2 -theme_override_font_sizes/font_size = 12 -text = "Deck: 0" -vertical_alignment = 1 - -[node name="OppDiscardBtn" type="Button" parent="HUD/TopBar/OpponentPanel"] -unique_name_in_owner = true -layout_mode = 2 -theme_override_font_sizes/font_size = 11 -text = "Discard" - -[node name="SP-ST Panel Container" type="PanelContainer" parent="HUD"] -anchors_preset = -1 -anchor_top = 0.675 -anchor_bottom = 0.675 -offset_top = -156.40002 -offset_right = 76.0 -offset_bottom = -0.4000244 -theme_override_styles/panel = SubResource("StyleBoxEmpty_wukpb") - -[node name="VBoxContainer" type="VBoxContainer" parent="HUD/SP-ST Panel Container"] -layout_mode = 2 -alignment = 2 - -[node name="TextureRect" type="TextureRect" parent="HUD/SP-ST Panel Container/VBoxContainer"] -self_modulate = Color(0, 0.8117647, 0.77254903, 0.38039216) -texture_filter = 5 -custom_minimum_size = Vector2(1.78, 76) -layout_mode = 2 -theme = SubResource("Theme_056su") -texture = ExtResource("2_056su") -expand_mode = 1 - -[node name="SpLabel" type="Label" parent="HUD/SP-ST Panel Container/VBoxContainer/TextureRect"] -unique_name_in_owner = true -layout_mode = 1 -anchors_preset = -1 -anchor_left = 0.513 -anchor_top = 0.36800003 -anchor_right = 0.513 -anchor_bottom = 0.36800003 -offset_left = -18.987999 -offset_top = -22.968002 -offset_right = 19.012001 -offset_bottom = 23.031998 -tooltip_text = "Spirit Points" -mouse_filter = 1 -theme_override_colors/font_color = Color(0.012617188, 0.012617188, 0.012617188, 1) -theme_override_font_sizes/font_size = 33 -text = "88" -horizontal_alignment = 1 -vertical_alignment = 1 -metadata/_edit_use_anchors_ = true - -[node name="TextureRect2" type="TextureRect" parent="HUD/SP-ST Panel Container/VBoxContainer"] -self_modulate = Color(0, 0.8117647, 0.77254903, 0.38039216) -texture_filter = 5 -custom_minimum_size = Vector2(1.78, 76) -layout_mode = 2 -theme = SubResource("Theme_056su") -texture = ExtResource("3_wukpb") -expand_mode = 1 - -[node name="StLabel" type="Label" parent="HUD/SP-ST Panel Container/VBoxContainer/TextureRect2"] -unique_name_in_owner = true -layout_mode = 1 -anchors_preset = -1 -anchor_left = 0.5 -anchor_top = 0.32200003 -anchor_right = 0.5 -anchor_bottom = 0.32200003 -offset_left = -20.0 -offset_top = -20.472002 -offset_right = 22.0 -offset_bottom = 25.527998 -tooltip_text = "Sacrifice Tokens" -mouse_filter = 1 -theme_override_colors/font_color = Color(0.06469653, 0.06469653, 0.06469653, 1) -theme_override_font_sizes/font_size = 33 -text = "88" -horizontal_alignment = 1 -vertical_alignment = 1 - -[node name="ActionRail" type="PanelContainer" parent="HUD"] -anchors_preset = 3 -anchor_left = 1.0 -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = -262.0 -offset_top = -220.0 -offset_right = -70.0 -offset_bottom = -56.0 -grow_horizontal = 0 -grow_vertical = 0 -theme_override_styles/panel = SubResource("StyleBoxFlat_ld7sk") - -[node name="RailMargin" type="MarginContainer" parent="HUD/ActionRail"] -layout_mode = 2 -theme_override_constants/margin_left = 10 -theme_override_constants/margin_top = 8 -theme_override_constants/margin_right = 10 -theme_override_constants/margin_bottom = 8 - -[node name="RailHBox" type="HBoxContainer" parent="HUD/ActionRail/RailMargin"] -layout_mode = 2 -theme_override_constants/separation = 12 - -[node name="Deck-Discard Panel Container" type="Control" parent="HUD/ActionRail/RailMargin/RailHBox"] -custom_minimum_size = Vector2(76, 0) -layout_mode = 2 - -[node name="VBoxContainer" type="VBoxContainer" parent="HUD/ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -alignment = 2 - -[node name="TextureRect" type="TextureRect" parent="HUD/ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer"] -self_modulate = Color(0, 0.8117647, 0.77254903, 0.38039216) -texture_filter = 5 -custom_minimum_size = Vector2(1.78, 76) -layout_mode = 2 -theme = SubResource("Theme_056su") -texture = ExtResource("4_ld7sk") -expand_mode = 1 - -[node name="DeckLabel" type="Label" parent="HUD/ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer/TextureRect"] -unique_name_in_owner = true -layout_mode = 1 -anchors_preset = -1 -anchor_left = 0.507 -anchor_top = 0.40789473 -anchor_right = 0.507 -anchor_bottom = 0.40789473 -offset_left = -22.532001 -offset_top = -36.0 -offset_right = 22.467999 -offset_bottom = 10.0 -grow_horizontal = 2 -grow_vertical = 2 -tooltip_text = "Cards in Deck" -mouse_filter = 1 -theme_override_colors/font_color = Color(0, 0, 0, 1) -theme_override_font_sizes/font_size = 33 -text = "88" -horizontal_alignment = 1 -vertical_alignment = 1 -metadata/_edit_use_anchors_ = true - -[node name="TextureRect2" type="TextureRect" parent="HUD/ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer"] -self_modulate = Color(0, 0.8117647, 0.77254903, 0.38039216) -texture_filter = 5 -custom_minimum_size = Vector2(1.78, 76) -layout_mode = 2 -theme = SubResource("Theme_056su") -expand_mode = 1 - -[node name="DiscardBtn" type="Button" parent="HUD/ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer/TextureRect2"] -unique_name_in_owner = true -layout_mode = 0 -offset_left = -4.000001 -offset_top = -5.000001 -offset_right = 568.0 -offset_bottom = 275.0 -scale = Vector2(0.14754085, 0.23068035) -tooltip_text = "View Discard" -theme_override_colors/icon_normal_color = Color(0.18431373, 0.49411765, 0.47843137, 1) -theme_override_colors/icon_focus_color = Color(0.18431373, 0.49411765, 0.47843137, 1) -theme_override_colors/icon_pressed_color = Color(0.35976923, 0.7944459, 0.77106035, 1) -theme_override_colors/icon_hover_color = Color(0.18431373, 0.49411765, 0.47843137, 1) -theme_override_colors/icon_hover_pressed_color = Color(0.18431373, 0.49411765, 0.47843137, 1) -theme_override_font_sizes/font_size = 12 -theme_override_icons/icon = ExtResource("5_pryjh") -theme_override_styles/normal = SubResource("StyleBoxEmpty_xjmfi") -theme_override_styles/pressed = SubResource("StyleBoxEmpty_pryjh") -theme_override_styles/hover = SubResource("StyleBoxEmpty_pnc6c") -theme_override_styles/hover_pressed = SubResource("StyleBoxEmpty_2dkum") -theme_override_styles/disabled = SubResource("StyleBoxEmpty_7me7j") -theme_override_styles/focus = SubResource("StyleBoxEmpty_msfbn") - -[node name="DiscardLabel" type="Label" parent="HUD/ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer/TextureRect2"] -unique_name_in_owner = true -layout_mode = 1 -anchors_preset = -1 -anchor_left = 0.5 -anchor_top = 0.32200003 -anchor_right = 0.5 -anchor_bottom = 0.32200003 -offset_left = -20.0 -offset_top = -31.472002 -offset_right = 22.0 -offset_bottom = 14.527998 -theme_override_colors/font_color = Color(0.06469653, 0.06469653, 0.06469653, 1) -theme_override_font_sizes/font_size = 33 -text = "88" -horizontal_alignment = 1 -vertical_alignment = 1 - -[node name="Controls" type="Control" parent="HUD/ActionRail/RailMargin/RailHBox"] -layout_mode = 2 -size_flags_horizontal = 3 - -[node name="RightVBox" type="VBoxContainer" parent="HUD/ActionRail/RailMargin/RailHBox/Controls"] -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -theme_override_constants/separation = 6 - -[node name="EndTurnBtn" type="Button" parent="HUD/ActionRail/RailMargin/RailHBox/Controls/RightVBox"] -unique_name_in_owner = true -custom_minimum_size = Vector2(0, 36) -layout_mode = 2 -theme_override_font_sizes/font_size = 13 -text = "End Turn" - -[node name="DrawBtn" type="Button" parent="HUD/ActionRail/RailMargin/RailHBox/Controls/RightVBox"] -unique_name_in_owner = true -custom_minimum_size = Vector2(0, 36) -layout_mode = 2 -theme_override_font_sizes/font_size = 13 -text = "Draw Card" - -[node name="SettingsBtn" type="Button" parent="HUD/ActionRail/RailMargin/RailHBox/Controls/RightVBox"] -unique_name_in_owner = true -custom_minimum_size = Vector2(0, 36) -layout_mode = 2 -theme_override_font_sizes/font_size = 12 -text = "Settings" - -[node name="ChatBubbleHost" type="Control" parent="HUD/ActionRail/RailMargin/RailHBox/Controls/RightVBox"] -unique_name_in_owner = true -custom_minimum_size = Vector2(0, 36) -layout_mode = 2 - -[node name="SpectatorLeaveBtn" type="Button" parent="HUD/ActionRail/RailMargin/RailHBox/Controls/RightVBox"] -unique_name_in_owner = true -visible = false -custom_minimum_size = Vector2(0, 36) -layout_mode = 2 -theme_override_font_sizes/font_size = 12 -text = "Leave Spectator" - -[node name="HandArea" type="PanelContainer" parent="HUD"] -anchors_preset = -1 -anchor_top = 1.0 -anchor_right = 0.75 -anchor_bottom = 1.0 -offset_top = -248.0 -offset_bottom = 2.0 -mouse_filter = 2 -theme_override_styles/panel = SubResource("StyleBoxEmpty_ld7sk") - -[node name="HandScroll" type="Control" parent="HUD/HandArea"] -unique_name_in_owner = true -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 - -[node name="HandCards" type="Control" parent="HUD/HandArea/HandScroll"] -unique_name_in_owner = true -anchors_preset = 0 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="Panel" type="Panel" parent="HUD/HandArea"] -layout_mode = 2 -mouse_filter = 2 -theme_override_styles/panel = SubResource("StyleBoxEmpty_w2jaq") - -[node name="HandSpinLeft" type="TextureButton" parent="HUD/HandArea/Panel"] -unique_name_in_owner = true -custom_minimum_size = Vector2(22, 22) -layout_mode = 0 -offset_left = -2.0 -offset_top = -4.0 -offset_right = 69.0 -offset_bottom = 104.0 -scale = Vector2(1.9999998, 1.44) -texture_normal = ExtResource("6_pryjh") -ignore_texture_size = true -stretch_mode = 5 -flip_h = true - -[node name="Panel2" type="Panel" parent="HUD/HandArea"] -layout_mode = 2 -mouse_filter = 2 -theme_override_styles/panel = SubResource("StyleBoxEmpty_fuou0") - -[node name="HandSpinRight" type="TextureButton" parent="HUD/HandArea/Panel2"] -unique_name_in_owner = true -custom_minimum_size = Vector2(22, 22) -layout_mode = 0 -offset_left = 963.0 -offset_top = 6.0 -offset_right = 1030.0 -offset_bottom = 108.0 -scale = Vector2(2.08, 1.6) -texture_normal = ExtResource("6_pryjh") -ignore_texture_size = true -stretch_mode = 5 +visible = true [node name="RightPanel" type="PanelContainer" parent="HUD"] visible = false @@ -435,33 +53,6 @@ offset_right = -1.0 offset_bottom = 9.0 scale = Vector2(1, 0.96000004) -[node name="SpectatorPlayersPanel" type="PanelContainer" parent="HUD"] -unique_name_in_owner = true -visible = false -anchors_preset = -1 -anchor_top = 1.0 -anchor_right = 0.75 -anchor_bottom = 1.0 -offset_top = -200.0 - -[node name="SpectatorMargin" type="MarginContainer" parent="HUD/SpectatorPlayersPanel"] -layout_mode = 2 -theme_override_constants/margin_left = 8 -theme_override_constants/margin_top = 8 -theme_override_constants/margin_right = 8 -theme_override_constants/margin_bottom = 8 - -[node name="SpectatorScroll" type="ScrollContainer" parent="HUD/SpectatorPlayersPanel/SpectatorMargin"] -layout_mode = 2 -size_flags_vertical = 3 -horizontal_scroll_mode = 0 - -[node name="SpectatorPlayerList" type="VBoxContainer" parent="HUD/SpectatorPlayersPanel/SpectatorMargin/SpectatorScroll"] -unique_name_in_owner = true -layout_mode = 2 -size_flags_horizontal = 3 -theme_override_constants/separation = 4 - [node name="TileDrawerToggleBtn" type="Button" parent="HUD"] unique_name_in_owner = true custom_minimum_size = Vector2(36, 48) @@ -526,89 +117,8 @@ layout_mode = 2 theme_override_font_sizes/font_size = 12 text = "Close" -[node name="DiscardViewer" type="PanelContainer" parent="HUD"] +[node name="GameOverOverlay" parent="HUD" instance=ExtResource("5_goo")] unique_name_in_owner = true -visible = false -anchors_preset = -1 -anchor_left = 0.1 -anchor_top = 0.05 -anchor_right = 0.9 -anchor_bottom = 0.95 - -[node name="DVMargin" type="MarginContainer" parent="HUD/DiscardViewer"] -layout_mode = 2 -theme_override_constants/margin_left = 16 -theme_override_constants/margin_top = 12 -theme_override_constants/margin_right = 16 -theme_override_constants/margin_bottom = 12 - -[node name="DVVBox" type="VBoxContainer" parent="HUD/DiscardViewer/DVMargin"] -layout_mode = 2 -theme_override_constants/separation = 8 - -[node name="DVTitle" type="Label" parent="HUD/DiscardViewer/DVMargin/DVVBox"] -unique_name_in_owner = true -layout_mode = 2 -theme_override_font_sizes/font_size = 16 -text = "Discard Pile" - -[node name="DVScroll" type="ScrollContainer" parent="HUD/DiscardViewer/DVMargin/DVVBox"] -layout_mode = 2 -size_flags_vertical = 3 -horizontal_scroll_mode = 0 - -[node name="DVList" type="VBoxContainer" parent="HUD/DiscardViewer/DVMargin/DVVBox/DVScroll"] -unique_name_in_owner = true -layout_mode = 2 -size_flags_horizontal = 3 -theme_override_constants/separation = 4 - -[node name="DVCloseBtn" type="Button" parent="HUD/DiscardViewer/DVMargin/DVVBox"] -unique_name_in_owner = true -custom_minimum_size = Vector2(0, 36) -layout_mode = 2 -theme_override_font_sizes/font_size = 13 -text = "Close" - -[node name="GameOverOverlay" type="PanelContainer" parent="HUD"] -unique_name_in_owner = true -visible = false -anchors_preset = -1 -anchor_left = 0.25 -anchor_top = 0.25 -anchor_right = 0.75 -anchor_bottom = 0.75 - -[node name="GOMargin" type="MarginContainer" parent="HUD/GameOverOverlay"] -layout_mode = 2 -theme_override_constants/margin_left = 24 -theme_override_constants/margin_top = 24 -theme_override_constants/margin_right = 24 -theme_override_constants/margin_bottom = 24 - -[node name="GOVBox" type="VBoxContainer" parent="HUD/GameOverOverlay/GOMargin"] -layout_mode = 2 -theme_override_constants/separation = 16 - -[node name="GOResultLabel" type="Label" parent="HUD/GameOverOverlay/GOMargin/GOVBox"] -unique_name_in_owner = true -layout_mode = 2 -theme_override_font_sizes/font_size = 28 -text = "Game Over" -horizontal_alignment = 1 - -[node name="GORankLabel" type="Label" parent="HUD/GameOverOverlay/GOMargin/GOVBox"] -unique_name_in_owner = true -layout_mode = 2 -theme_override_font_sizes/font_size = 15 -horizontal_alignment = 1 - -[node name="GOMainMenuBtn" type="Button" parent="HUD/GameOverOverlay/GOMargin/GOVBox"] -unique_name_in_owner = true -custom_minimum_size = Vector2(0, 44) -layout_mode = 2 -theme_override_font_sizes/font_size = 15 -text = "Return to Main Menu" [node name="CamCtrlPanel" type="PanelContainer" parent="HUD"] unique_name_in_owner = true diff --git a/Client/origin-client/scenes/game/components/board/tile_target_resolver.gd b/Client/origin-client/scenes/game/components/board/tile_target_resolver.gd index c549ddb..c5ac3e3 100644 --- a/Client/origin-client/scenes/game/components/board/tile_target_resolver.gd +++ b/Client/origin-client/scenes/game/components/board/tile_target_resolver.gd @@ -165,8 +165,10 @@ func valid_attack_target_coords(unit: Dictionary) -> Array: return results var ux: int = pos.get("x", 0) var uy: int = pos.get("y", 0) - var min_r: int = int(unit.get("minAttackRange") or 1) - var max_r: int = int(unit.get("maxAttackRange") or 1) + var raw_min_r: Variant = unit.get("minAttackRange") + var raw_max_r: Variant = unit.get("maxAttackRange") + var min_r: int = 1 if raw_min_r == null else int(raw_min_r) + var max_r: int = 1 if raw_max_r == null else int(raw_max_r) var needs_los: bool = bool(unit.get("attackRequiresLos", false)) if unit.get("isExhausted", false) and unit.get("extraAttacksRemaining", 0) == 0: return results @@ -200,8 +202,10 @@ func valid_attack_target_ids(unit: Dictionary) -> Array: return results var ux: int = pos.get("x", 0) var uy: int = pos.get("y", 0) - var min_r: int = int(unit.get("minAttackRange") or 1) - var max_r: int = int(unit.get("maxAttackRange") or 1) + var raw_min_r: Variant = unit.get("minAttackRange") + var raw_max_r: Variant = unit.get("maxAttackRange") + var min_r: int = 1 if raw_min_r == null else int(raw_min_r) + var max_r: int = 1 if raw_max_r == null else int(raw_max_r) var needs_los: bool = bool(unit.get("attackRequiresLos", false)) if unit.get("isExhausted", false) and unit.get("extraAttacksRemaining", 0) == 0: return results diff --git a/Client/origin-client/scenes/game/components/camera/camera_controller.gd b/Client/origin-client/scenes/game/components/camera/camera_controller.gd index b48c182..5adba33 100644 --- a/Client/origin-client/scenes/game/components/camera/camera_controller.gd +++ b/Client/origin-client/scenes/game/components/camera/camera_controller.gd @@ -9,8 +9,15 @@ signal zoom_btn_toggled(pressed: bool) var cam_yaw: float = 0.0 var cam_pitch: float = 40.0 var cam_distance: float = 14.0 +var cam_target_distance: float = 14.0 var cam_pivot: Vector3 = Vector3.ZERO var cam_tween: Tween = null +var cam_zoom_tween: Tween = null + +const CAM_MIN_DISTANCE: float = 4.0 +const CAM_MAX_DISTANCE: float = 22.0 +const CAM_ZOOM_SENSITIVITY: float = 0.4 +const CAM_ZOOM_TWEEN_SECONDS: float = 0.12 # Set by parent var camera_rig: Node3D = null @@ -32,7 +39,25 @@ func apply_camera() -> void: func zoom(delta: float) -> void: - cam_distance = clampf(cam_distance - delta, 4.0, 22.0) + if cam_zoom_tween == null or not cam_zoom_tween.is_running(): + cam_target_distance = cam_distance + cam_target_distance = clampf( + cam_target_distance - (delta * CAM_ZOOM_SENSITIVITY), + CAM_MIN_DISTANCE, + CAM_MAX_DISTANCE) + if cam_zoom_tween != null: + cam_zoom_tween.kill() + cam_zoom_tween = create_tween() + cam_zoom_tween.tween_method( + _set_distance, + cam_distance, + cam_target_distance, + CAM_ZOOM_TWEEN_SECONDS + ).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT) + + +func _set_distance(distance: float) -> void: + cam_distance = distance apply_camera() @@ -90,7 +115,7 @@ func apply_orbit(delta: Vector2) -> void: func apply_pan(delta: Vector2, cam_dist: float) -> void: var ps: float = cam_dist * 0.0015 var right: Vector3 = camera_rig.global_basis.x * delta.x * ps - var fwd: Vector3 = Vector3(camera_rig.global_basis.z.x, 0.0, camera_rig.global_basis.z.z).normalized() + var fwd: Vector3 = Vector3(camera_rig.global_basis.z.x, 0.0, -camera_rig.global_basis.z.z).normalized() cam_pivot += right + fwd * -delta.y * ps var pan_lim: float = clampf(max(float(Game.board_width()), float(Game.board_height())) * GameConstants.TILE_SPACING * 0.5, 6.0, 20.0) cam_pivot.x = clampf(cam_pivot.x, -pan_lim, pan_lim) diff --git a/Client/origin-client/scenes/game/components/hud/hud_controller.gd b/Client/origin-client/scenes/game/components/hud/hud_controller.gd index af91dc7..7a7f86e 100644 --- a/Client/origin-client/scenes/game/components/hud/hud_controller.gd +++ b/Client/origin-client/scenes/game/components/hud/hud_controller.gd @@ -1,106 +1,139 @@ class_name HudController -extends Node +extends Control -# ── Node refs (set from game_screen) ───────────────────────────────────────── +## Owns all permanent HUD elements: TopBar, SP-ST panel, ActionRail, DiscardViewer, +## SpectatorPanel. Emits signals for actions that GameScreen must handle. + +signal draw_requested +signal end_turn_requested +signal settings_requested +signal spectator_leave_requested + +# ── Scene node refs ─────────────────────────────────────────────────────────── + +@onready var _phase_lbl : Label = %PhaseLabel +@onready var _turn_lbl : Label = %TurnLabel +@onready var _turn_order_strip : HBoxContainer = %TurnOrderStrip +@onready var _opp_panel : HBoxContainer = %OpponentPanel +@onready var _opp_name_lbl : Label = %OppNameLabel +@onready var _opp_hand_lbl : Label = %OppHandLabel +@onready var _opp_deck_lbl : Label = %OppDeckLabel +@onready var _opp_discard_btn : Button = %OppDiscardBtn +@onready var _sp_lbl : Label = %SpLabel +@onready var _st_lbl : Label = %StLabel +@onready var _deck_lbl : Label = %DeckLabel +@onready var _discard_btn : Button = %DiscardBtn +@onready var _discard_lbl : Label = %DiscardLabel +@onready var _draw_btn : Button = %DrawBtn +@onready var _end_turn_btn : Button = %EndTurnBtn +@onready var _settings_btn : Button = %SettingsBtn +@onready var _spectator_leave_btn : Button = %SpectatorLeaveBtn +@onready var _dv_overlay : PanelContainer = %DiscardViewer +@onready var _dv_title : Label = %DVTitle +@onready var _dv_list : VBoxContainer = %DVList +@onready var _dv_close_btn : Button = %DVCloseBtn +@onready var _spectator_panel : PanelContainer = %SpectatorPlayersPanel +@onready var _spectator_list : VBoxContainer = %SpectatorPlayerList +@onready var _sp_st_panel : PanelContainer = $"SP-ST Panel Container" +@onready var _deck_discard_panel: Control = $"ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container" + +## Exposed so GameScreen can hand it to the Chat system. +@onready var chat_bubble_host : Control = %ChatBubbleHost -var phase_lbl: Label = null -var turn_lbl: Label = null -var turn_order_strip: HBoxContainer = null -var opp_panel: HBoxContainer = null -var opp_name_lbl: Label = null -var opp_hand_lbl: Label = null -var opp_deck_lbl: Label = null -var opp_discard_btn: Button = null -var sp_lbl: Label = null -var st_lbl: Label = null -var deck_lbl: Label = null -var discard_btn: Button = null -var discard_lbl: Label = null -var draw_btn: Button = null -var end_turn_btn: Button = null -var dv_overlay: PanelContainer = null -var dv_title: Label = null -var dv_list: VBoxContainer = null -var dv_close_btn: Button = null -var spectator_panel: PanelContainer = null -var spectator_list: VBoxContainer = null var is_spectating: bool = false +# ── Lifecycle ───────────────────────────────────────────────────────────────── + +func _ready() -> void: + _draw_btn.pressed.connect(func() -> void: draw_requested.emit()) + _end_turn_btn.pressed.connect(func() -> void: end_turn_requested.emit()) + _settings_btn.pressed.connect(func() -> void: settings_requested.emit()) + _discard_btn.pressed.connect(func() -> void: show_own_discard(Game.state)) + _opp_discard_btn.pressed.connect(func() -> void: show_opp_discard(Game.state)) + _dv_close_btn.pressed.connect(func() -> void: _dv_overlay.visible = false) + _spectator_leave_btn.pressed.connect(func() -> void: spectator_leave_requested.emit()) + # ── Public API ──────────────────────────────────────────────────────────────── +func enter_spectator_mode() -> void: + is_spectating = true + _sp_st_panel.visible = false + _deck_discard_panel.visible = false + _draw_btn.visible = false + _end_turn_btn.visible = false + _spectator_panel.visible = true + _spectator_leave_btn.visible = true + + func update_hud(state: Dictionary) -> void: var phase: String = state.get("phase", "") var turn: int = state.get("turnNumber", 1) - phase_lbl.text = "Phase: %s" % phase + _phase_lbl.text = "Phase: %s" % phase if is_spectating: update_hud_spectator(state) return - # ── Player path ─────────────────────────────────────────────────────────── var is_mine: bool = Game.is_my_turn() var my: Dictionary = Game.get_my_player() var opp: Dictionary = Game.get_opponent() - turn_lbl.text = "Turn %d — %s" % [turn, "Your turn" if is_mine else "Opponent's turn"] - turn_lbl.modulate = Color(0.4, 1.0, 0.5) if is_mine else Color(1.0, 0.6, 0.6) + _turn_lbl.text = "Turn %d — %s" % [turn, "Your turn" if is_mine else "Opponent's turn"] + _turn_lbl.modulate = Color(0.4, 1.0, 0.5) if is_mine else Color(1.0, 0.6, 0.6) - sp_lbl.text = "%d" % int(my.get("currentSp", 0)) - st_lbl.text = "%d" % int(my.get("currentSt", 0)) - deck_lbl.text = "%d" % int(my.get("deckCount", 0)) + _sp_lbl.text = "%d" % int(my.get("currentSp", 0)) + _st_lbl.text = "%d" % int(my.get("currentSt", 0)) + _deck_lbl.text = "%d" % int(my.get("deckCount", 0)) var discard: Array = my.get("discard", []) - discard_lbl.text = "%d" % max(0, discard.size()) + _discard_lbl.text = "%d" % max(0, discard.size()) - opp_name_lbl.text = Game.get_display_name(str(opp.get("accountId", ""))) - opp_hand_lbl.text = "Hand: %d" % int(opp.get("handCount", 0)) - opp_deck_lbl.text = "Deck: %d" % int(opp.get("deckCount", 0)) + _opp_name_lbl.text = Game.get_display_name(str(opp.get("accountId", ""))) + _opp_hand_lbl.text = "Hand: %d" % int(opp.get("handCount", 0)) + _opp_deck_lbl.text = "Deck: %d" % int(opp.get("deckCount", 0)) var all_players: Array = state.get("players", []) if all_players.size() > 2: - opp_panel.visible = false - turn_order_strip.visible = true + _opp_panel.visible = false + _turn_order_strip.visible = true rebuild_turn_order_strip(state) else: - opp_panel.visible = true - turn_order_strip.visible = false + _opp_panel.visible = true + _turn_order_strip.visible = false - draw_btn.visible = (phase == "Draw" and is_mine) - end_turn_btn.visible = (phase == "Main" and is_mine) - end_turn_btn.disabled = not is_mine + _draw_btn.visible = (phase == "Draw" and is_mine) + _end_turn_btn.visible = (phase == "Main" and is_mine) + _end_turn_btn.disabled = not is_mine if phase == "Placement": var my_arch: Dictionary = my.get("archSpirit", {}) var i_have_placed: bool = not my_arch.is_empty() and my_arch.get("position") != null if not i_have_placed: - phase_lbl.text = "Phase: Placement — click a tile to place your ArchSpirit" + _phase_lbl.text = "Phase: Placement — click a tile to place your ArchSpirit" else: - phase_lbl.text = "Phase: Placement — waiting for opponent…" + _phase_lbl.text = "Phase: Placement — waiting for opponent…" func update_hud_spectator(state: Dictionary) -> void: var turn: int = state.get("turnNumber", 1) var active_id: String = str(state.get("activePlayerAccountId", "")) var active_name: String = Game.get_display_name(active_id) - turn_lbl.text = "Turn %d — %s is acting" % [turn, active_name] - turn_lbl.modulate = Color(1.0, 0.76, 0.2) + _turn_lbl.text = "Turn %d — %s is acting" % [turn, active_name] + _turn_lbl.modulate = Color(1.0, 0.76, 0.2) - # Always hide the 2-player opponent panel; show turn strip for all player counts. - opp_panel.visible = false + _opp_panel.visible = false var all_players: Array = state.get("players", []) - turn_order_strip.visible = all_players.size() > 1 - if turn_order_strip.visible: + _turn_order_strip.visible = all_players.size() > 1 + if _turn_order_strip.visible: rebuild_turn_order_strip(state) - draw_btn.visible = false - end_turn_btn.visible = false + _draw_btn.visible = false + _end_turn_btn.visible = false rebuild_spectator_panel(state) -## Rebuild the spectator player-summary list. One row per player sorted by seatIndex. -## Shows name (with active-turn highlight), SP, ST, deck count, and a Discard button. func rebuild_spectator_panel(state: Dictionary) -> void: - for c in spectator_list.get_children(): + for c in _spectator_list.get_children(): c.queue_free() var active_id: String = str(state.get("activePlayerAccountId", "")) @@ -187,21 +220,17 @@ func rebuild_spectator_panel(state: Dictionary) -> void: disc_btn.disabled = true hbox.add_child(disc_btn) - spectator_list.add_child(row) + _spectator_list.add_child(row) -## Rebuild the turn-order chip strip for N-player games. -## One chip per player sorted by seatIndex; highlights the active player, -## dims eliminated players, and marks the local player as "You". func rebuild_turn_order_strip(state: Dictionary) -> void: - for c in turn_order_strip.get_children(): + for c in _turn_order_strip.get_children(): c.queue_free() var active_id: String = str(state.get("activePlayerAccountId", "")) var players: Array = state.get("players", []).duplicate() var team_colors: Dictionary = state.get("teamColors", {}) - # Sort by seatIndex so chips appear in turn order. players.sort_custom(func(a: Dictionary, b: Dictionary) -> bool: return int(a.get("seatIndex", 0)) < int(b.get("seatIndex", 0))) @@ -219,7 +248,6 @@ func rebuild_turn_order_strip(state: Dictionary) -> void: chip.self_modulate = Color(1, 1, 1, 0.3 if eliminated else (0.95 if is_active else 0.6)) chip.mouse_filter = Control.MOUSE_FILTER_STOP - # Team-color left border via StyleBoxFlat. var style: StyleBoxFlat = StyleBoxFlat.new() style.bg_color = Color(0.12, 0.12, 0.14, 0.85) style.border_width_left = 3 @@ -242,7 +270,6 @@ func rebuild_turn_order_strip(state: Dictionary) -> void: elif is_me: lbl.add_theme_color_override("font_color", Color(0.5, 1.0, 0.5)) - # Hover tooltip showing player specs (opponents only). if not is_me: var sp: int = int(p.get("currentSp", 0)) var st: int = int(p.get("currentSt", 0)) @@ -252,7 +279,7 @@ func rebuild_turn_order_strip(state: Dictionary) -> void: display, sp, st, hand, deck] chip.add_child(lbl) - turn_order_strip.add_child(chip) + _turn_order_strip.add_child(chip) func show_own_discard(state: Dictionary) -> void: @@ -264,18 +291,18 @@ func show_opp_discard(state: Dictionary) -> void: func show_discard_for(title: String, cards: Array) -> void: - dv_title.text = "%s (%d)" % [title, cards.size()] - for c in dv_list.get_children(): + _dv_title.text = "%s (%d)" % [title, cards.size()] + for c in _dv_list.get_children(): c.queue_free() if cards.is_empty(): var lbl: Label = Label.new() lbl.text = "(empty)" lbl.add_theme_color_override("font_color", Color(0.55, 0.55, 0.6)) - dv_list.add_child(lbl) + _dv_list.add_child(lbl) else: for card: Dictionary in cards: - dv_list.add_child(make_discard_row(card)) - dv_overlay.visible = true + _dv_list.add_child(make_discard_row(card)) + _dv_overlay.visible = true func make_discard_row(card: Dictionary) -> Control: diff --git a/Client/origin-client/scenes/game/components/hud/hud_controller.tscn b/Client/origin-client/scenes/game/components/hud/hud_controller.tscn new file mode 100644 index 0000000..867bc41 --- /dev/null +++ b/Client/origin-client/scenes/game/components/hud/hud_controller.tscn @@ -0,0 +1,407 @@ +[gd_scene load_steps=15 format=3 uid="uid://doy6e5sb5bk48"] + +[ext_resource type="Script" uid="uid://c0cr5qgneoab1" path="res://scenes/game/components/hud/hud_controller.gd" id="1_script"] +[ext_resource type="Texture2D" uid="uid://dvmripj4jux0b" path="res://icons/SP-Symbol-White.png" id="2_sp"] +[ext_resource type="Texture2D" uid="uid://csvmdo2kwnh7c" path="res://icons/ST-Symbol-White.png" id="3_st"] +[ext_resource type="Texture2D" uid="uid://beyeu0y34m3v4" path="res://ui/icons/Deck Icon.png" id="4_deck"] +[ext_resource type="Texture2D" uid="uid://c65s8sn4p7s37" path="res://ui/icons/Discard Icon.png" id="5_discard"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_spst"] + +[sub_resource type="Theme" id="Theme_tex"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_action"] +bg_color = Color(0.38039216, 0.38039216, 0.38039216, 0.58431375) + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_disc_normal"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_disc_pressed"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_disc_hover"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_disc_hovpressed"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_disc_disabled"] + +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_disc_focus"] + +[node name="HudController" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +script = ExtResource("1_script") + +[node name="TopBar" type="HBoxContainer" parent="."] +layout_mode = 0 +anchor_right = 1.0 +offset_bottom = 48.0 +theme_override_constants/separation = 0 + +[node name="PhaseLabel" type="Label" parent="TopBar"] +unique_name_in_owner = true +custom_minimum_size = Vector2(140, 48) +layout_mode = 2 +theme_override_font_sizes/font_size = 13 +text = "Phase: —" +vertical_alignment = 1 + +[node name="TurnLabel" type="Label" parent="TopBar"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 13 +text = "Turn 1 — Your turn" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="TurnOrderStrip" type="HBoxContainer" parent="TopBar"] +unique_name_in_owner = true +visible = false +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/separation = 4 + +[node name="OpponentPanel" type="HBoxContainer" parent="TopBar"] +unique_name_in_owner = true +custom_minimum_size = Vector2(240, 48) +layout_mode = 2 +theme_override_constants/separation = 8 + +[node name="OppNameLabel" type="Label" parent="TopBar/OpponentPanel"] +unique_name_in_owner = true +modulate = Color(1, 0.5, 0.5, 1) +layout_mode = 2 +theme_override_font_sizes/font_size = 12 +text = "Opponent" +vertical_alignment = 1 + +[node name="OppHandLabel" type="Label" parent="TopBar/OpponentPanel"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 12 +text = "Hand: 0" +vertical_alignment = 1 + +[node name="OppDeckLabel" type="Label" parent="TopBar/OpponentPanel"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 12 +text = "Deck: 0" +vertical_alignment = 1 + +[node name="OppDiscardBtn" type="Button" parent="TopBar/OpponentPanel"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 11 +text = "Discard" + +[node name="SP-ST Panel Container" type="PanelContainer" parent="."] +layout_mode = 0 +anchor_top = 0.675 +anchor_bottom = 0.675 +offset_top = -156.40002 +offset_right = 76.0 +offset_bottom = -0.4000244 +theme_override_styles/panel = SubResource("StyleBoxEmpty_spst") + +[node name="VBoxContainer" type="VBoxContainer" parent="SP-ST Panel Container"] +layout_mode = 2 +alignment = 2 + +[node name="TextureRect" type="TextureRect" parent="SP-ST Panel Container/VBoxContainer"] +self_modulate = Color(0, 0.8117647, 0.77254903, 0.38039216) +texture_filter = 5 +custom_minimum_size = Vector2(1.78, 76) +layout_mode = 2 +theme = SubResource("Theme_tex") +texture = ExtResource("2_sp") +expand_mode = 1 + +[node name="SpLabel" type="Label" parent="SP-ST Panel Container/VBoxContainer/TextureRect"] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.513 +anchor_top = 0.36800003 +anchor_right = 0.513 +anchor_bottom = 0.36800003 +offset_left = -18.987999 +offset_top = -22.968002 +offset_right = 19.012001 +offset_bottom = 23.031998 +tooltip_text = "Spirit Points" +mouse_filter = 1 +theme_override_colors/font_color = Color(0.012617188, 0.012617188, 0.012617188, 1) +theme_override_font_sizes/font_size = 33 +text = "88" +horizontal_alignment = 1 +vertical_alignment = 1 +metadata/_edit_use_anchors_ = true + +[node name="TextureRect2" type="TextureRect" parent="SP-ST Panel Container/VBoxContainer"] +self_modulate = Color(0, 0.8117647, 0.77254903, 0.38039216) +texture_filter = 5 +custom_minimum_size = Vector2(1.78, 76) +layout_mode = 2 +theme = SubResource("Theme_tex") +texture = ExtResource("3_st") +expand_mode = 1 + +[node name="StLabel" type="Label" parent="SP-ST Panel Container/VBoxContainer/TextureRect2"] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.5 +anchor_top = 0.32200003 +anchor_right = 0.5 +anchor_bottom = 0.32200003 +offset_left = -20.0 +offset_top = -20.472002 +offset_right = 22.0 +offset_bottom = 25.527998 +tooltip_text = "Sacrifice Tokens" +mouse_filter = 1 +theme_override_colors/font_color = Color(0.06469653, 0.06469653, 0.06469653, 1) +theme_override_font_sizes/font_size = 33 +text = "88" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ActionRail" type="PanelContainer" parent="."] +layout_mode = 0 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -262.0 +offset_top = -220.0 +offset_right = -70.0 +offset_bottom = -56.0 +grow_horizontal = 0 +grow_vertical = 0 +theme_override_styles/panel = SubResource("StyleBoxFlat_action") + +[node name="RailMargin" type="MarginContainer" parent="ActionRail"] +layout_mode = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 8 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 8 + +[node name="RailHBox" type="HBoxContainer" parent="ActionRail/RailMargin"] +layout_mode = 2 +theme_override_constants/separation = 12 + +[node name="Deck-Discard Panel Container" type="Control" parent="ActionRail/RailMargin/RailHBox"] +custom_minimum_size = Vector2(76, 0) +layout_mode = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +alignment = 2 + +[node name="TextureRect" type="TextureRect" parent="ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer"] +self_modulate = Color(0, 0.8117647, 0.77254903, 0.38039216) +texture_filter = 5 +custom_minimum_size = Vector2(1.78, 76) +layout_mode = 2 +theme = SubResource("Theme_tex") +texture = ExtResource("4_deck") +expand_mode = 1 + +[node name="DeckLabel" type="Label" parent="ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer/TextureRect"] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.507 +anchor_top = 0.40789473 +anchor_right = 0.507 +anchor_bottom = 0.40789473 +offset_left = -22.532001 +offset_top = -36.0 +offset_right = 22.467999 +offset_bottom = 10.0 +grow_horizontal = 2 +grow_vertical = 2 +tooltip_text = "Cards in Deck" +mouse_filter = 1 +theme_override_colors/font_color = Color(0, 0, 0, 1) +theme_override_font_sizes/font_size = 33 +text = "88" +horizontal_alignment = 1 +vertical_alignment = 1 +metadata/_edit_use_anchors_ = true + +[node name="TextureRect2" type="TextureRect" parent="ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer"] +self_modulate = Color(0, 0.8117647, 0.77254903, 0.38039216) +texture_filter = 5 +custom_minimum_size = Vector2(1.78, 76) +layout_mode = 2 +theme = SubResource("Theme_tex") +expand_mode = 1 + +[node name="DiscardBtn" type="Button" parent="ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer/TextureRect2"] +unique_name_in_owner = true +layout_mode = 0 +offset_left = -4.000001 +offset_top = -5.000001 +offset_right = 568.0 +offset_bottom = 275.0 +scale = Vector2(0.14754085, 0.23068035) +tooltip_text = "View Discard" +theme_override_colors/icon_normal_color = Color(0.18431373, 0.49411765, 0.47843137, 1) +theme_override_colors/icon_focus_color = Color(0.18431373, 0.49411765, 0.47843137, 1) +theme_override_colors/icon_pressed_color = Color(0.35976923, 0.7944459, 0.77106035, 1) +theme_override_colors/icon_hover_color = Color(0.18431373, 0.49411765, 0.47843137, 1) +theme_override_colors/icon_hover_pressed_color = Color(0.18431373, 0.49411765, 0.47843137, 1) +theme_override_font_sizes/font_size = 12 +theme_override_icons/icon = ExtResource("5_discard") +theme_override_styles/normal = SubResource("StyleBoxEmpty_disc_normal") +theme_override_styles/pressed = SubResource("StyleBoxEmpty_disc_pressed") +theme_override_styles/hover = SubResource("StyleBoxEmpty_disc_hover") +theme_override_styles/hover_pressed = SubResource("StyleBoxEmpty_disc_hovpressed") +theme_override_styles/disabled = SubResource("StyleBoxEmpty_disc_disabled") +theme_override_styles/focus = SubResource("StyleBoxEmpty_disc_focus") + +[node name="DiscardLabel" type="Label" parent="ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container/VBoxContainer/TextureRect2"] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.5 +anchor_top = 0.32200003 +anchor_right = 0.5 +anchor_bottom = 0.32200003 +offset_left = -20.0 +offset_top = -31.472002 +offset_right = 22.0 +offset_bottom = 14.527998 +theme_override_colors/font_color = Color(0.06469653, 0.06469653, 0.06469653, 1) +theme_override_font_sizes/font_size = 33 +text = "88" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Controls" type="Control" parent="ActionRail/RailMargin/RailHBox"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="RightVBox" type="VBoxContainer" parent="ActionRail/RailMargin/RailHBox/Controls"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/separation = 6 + +[node name="EndTurnBtn" type="Button" parent="ActionRail/RailMargin/RailHBox/Controls/RightVBox"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 36) +layout_mode = 2 +theme_override_font_sizes/font_size = 13 +text = "End Turn" + +[node name="DrawBtn" type="Button" parent="ActionRail/RailMargin/RailHBox/Controls/RightVBox"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 36) +layout_mode = 2 +theme_override_font_sizes/font_size = 13 +text = "Draw Card" + +[node name="SettingsBtn" type="Button" parent="ActionRail/RailMargin/RailHBox/Controls/RightVBox"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 36) +layout_mode = 2 +theme_override_font_sizes/font_size = 12 +text = "Settings" + +[node name="ChatBubbleHost" type="Control" parent="ActionRail/RailMargin/RailHBox/Controls/RightVBox"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 36) +layout_mode = 2 + +[node name="SpectatorLeaveBtn" type="Button" parent="ActionRail/RailMargin/RailHBox/Controls/RightVBox"] +unique_name_in_owner = true +visible = false +custom_minimum_size = Vector2(0, 36) +layout_mode = 2 +theme_override_font_sizes/font_size = 12 +text = "Leave Spectator" + +[node name="DiscardViewer" type="PanelContainer" parent="."] +unique_name_in_owner = true +visible = false +layout_mode = 0 +anchor_left = 0.1 +anchor_top = 0.05 +anchor_right = 0.9 +anchor_bottom = 0.95 + +[node name="DVMargin" type="MarginContainer" parent="DiscardViewer"] +layout_mode = 2 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 12 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 12 + +[node name="DVVBox" type="VBoxContainer" parent="DiscardViewer/DVMargin"] +layout_mode = 2 +theme_override_constants/separation = 8 + +[node name="DVTitle" type="Label" parent="DiscardViewer/DVMargin/DVVBox"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 16 +text = "Discard Pile" + +[node name="DVScroll" type="ScrollContainer" parent="DiscardViewer/DVMargin/DVVBox"] +layout_mode = 2 +size_flags_vertical = 3 +horizontal_scroll_mode = 0 + +[node name="DVList" type="VBoxContainer" parent="DiscardViewer/DVMargin/DVVBox/DVScroll"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/separation = 4 + +[node name="DVCloseBtn" type="Button" parent="DiscardViewer/DVMargin/DVVBox"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 36) +layout_mode = 2 +theme_override_font_sizes/font_size = 13 +text = "Close" + +[node name="SpectatorPlayersPanel" type="PanelContainer" parent="."] +unique_name_in_owner = true +visible = false +layout_mode = 0 +anchor_top = 1.0 +anchor_right = 0.75 +anchor_bottom = 1.0 +offset_top = -200.0 + +[node name="SpectatorMargin" type="MarginContainer" parent="SpectatorPlayersPanel"] +layout_mode = 2 +theme_override_constants/margin_left = 8 +theme_override_constants/margin_top = 8 +theme_override_constants/margin_right = 8 +theme_override_constants/margin_bottom = 8 + +[node name="SpectatorScroll" type="ScrollContainer" parent="SpectatorPlayersPanel/SpectatorMargin"] +layout_mode = 2 +size_flags_vertical = 3 +horizontal_scroll_mode = 0 + +[node name="SpectatorPlayerList" type="VBoxContainer" parent="SpectatorPlayersPanel/SpectatorMargin/SpectatorScroll"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/separation = 4 diff --git a/Client/origin-client/scenes/game/components/overlays/game_over_overlay.gd b/Client/origin-client/scenes/game/components/overlays/game_over_overlay.gd index 19e0bf5..eb78a4d 100644 --- a/Client/origin-client/scenes/game/components/overlays/game_over_overlay.gd +++ b/Client/origin-client/scenes/game/components/overlays/game_over_overlay.gd @@ -1,13 +1,17 @@ class_name GameOverOverlay -extends Node +extends PanelContainer -## Manages the end-of-game Victory/Defeat overlay. -## Node refs are set by game_screen after scene is ready. +## End-of-game Victory/Defeat overlay. +## Self-contained: wires its own button and handles scene transitions internally. + +@onready var _result_lbl : Label = %GOResultLabel +@onready var _rank_lbl : Label = %GORankLabel +@onready var _menu_btn : Button = %GOMainMenuBtn + +func _ready() -> void: + _menu_btn.pressed.connect(func() -> void: + get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")) -var go_overlay: PanelContainer = null -var go_result_lbl: Label = null -var go_rank_lbl: Label = null -var go_menu_btn: Button = null func show_result(winner_id: String, win_condition: String, winner_delta: int, loser_delta: int, @@ -23,8 +27,8 @@ func show_result(winner_id: String, win_condition: String, else: i_won = (winner_id == Auth.user_id) - go_result_lbl.text = "Victory!" if i_won else "Defeat" - go_result_lbl.modulate = Color(0.4, 1.0, 0.5) if i_won else Color(1.0, 0.4, 0.4) + _result_lbl.text = "Victory!" if i_won else "Defeat" + _result_lbl.modulate = Color(0.4, 1.0, 0.5) if i_won else Color(1.0, 0.4, 0.4) if not player_outcomes.is_empty(): var outcome_lines: Array = [] @@ -35,12 +39,12 @@ func show_result(winner_id: String, win_condition: String, var sign: String = "+" if rd >= 0 else "" var label: String = "You" if pid == Auth.user_id else Game.get_display_name(pid) outcome_lines.append("%s: %s (%s%d)" % [label, oc, sign, rd]) - go_rank_lbl.text = "[%s]\n" % win_condition + "\n".join(outcome_lines) + _rank_lbl.text = "[%s]\n" % win_condition + "\n".join(outcome_lines) else: var my_delta: int = winner_delta if i_won else loser_delta - go_rank_lbl.text = "Win by %s | Rank %s%d" % [ + _rank_lbl.text = "Win by %s | Rank %s%d" % [ win_condition, "+" if my_delta >= 0 else "", my_delta] - go_overlay.visible = true + visible = true func on_session_abandoned(_reason: String) -> void: diff --git a/Client/origin-client/scenes/game/components/overlays/game_over_overlay.tscn b/Client/origin-client/scenes/game/components/overlays/game_over_overlay.tscn new file mode 100644 index 0000000..4a6251f --- /dev/null +++ b/Client/origin-client/scenes/game/components/overlays/game_over_overlay.tscn @@ -0,0 +1,43 @@ +[gd_scene load_steps=2 format=3 uid="uid://game_over_overlay"] + +[ext_resource type="Script" path="res://scenes/game/components/overlays/game_over_overlay.gd" id="1_script"] + +[node name="GameOverOverlay" type="PanelContainer"] +visible = false +anchors_preset = -1 +anchor_left = 0.25 +anchor_top = 0.25 +anchor_right = 0.75 +anchor_bottom = 0.75 +script = ExtResource("1_script") + +[node name="GOMargin" type="MarginContainer" parent="."] +layout_mode = 2 +theme_override_constants/margin_left = 24 +theme_override_constants/margin_top = 24 +theme_override_constants/margin_right = 24 +theme_override_constants/margin_bottom = 24 + +[node name="GOVBox" type="VBoxContainer" parent="GOMargin"] +layout_mode = 2 +theme_override_constants/separation = 16 + +[node name="GOResultLabel" type="Label" parent="GOMargin/GOVBox"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 28 +text = "Game Over" +horizontal_alignment = 1 + +[node name="GORankLabel" type="Label" parent="GOMargin/GOVBox"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_font_sizes/font_size = 15 +horizontal_alignment = 1 + +[node name="GOMainMenuBtn" type="Button" parent="GOMargin/GOVBox"] +unique_name_in_owner = true +custom_minimum_size = Vector2(0, 44) +layout_mode = 2 +theme_override_font_sizes/font_size = 15 +text = "Return to Main Menu" diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 55cde38..88ab38b 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -1,10 +1,15 @@ extends Node3D ## GameScreen — slim orchestrator. ## All gameplay logic lives in components under scenes/game/components/. -## This script instantiates them, sets their external refs, wires their signals, -## and fans out Game signals to the appropriate handler. +## HUD components are now individual instanced scenes; this script wires their +## signals and fans out Game signals to the appropriate handlers. ## -## Components owned: +## Scene-based components (instanced in GameScreen.tscn): +## _hud_ctrl HudController — TopBar, SP-ST, ActionRail, DiscardViewer, SpectatorPanel +## _hand_mgr HandManager — fan arc hand, card popups, spin buttons +## _game_over GameOverOverlay — Victory / Defeat overlay +## +## Code-only components (created via .new() in _ready): ## _board_ctrl BoardController — tile mesh build, affinity updates ## _cam_ctrl CameraController — yaw/pitch/distance, tweens ## _pathfinder Pathfinder — coord↔world, BFS, raycasts @@ -13,17 +18,20 @@ extends Node3D ## _mesh_builder UnitMeshBuilder — unit StaticBody3D + mesh lifecycle ## _animator UnitAnimator — move/damage/hitsplat animations ## _input_handler BoardInputHandler — mouse/touch → typed signals -## _hud_ctrl HudController — HUD labels, turn strip, discard viewer -## _hand_mgr HandManager — fan arc hand, card popups, spin btns ## _tile_drawer TileDrawer — slide-in tile detail panel ## _skybox SkyboxController — procedural / CDN / live skybox -## _game_over GameOverOverlay — Victory / Defeat overlay ## _inactive_dlgs InactiveDialogs — inactivity / elimination dialogs ## _sel_ctrl SelectionController — mode state, board-click dispatch ## _abt AbilityTargeting — ability panel, targeting UI, send ## _prompt_handler ServerPromptHandler — server-driven ability-pause prompts -# ── Component node vars ─────────────────────────────────────────────────────── +# ── Scene-based component vars ──────────────────────────────────────────────── + +@onready var _hud_ctrl : HudController = $HUD/HudController +@onready var _hand_mgr : HandManager = $HUD/HandManager +@onready var _game_over : GameOverOverlay = $HUD/GameOverOverlay + +# ── Code-only component vars ────────────────────────────────────────────────── var _board_ctrl : BoardController = null var _cam_ctrl : CameraController = null @@ -33,79 +41,37 @@ var _tile_resolver : TileTargetResolver = null var _mesh_builder : UnitMeshBuilder = null var _animator : UnitAnimator = null var _input_handler : BoardInputHandler = null -var _hud_ctrl : HudController = null -var _hand_mgr : HandManager = null var _tile_drawer : TileDrawer = null var _skybox : SkyboxController = null -var _game_over : GameOverOverlay = null var _inactive_dlgs : InactiveDialogs = null var _sel_ctrl : SelectionController = null var _abt : AbilityTargeting = null var _prompt_handler: ServerPromptHandler = null -# ── @onready node refs (bound to scene tree) ────────────────────────────────── +# ── @onready node refs ──────────────────────────────────────────────────────── -@onready var _camera_rig : Node3D = $CameraRig -@onready var _camera : Camera3D = $CameraRig/Camera3D -@onready var _tiles_root : Node3D = $BoardRoot/TilesRoot -@onready var _units_root : Node3D = $BoardRoot/UnitsRoot -@onready var _hi_root : Node3D = $BoardRoot/HighlightsRoot -@onready var _hold_timer : Timer = $HoldTimer -@onready var _cam_gesture_timer : Timer = $CamGestureTimer -@onready var _cam_ctrl_panel : Control = %CamCtrlPanel -@onready var _cam_orbit_btn : Button = %CamOrbitBtn -@onready var _cam_pan_btn : Button = %CamPanBtn -@onready var _cam_zoom_btn : Button = %CamZoomBtn - -@onready var _phase_lbl : Label = %PhaseLabel -@onready var _turn_lbl : Label = %TurnLabel -@onready var _turn_order_strip : HBoxContainer = %TurnOrderStrip -@onready var _opp_panel : HBoxContainer = %OpponentPanel -@onready var _opp_name_lbl : Label = %OppNameLabel -@onready var _opp_hand_lbl : Label = %OppHandLabel -@onready var _opp_deck_lbl : Label = %OppDeckLabel -@onready var _opp_discard_btn : Button = %OppDiscardBtn -@onready var _hand_cards : Control = %HandCards -@onready var _sp_lbl : Label = %SpLabel -@onready var _st_lbl : Label = %StLabel -@onready var _deck_lbl : Label = %DeckLabel -@onready var _discard_btn : Button = %DiscardBtn -@onready var _discard_lbl : Label = %DiscardLabel -@onready var _draw_btn : Button = %DrawBtn -@onready var _end_turn_btn : Button = %EndTurnBtn -@onready var _settings_btn : Button = %SettingsBtn -@onready var _chat_bubble_host : Control = %ChatBubbleHost -@onready var _tile_drawer_toggle_btn : Button = %TileDrawerToggleBtn -@onready var _in_game_settings: PanelContainer = %InGameSettings -@onready var _ctx_popup : PanelContainer = %ContextPopup -@onready var _ctx_tile_lbl : Label = %ContextTileLabel -@onready var _ctx_unit_lbl : Label = %ContextUnitLabel -@onready var _ctx_abil_lbl : Label = %ContextAbilitiesLabel -@onready var _ctx_close_btn : Button = %ContextClose -@onready var _dv_overlay : PanelContainer = %DiscardViewer -@onready var _dv_title : Label = %DVTitle -@onready var _dv_list : VBoxContainer = %DVList -@onready var _dv_close_btn : Button = %DVCloseBtn -@onready var _go_overlay : PanelContainer = %GameOverOverlay -@onready var _go_result_lbl : Label = %GOResultLabel -@onready var _go_rank_lbl : Label = %GORankLabel -@onready var _go_menu_btn : Button = %GOMainMenuBtn -@onready var _hud : CanvasLayer = $HUD -@onready var _hand_area : PanelContainer = $HUD/HandArea -@onready var _hand_spin_left : TextureButton = %HandSpinLeft -@onready var _hand_spin_right : TextureButton = %HandSpinRight -@onready var _sp_st_panel : PanelContainer = $"HUD/SP-ST Panel Container" -@onready var _deck_discard_panel : Control = $"HUD/ActionRail/RailMargin/RailHBox/Deck-Discard Panel Container" -@onready var _spectator_panel : PanelContainer = %SpectatorPlayersPanel -@onready var _spectator_list : VBoxContainer = %SpectatorPlayerList -@onready var _spectator_leave_btn : Button = %SpectatorLeaveBtn +@onready var _camera_rig : Node3D = $CameraRig +@onready var _camera : Camera3D = $CameraRig/Camera3D +@onready var _tiles_root : Node3D = $BoardRoot/TilesRoot +@onready var _units_root : Node3D = $BoardRoot/UnitsRoot +@onready var _hi_root : Node3D = $BoardRoot/HighlightsRoot +@onready var _hold_timer : Timer = $HoldTimer +@onready var _cam_gesture_timer : Timer = $CamGestureTimer +@onready var _cam_ctrl_panel : Control = %CamCtrlPanel +@onready var _cam_orbit_btn : Button = %CamOrbitBtn +@onready var _cam_pan_btn : Button = %CamPanBtn +@onready var _cam_zoom_btn : Button = %CamZoomBtn +@onready var _hud : CanvasLayer = $HUD +@onready var _in_game_settings : PanelContainer = %InGameSettings +@onready var _ctx_popup : PanelContainer = %ContextPopup +@onready var _ctx_tile_lbl : Label = %ContextTileLabel +@onready var _ctx_unit_lbl : Label = %ContextUnitLabel +@onready var _ctx_abil_lbl : Label = %ContextAbilitiesLabel +@onready var _ctx_close_btn : Button = %ContextClose +@onready var _tile_drawer_toggle_btn : Button = %TileDrawerToggleBtn # ── Preloaded assets ────────────────────────────────────────────────────────── -const _CARD_WIDGET_SCENE := preload("res://scenes/collection/components/CardWidget.tscn") -const _HAND_ARROW_REGULAR := preload("res://ui/icons/Green_Gem_Arrow_Button_Regular.png") -const _HAND_ARROW_HOVER := preload("res://ui/icons/Green_Gem_Arrow_Button_Hover.png") -const _HAND_ARROW_PRESSED := preload("res://ui/icons/Green_Gem_Arrow_Button_Click.png") const _HITSPLAT_SHIELD_ICON := preload("res://ui/icons/Shield_Overlay_Gradient.png") const _HITSPLAT_HEART_ICON := preload("res://ui/icons/Heart_Overlay_Gradient.png") @@ -115,7 +81,7 @@ const TILE_SPACING : float = 1.1 const HEX_TILE_RADIUS : float = 0.577 const HEX_TILE_SPACING : float = 1.0 const MOVE_STEP_SECS : float = 0.28 -const POST_ANIM_SECS : float = 1.2 +const POST_ANIM_SECS : float = 2.0 const SKY_ROTATION_SPEED : float = 0.026 # ── Minimal orchestrator state ──────────────────────────────────────────────── @@ -128,7 +94,6 @@ var _last_click_iid : String = "" var _rebuild_pending : bool = false var _pending_rebuild_state: Dictionary = {} -# Hover cursor quads (permanently allocated, managed inline here) var _cursor_highlight : MeshInstance3D = null var _hover_team_overlay : MeshInstance3D = null var _hovered_coord : Vector2i = Vector2i(-1, -1) @@ -137,7 +102,7 @@ var _hovered_unit_mesh : MeshInstance3D = null # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: - # ── 1. Critical game signals (connect before anything that can error) ────── + # ── 1. Critical game signals ─────────────────────────────────────────────── Game.state_updated.connect(_on_state_updated) Game.game_over.connect(_on_game_over) Game.session_abandoned.connect(_on_session_abandoned) @@ -147,7 +112,7 @@ func _ready() -> void: Game.player_eliminated.connect(_on_player_eliminated) HighlightConfig.texture_loaded.connect(_on_highlight_texture_loaded) - # ── 2. Instantiate and configure components ──────────────────────────────── + # ── 2. Instantiate and configure code-only components ───────────────────── # Pathfinder _pathfinder = Pathfinder.new() @@ -206,41 +171,6 @@ func _ready() -> void: _skybox.world_environment = $WorldEnvironment add_child(_skybox) - # HudController - _hud_ctrl = HudController.new() - _hud_ctrl.phase_lbl = _phase_lbl - _hud_ctrl.turn_lbl = _turn_lbl - _hud_ctrl.turn_order_strip = _turn_order_strip - _hud_ctrl.opp_panel = _opp_panel - _hud_ctrl.opp_name_lbl = _opp_name_lbl - _hud_ctrl.opp_hand_lbl = _opp_hand_lbl - _hud_ctrl.opp_deck_lbl = _opp_deck_lbl - _hud_ctrl.opp_discard_btn = _opp_discard_btn - _hud_ctrl.sp_lbl = _sp_lbl - _hud_ctrl.st_lbl = _st_lbl - _hud_ctrl.deck_lbl = _deck_lbl - _hud_ctrl.discard_btn = _discard_btn - _hud_ctrl.discard_lbl = _discard_lbl - _hud_ctrl.draw_btn = _draw_btn - _hud_ctrl.end_turn_btn = _end_turn_btn - _hud_ctrl.dv_overlay = _dv_overlay - _hud_ctrl.dv_title = _dv_title - _hud_ctrl.dv_list = _dv_list - _hud_ctrl.dv_close_btn = _dv_close_btn - _hud_ctrl.spectator_panel = _spectator_panel - _hud_ctrl.spectator_list = _spectator_list - add_child(_hud_ctrl) - - # HandManager - _hand_mgr = HandManager.new() - _hand_mgr.hand_cards = _hand_cards - _hand_mgr.hand_area = _hand_area - _hand_mgr.hand_spin_left = _hand_spin_left - _hand_mgr.hand_spin_right = _hand_spin_right - _hand_mgr.hud = _hud - add_child(_hand_mgr) - _hand_mgr.hand_card_clicked.connect(_on_hand_card_clicked) - # TileDrawer _tile_drawer = TileDrawer.new() _tile_drawer.hud = _hud @@ -251,14 +181,6 @@ func _ready() -> void: func(world_pos: Vector3) -> void: _cam_ctrl.tween_to_pivot(world_pos) ) - # GameOverOverlay - _game_over = GameOverOverlay.new() - _game_over.go_overlay = _go_overlay - _game_over.go_result_lbl = _go_result_lbl - _game_over.go_rank_lbl = _go_rank_lbl - _game_over.go_menu_btn = _go_menu_btn - add_child(_game_over) - # InactiveDialogs _inactive_dlgs = InactiveDialogs.new() add_child(_inactive_dlgs) @@ -311,7 +233,7 @@ func _ready() -> void: _input_handler = BoardInputHandler.new() _input_handler.hold_timer = _hold_timer _input_handler.cam_gesture_timer = _cam_gesture_timer - _input_handler.hand_area = _hand_area + _input_handler.hand_area = _hand_mgr # HandManager IS the PanelContainer _input_handler.camera_rig = _camera_rig _input_handler.cam_distance = _cam_ctrl.cam_distance _input_handler.fn_mouse_to_tile_coord = func(pos: Vector2) -> Vector2i: @@ -327,29 +249,22 @@ func _ready() -> void: _input_handler.hand_scroll.connect(_on_hand_scroll) _input_handler.deselect_pending.connect(_on_deselect_pending) - # ── 3. Route server prompt signals to components ─────────────────────────── - Game.triggered_target_request.connect(_abt.on_triggered_target_request) - Game.cost_pick_request.connect(_prompt_handler.on_cost_pick_request) - Game.cost_group_pick_request.connect(_prompt_handler.on_cost_group_pick_request) - Game.action_group_pick_request.connect(_prompt_handler.on_action_group_pick_request) - Game.branch_pick_request.connect(_prompt_handler.on_branch_pick_request) - Game.target_pick_request.connect(_prompt_handler.on_target_pick_request) - Game.tile_pick_request.connect(_prompt_handler.on_tile_pick_request) - Game.player_pick_request.connect(_prompt_handler.on_player_pick_request) - Game.reveal_choice_pick_request.connect(_prompt_handler.on_reveal_choice_pick_request) + # ── 3. Wire scene-based components ──────────────────────────────────────── - # ── 4. HUD button wiring ────────────────────────────────────────────────── - _draw_btn.pressed.connect(_on_draw_pressed) - _end_turn_btn.pressed.connect(_on_end_turn_pressed) - _settings_btn.pressed.connect(func() -> void: _in_game_settings.open()) - _discard_btn.pressed.connect( - func() -> void: _hud_ctrl.show_own_discard(Game.state)) - _opp_discard_btn.pressed.connect( - func() -> void: _hud_ctrl.show_opp_discard(Game.state)) + # HandManager (scene already ready; just connect its signal) + _hand_mgr.hand_card_clicked.connect(_on_hand_card_clicked) + _hand_mgr.hand_spin_requested.connect(_on_hand_scroll) + + # HudController signals + _hud_ctrl.draw_requested.connect(_on_draw_pressed) + _hud_ctrl.end_turn_requested.connect(_on_end_turn_pressed) + _hud_ctrl.settings_requested.connect(func() -> void: _in_game_settings.open()) + _hud_ctrl.spectator_leave_requested.connect(func() -> void: + Game.stop_spectating() + get_tree().change_scene_to_file("res://scenes/free_play/FreePlayScreen.tscn")) + + # ── 4. Remaining HUD button wiring ──────────────────────────────────────── _ctx_close_btn.pressed.connect(func() -> void: _ctx_popup.visible = false) - _dv_close_btn.pressed.connect(func() -> void: _dv_overlay.visible = false) - _go_menu_btn.pressed.connect(func() -> void: - get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")) _hold_timer.timeout.connect(_on_hold_timer_fired) _cam_gesture_timer.timeout.connect( func() -> void: _cam_ctrl.on_cam_gesture_timer_fired(_input_handler.gesture_finger_count) @@ -369,13 +284,20 @@ func _ready() -> void: _cam_ctrl.on_cam_zoom_btn_toggled(p) _input_handler.touch_cam_zoom = p and _cam_ctrl.cam_zoom_btn.button_pressed ) - _hand_area.resized.connect(_hand_mgr.queue_hand_layout) - _hand_area.resized.connect(_hand_mgr.layout_hand_spin_buttons) - _hand_cards.resized.connect(_hand_mgr.queue_hand_layout) - _hand_mgr.configure_hand_spin_buttons() _tile_drawer_toggle_btn.pressed.connect(_tile_drawer.on_tile_drawer_toggle_pressed) - # ── 5. Camera, skybox, hover, chat ──────────────────────────────────────── + # ── 5. Route server prompt signals to components ────────────────────────── + Game.triggered_target_request.connect(_abt.on_triggered_target_request) + Game.cost_pick_request.connect(_prompt_handler.on_cost_pick_request) + Game.cost_group_pick_request.connect(_prompt_handler.on_cost_group_pick_request) + Game.action_group_pick_request.connect(_prompt_handler.on_action_group_pick_request) + Game.branch_pick_request.connect(_prompt_handler.on_branch_pick_request) + Game.target_pick_request.connect(_prompt_handler.on_target_pick_request) + Game.tile_pick_request.connect(_prompt_handler.on_tile_pick_request) + Game.player_pick_request.connect(_prompt_handler.on_player_pick_request) + Game.reveal_choice_pick_request.connect(_prompt_handler.on_reveal_choice_pick_request) + + # ── 6. Camera, skybox, hover, chat ─────────────────────────────────────── _cam_ctrl.sync_cam_ctrl_panel() Settings.settings_changed.connect( func() -> void: @@ -386,9 +308,9 @@ func _ready() -> void: _skybox.setup_environment() _init_cursor_nodes() Chat.claim_bubble_visibility(self) - Chat.set_bubble_host(_chat_bubble_host) + Chat.set_bubble_host(_hud_ctrl.chat_bubble_host) - # ── 6. Spectator / initial state ────────────────────────────────────────── + # ── 7. Spectator / initial state ────────────────────────────────────────── if Game.is_spectating: _is_spectating = true _setup_spectator_ui() @@ -412,7 +334,6 @@ func _process(delta: float) -> void: func _exit_tree() -> void: if _is_spectating: Game.stop_spectating() - # Disconnect game signals (Godot auto-disconnects on queue_free, but be explicit). if Game.state_updated.is_connected(_on_state_updated): Game.state_updated.disconnect(_on_state_updated) if Game.game_over.is_connected(_on_game_over): @@ -459,7 +380,6 @@ func _on_state_updated(state: Dictionary) -> void: " mode=", _sel_ctrl.mode if _sel_ctrl != null else "n/a") _unit_reg.rebuild_ownership(state) - # Orient camera on first state that has playerOneAccountId. var p1_id: String = str(state.get("playerOneAccountId", "")) if not p1_id.is_empty(): _local_is_p1 = Auth.user_id.to_lower() == p1_id.to_lower() @@ -468,11 +388,9 @@ func _on_state_updated(state: Dictionary) -> void: _camera_oriented = true _orient_camera_to_player(state) - # Board build / affinity update. var board: Dictionary = state.get("board", {}) if _board_ctrl.tile_bodies.is_empty() and not board.is_empty(): _board_ctrl.build_board(board) - # Push grid info to pathfinder and sel_ctrl after board is known. _pathfinder.grid_type = str(board.get("gridType", "Square")) _pathfinder.hex_sides = int(board.get("hexSides", 0)) _sel_ctrl.board_grid_type = _pathfinder.grid_type @@ -483,21 +401,17 @@ func _on_state_updated(state: Dictionary) -> void: c.get("x", 0), c.get("y", 0), tile.get("resolvedAffinity", "Void")) - # Sync tile height maps into mesh_builder. _mesh_builder.tile_heights = _board_ctrl.tile_heights _mesh_builder.tile_y_bases = _board_ctrl.tile_y_bases - # Fire animations on existing nodes before rebuild. var move_dur: float = _animator.play_move_animations( state, _board_ctrl.tile_heights, _board_ctrl.tile_y_bases, _pathfinder, _board_ctrl.tile_bodies) var dmg_played: bool = _animator.play_damage_animations(state) - # Immediate UI updates (hand / HUD don't wait for animations). _hand_mgr.rebuild_hand(Game.get_hand(), _is_spectating) _hud_ctrl.update_hud(state) - # Enter Placement mode whenever we haven't placed yet (simultaneous phase). var phase: String = str(state.get("phase", "")) if phase == "Placement" and not _is_spectating: var my_arch: Dictionary = Game.get_my_player().get("archSpirit", {}) @@ -507,16 +421,13 @@ func _on_state_updated(state: Dictionary) -> void: _clear_highlights() _highlight_tiles(_tile_resolver.valid_placement_tiles(), "movement") - # Snapshot state for next frame's diff. _animator.update_prev_state(state) - # Schedule delayed board rebuild to let animations finish. var delay: float = move_dur if dmg_played: delay = maxf(delay, POST_ANIM_SECS) _animator.schedule_rebuild(state, delay) - # Selection preservation across server pushes. var cur_mode: SelectionController.Mode = _sel_ctrl.mode match cur_mode: SelectionController.Mode.NONE, SelectionController.Mode.PLACEMENT: @@ -537,7 +448,6 @@ func _on_state_updated(state: Dictionary) -> void: _: _sel_ctrl.set_mode(SelectionController.Mode.NONE) - # Auto-draw. if state.get("phase", "") == "Draw" and Game.is_my_turn(): await get_tree().create_timer(0.3).timeout Game.send_draw() @@ -545,18 +455,13 @@ func _on_state_updated(state: Dictionary) -> void: func _on_rebuild_scheduled(state: Dictionary, delay: float) -> void: if delay <= 0.0: - # If a delayed rebuild is already in flight (protecting a move tween), - # just update its state — do NOT call rebuild_units now, which would - # kill the in-progress tween and freeze the unit mid-path. if _rebuild_pending: _pending_rebuild_state = state return _mesh_builder.rebuild_units(state) return - # Delayed rebuild: protect any concurrent move tween from premature kills. _pending_rebuild_state = state if _rebuild_pending: - # A timer is already running; updating the state is enough. return _rebuild_pending = true var t: SceneTreeTimer = get_tree().create_timer(delay + 0.1) @@ -564,7 +469,7 @@ func _on_rebuild_scheduled(state: Dictionary, delay: float) -> void: _rebuild_pending = false _mesh_builder.rebuild_units(_pending_rebuild_state)) -# ── Camera orientation helper ───────────────────────────────────────────────── +# ── Camera orientation ──────────────────────────────────────────────────────── func _orient_camera_to_player(state: Dictionary) -> void: var bw: float = float(Game.board_width()) @@ -639,7 +544,6 @@ func _on_deselect_pending() -> void: func _on_hand_card_clicked(card_data: Dictionary) -> void: var iid: String = str(card_data.get("instanceId", "")) - # Dedup: same card, same frame. var cf: int = Engine.get_process_frames() if cf == _last_click_frame and _last_click_iid == iid: return @@ -652,7 +556,6 @@ func _on_hand_card_clicked(card_data: Dictionary) -> void: if not Game.is_my_turn() and card.get("cardType", "") != "Instinct": return - # ArchSpirit → Ascend / Transition. if card.get("cardType", "") == "ArchSpirit": var tier: int = int(card.get("tier", 0)) var cur_tier: int = _sel_ctrl._get_my_arch_tier() @@ -662,7 +565,6 @@ func _on_hand_card_clicked(card_data: Dictionary) -> void: _sel_ctrl._confirm_transition(card) return - # Terramorpha → multi-tile flow. if card.get("cardType", "") == "Terramorpha": if Game.get_my_player().get("currentSp", 0) < card.get("spCost", 0): return @@ -674,12 +576,10 @@ func _on_hand_card_clicked(card_data: Dictionary) -> void: _highlight_tiles(_tile_resolver.valid_play_tiles(card, _board_ctrl.tile_bodies), "movement") return - # Ruin → preflight + confirm. if card.get("cardType", "") == "Ruin": _sel_ctrl.channel_ruin(card) return - # Repentance / Instinct — may have an active ability. if card.get("cardType", "") in ["Repentance", "Instinct"]: var ab_mode: SelectionController.Mode = _sel_ctrl.mode if (ab_mode == SelectionController.Mode.ABILITY_TARGET and _abt.ability_card_id == iid) \ @@ -691,7 +591,6 @@ func _on_hand_card_clicked(card_data: Dictionary) -> void: or (ab_mode == SelectionController.Mode.ABILITY_TARGET and not _abt.ability_card_id.is_empty()): _sel_ctrl.set_mode(SelectionController.Mode.NONE) - # Parse abilitiesJson for the first Active ability. var abs_v: Variant = card.get("abilitiesJson") var abs_raw: String = "" if abs_v == null else str(abs_v) if not abs_raw.is_empty(): @@ -724,17 +623,14 @@ func _on_hand_card_clicked(card_data: Dictionary) -> void: _clear_highlights() _abt.start_ability_targeting() return - # No active ability — channel immediately. Game.send_play_card(iid, 0, 0) return - # Deselect if same card clicked again. if _sel_ctrl.mode == SelectionController.Mode.CARD_FROM_HAND \ and _sel_ctrl.sel_card_id == iid: _sel_ctrl.set_mode(SelectionController.Mode.NONE) return - # Standard card — enter CARD_FROM_HAND mode with tile highlights. _sel_ctrl.sel_card_id = iid _sel_ctrl.set_mode(SelectionController.Mode.CARD_FROM_HAND) _clear_highlights() @@ -748,7 +644,7 @@ func _refresh_hand_selection() -> void: var sel_card_id: String = _sel_ctrl.sel_card_id var ability_card_id: String = _abt.ability_card_id var needs_layout: bool = false - for widget: Node in _hand_cards.get_children(): + for widget: Node in _hand_mgr.hand_cards.get_children(): if not widget.has_meta("card_instance_id"): continue var iid: String = str(widget.get_meta("card_instance_id")) @@ -766,7 +662,7 @@ func _refresh_hand_selection() -> void: if needs_layout: _hand_mgr.queue_hand_layout() -# ── Highlight system (board overlay quads) ──────────────────────────────────── +# ── Highlight system ────────────────────────────────────────────────────────── func _clear_highlights() -> void: var children: Array = _hi_root.get_children() @@ -1016,16 +912,8 @@ func _setup_spectator_ui() -> void: lbl.set_anchors_preset(Control.PRESET_TOP_WIDE) lbl.position = Vector2(0, 8) _hud.add_child(lbl) - _hand_area.visible = false - _sp_st_panel.visible = false - _deck_discard_panel.visible = false - _draw_btn.visible = false - _end_turn_btn.visible = false - _spectator_panel.visible = true - _spectator_leave_btn.visible = true - _spectator_leave_btn.pressed.connect(func() -> void: - Game.stop_spectating() - get_tree().change_scene_to_file("res://scenes/free_play/FreePlayScreen.tscn")) + _hand_mgr.visible = false + _hud_ctrl.enter_spectator_mode() func _pending_popup_cards_clear() -> void: diff --git a/Server/src/SOR.Game/GameEngine.cs b/Server/src/SOR.Game/GameEngine.cs index 42af295..d687a15 100644 --- a/Server/src/SOR.Game/GameEngine.cs +++ b/Server/src/SOR.Game/GameEngine.cs @@ -735,8 +735,9 @@ public static class GameEngine Console.WriteLine($"[GameEngine.Attack] attacker {UnitSummary(attacker)} locations={Locations(attacker.InstanceId)}"); Console.WriteLine($"[GameEngine.Attack] target {UnitSummary(target)} owner={opponentId} locations={Locations(target.InstanceId)}"); - if (attacker.IsExhausted) throw new GameException("CARD_EXHAUSTED"); - if (!attacker.CanAttack) throw new GameException("CARD_CANNOT_ATTACK"); + if (attacker.IsExhausted) throw new GameException("CARD_EXHAUSTED"); + if (!attacker.CanAttack) throw new GameException("CARD_CANNOT_ATTACK"); + if (attacker.CurrentHealth <= 0) throw new GameException("UNIT_IS_DEAD"); if (!target.CanBeAttacked) throw new GameException("TARGET_CANNOT_BE_ATTACKED"); @@ -828,10 +829,14 @@ public static class GameEngine bool gameOver = false; var activePlayer = state.Players[actorId]; - Console.WriteLine($"[GameEngine.Attack] death check attacker hp={attacker.CurrentHealth} leader={attacker.IsLeader} locations={Locations(attacker.InstanceId)}"); + // Use ArchSpirit InstanceId as fallback for leader detection in case IsLeader flag is stale. + bool attackerIsLeader = attacker.IsLeader || activePlayer.ArchSpirit?.InstanceId == attacker.InstanceId; + bool targetIsLeader = target.IsLeader || opponentPlayer.ArchSpirit?.InstanceId == target.InstanceId; + + Console.WriteLine($"[GameEngine.Attack] death check attacker hp={attacker.CurrentHealth} leader={attacker.IsLeader} archLeader={attackerIsLeader} locations={Locations(attacker.InstanceId)}"); if (attacker.CurrentHealth <= 0) { - if (attacker.IsLeader) + if (attackerIsLeader) { Console.WriteLine($"[GameEngine.Attack] attacker leader death -> eliminate actor={actorId}"); EliminatePlayer(state, activePlayer, out gameOver); @@ -863,10 +868,10 @@ public static class GameEngine } } - Console.WriteLine($"[GameEngine.Attack] death check target hp={target.CurrentHealth} leader={target.IsLeader} locations={Locations(target.InstanceId)}"); + Console.WriteLine($"[GameEngine.Attack] death check target hp={target.CurrentHealth} leader={target.IsLeader} archLeader={targetIsLeader} locations={Locations(target.InstanceId)}"); if (target.CurrentHealth <= 0) { - if (target.IsLeader) + if (targetIsLeader) { Console.WriteLine($"[GameEngine.Attack] target leader death -> eliminate opponent={opponentId}"); EliminatePlayer(state, opponentPlayer, out gameOver);