Build Bazaar: 4 tabs, sort/filter, art images, USD disabled
Actually: Add ranked gameplay UI — matchmaking + 3D game screen
- Game.gd autoload: stores session/state, handles match_found and
game.state_update.push, exposes helpers and all server action methods
- MatchmakingScreen: fetches decks, joins ranked queue, shows elapsed
timer, cancels cleanly; navigates to GameScreen on match_found push
- GameScreen (3D + 2D overlay):
- 3D board: 1×1×0.5 BoxMesh tiles colored by affinity (24 affinities),
StaticBody3D per tile for raycast picking
- Unit placeholders: sphere=Spirit, cylinder=ArchSpirit, box=Ruin,
team-colored (blue/red), exhaust dimming
- Camera: orbit (left-drag / one-finger), zoom (scroll / pinch),
pan (middle-drag / two-finger); isometric default ~40° pitch
- Hand: scrollable row of GameCardWidgets; hover → scale+rise anim;
click → select; selected card highlights valid play tiles green
- Unit selection: click unit → movement range (green), attack
range (red); click target tile → move; click enemy → attack
- Placement phase: valid ArchSpirit tiles highlighted automatically
- Draw phase: auto-draws after 0.3s delay
- Context popup: hold 0.5s on tile → tile coord/affinity + unit
stats + ability names
- Discard viewer: own + opponent, scrollable card list
- Game-over overlay: result, rank delta, return to main menu
- All game actions wired: play, move, attack, sacrifice, end turn,
draw, concede, ascend, transition, activate ability
- main_screen.gd: MatchBtn → MatchmakingScreen
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -0,0 +1,244 @@
|
||||
extends Node
|
||||
## Game autoload — manages all ranked-game state and server communication.
|
||||
##
|
||||
## Receives matchmaking and game server pushes, stores game state,
|
||||
## and provides helpers for the GameScreen and MatchmakingScreen.
|
||||
##
|
||||
## Usage:
|
||||
## Game.session_id ← current session GUID string
|
||||
## Game.state ← latest GameStateDto dict
|
||||
## Game.get_my_player() ← own PlayerStateDto dict
|
||||
## Game.is_my_turn() ← bool
|
||||
|
||||
# ── Signals ───────────────────────────────────────────────────────────────────
|
||||
|
||||
## Emitted when matchmaking finds a game. Navigate to GameScreen.
|
||||
signal match_found(session_id: String, opponent_name: String, opponent_rank: int)
|
||||
|
||||
## Emitted whenever the authoritative game state changes.
|
||||
signal state_updated(state: Dictionary)
|
||||
|
||||
## Emitted when the game ends.
|
||||
signal game_over(winner_account_id: String, win_condition: String,
|
||||
winner_rank_delta: int, loser_rank_delta: int)
|
||||
|
||||
# ── State ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
var session_id : String = ""
|
||||
var state : Dictionary = {}
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
Network.message_received.connect(_on_server_push)
|
||||
Auth.session_expired.connect(_clear_state)
|
||||
|
||||
|
||||
func _clear_state() -> void:
|
||||
session_id = ""
|
||||
state = {}
|
||||
|
||||
# ── Public helpers ────────────────────────────────────────────────────────────
|
||||
|
||||
## Returns the PlayerStateDto dict for the local player, or {}.
|
||||
func get_my_player() -> Dictionary:
|
||||
return _player_by_id(Auth.user_id)
|
||||
|
||||
|
||||
## Returns the PlayerStateDto dict for the opponent, or {}.
|
||||
func get_opponent() -> Dictionary:
|
||||
for p: Dictionary in state.get("players", []):
|
||||
if str(p.get("accountId", "")) != Auth.user_id:
|
||||
return p
|
||||
return {}
|
||||
|
||||
|
||||
## Returns true when it is the local player's turn.
|
||||
func is_my_turn() -> bool:
|
||||
return str(state.get("activePlayerAccountId", "")) == Auth.user_id
|
||||
|
||||
|
||||
## Returns the current phase string (Placement | Draw | Main | End | GameOver).
|
||||
func get_phase() -> String:
|
||||
return state.get("phase", "")
|
||||
|
||||
|
||||
## Returns the BoardDto dict, or {}.
|
||||
func get_board() -> Dictionary:
|
||||
return state.get("board", {})
|
||||
|
||||
|
||||
## Returns Array of TileDto dicts.
|
||||
func get_tiles() -> Array:
|
||||
return get_board().get("tiles", [])
|
||||
|
||||
|
||||
## Returns the local player's hand (Array of CardInstanceDto dicts).
|
||||
func get_hand() -> Array:
|
||||
return get_my_player().get("hand", [])
|
||||
|
||||
|
||||
## Returns the local player's field (Array of CardInstanceDto dicts).
|
||||
func get_field() -> Array:
|
||||
return get_my_player().get("field", [])
|
||||
|
||||
|
||||
## Returns the opponent's field (Array of CardInstanceDto dicts).
|
||||
func get_opponent_field() -> Array:
|
||||
return get_opponent().get("field", [])
|
||||
|
||||
|
||||
## Returns a TileDto dict by coord, or {}.
|
||||
func get_tile(x: int, y: int) -> Dictionary:
|
||||
for t: Dictionary in get_tiles():
|
||||
var c: Dictionary = t.get("coord", {})
|
||||
if c.get("x", -1) == x and c.get("y", -1) == y:
|
||||
return t
|
||||
return {}
|
||||
|
||||
|
||||
## Returns a CardInstanceDto from any player's field by instanceId, or {}.
|
||||
func get_unit_by_id(instance_id: String) -> Dictionary:
|
||||
for p: Dictionary in state.get("players", []):
|
||||
for u: Dictionary in p.get("field", []):
|
||||
if u.get("instanceId", "") == instance_id:
|
||||
return u
|
||||
var arch: Dictionary = p.get("archSpirit", {})
|
||||
if arch.get("instanceId", "") == instance_id:
|
||||
return arch
|
||||
return {}
|
||||
|
||||
|
||||
## Returns the board width (default 8).
|
||||
func board_width() -> int:
|
||||
return get_board().get("width", 8)
|
||||
|
||||
|
||||
## Returns the board height (default 8).
|
||||
func board_height() -> int:
|
||||
return get_board().get("height", 8)
|
||||
|
||||
# ── Server actions ────────────────────────────────────────────────────────────
|
||||
|
||||
func send_ready() -> void:
|
||||
Network.request("game.ready",
|
||||
{ "sessionId": session_id },
|
||||
func(_t: String, p: Variant) -> void: _apply_state_from_payload(p),
|
||||
func(_c: String, _m: String) -> void: pass)
|
||||
|
||||
|
||||
func send_draw() -> void:
|
||||
_game_request("game.draw", {})
|
||||
|
||||
|
||||
func send_place_arch_spirit(x: int, y: int) -> void:
|
||||
_game_request("game.place_arch_spirit",
|
||||
{ "position": { "x": x, "y": y } })
|
||||
|
||||
|
||||
func send_play_card(card_instance_id: String, target_x: int, target_y: int) -> void:
|
||||
_game_request("game.play_card", {
|
||||
"cardInstanceId": card_instance_id,
|
||||
"targetTile": { "x": target_x, "y": target_y }
|
||||
})
|
||||
|
||||
|
||||
func send_play_card_multi(card_instance_id: String, targets: Array) -> void:
|
||||
_game_request("game.play_card", {
|
||||
"cardInstanceId": card_instance_id,
|
||||
"targetTiles": targets
|
||||
})
|
||||
|
||||
|
||||
func send_move_unit(unit_instance_id: String, target_x: int, target_y: int) -> void:
|
||||
_game_request("game.move_unit", {
|
||||
"unitInstanceId": unit_instance_id,
|
||||
"targetPosition": { "x": target_x, "y": target_y }
|
||||
})
|
||||
|
||||
|
||||
func send_attack(attacker_id: String, target_id: String) -> void:
|
||||
_game_request("game.attack", {
|
||||
"attackerInstanceId": attacker_id,
|
||||
"targetInstanceId": target_id
|
||||
})
|
||||
|
||||
|
||||
func send_sacrifice(unit_id: String) -> void:
|
||||
_game_request("game.sacrifice", { "unitInstanceId": unit_id })
|
||||
|
||||
|
||||
func send_end_turn() -> void:
|
||||
_game_request("game.end_turn", {})
|
||||
|
||||
|
||||
func send_concede() -> void:
|
||||
_game_request("game.concede", {})
|
||||
|
||||
|
||||
func send_ascend(incoming_card_instance_id: String) -> void:
|
||||
_game_request("game.ascend",
|
||||
{ "incomingCardInstanceId": incoming_card_instance_id })
|
||||
|
||||
|
||||
func send_transition(incoming_card_instance_id: String) -> void:
|
||||
_game_request("game.transition",
|
||||
{ "incomingCardInstanceId": incoming_card_instance_id })
|
||||
|
||||
|
||||
func send_activate_ability(source_id: String, ability_index: int) -> void:
|
||||
_game_request("game.activate_ability", {
|
||||
"sourceInstanceId": source_id,
|
||||
"abilityIndex": ability_index
|
||||
})
|
||||
|
||||
# ── Private ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func _game_request(msg_type: String, extra: Dictionary) -> void:
|
||||
var payload := { "sessionId": session_id }
|
||||
payload.merge(extra)
|
||||
Network.request(msg_type, payload,
|
||||
func(_t: String, p: Variant) -> void: _apply_state_from_payload(p),
|
||||
func(_c: String, _m: String) -> void: pass)
|
||||
|
||||
|
||||
func _apply_state_from_payload(p: Variant) -> void:
|
||||
var d := p as Dictionary
|
||||
var s := d.get("state", {}) as Dictionary
|
||||
if s.is_empty():
|
||||
return
|
||||
state = s
|
||||
state_updated.emit(state)
|
||||
|
||||
|
||||
func _player_by_id(account_id: String) -> Dictionary:
|
||||
for p: Dictionary in state.get("players", []):
|
||||
if str(p.get("accountId", "")) == account_id:
|
||||
return p
|
||||
return {}
|
||||
|
||||
|
||||
func _on_server_push(type: String, payload: Variant) -> void:
|
||||
match type:
|
||||
"matchmaking.match_found":
|
||||
var d := payload as Dictionary
|
||||
var sid : String = str(d.get("gameSessionId", ""))
|
||||
var oname : String = str(d.get("opponentDisplayName", "Opponent"))
|
||||
var orank : int = int(d.get("opponentRankScore", 0))
|
||||
session_id = sid
|
||||
match_found.emit(sid, oname, orank)
|
||||
|
||||
"game.state_update.push":
|
||||
var d := payload as Dictionary
|
||||
var s := d.get("state", {}) as Dictionary
|
||||
if not s.is_empty():
|
||||
state = s
|
||||
state_updated.emit(state)
|
||||
|
||||
"game.over.push":
|
||||
var d := payload as Dictionary
|
||||
var winner : String = str(d.get("winnerAccountId", ""))
|
||||
var wc : String = str(d.get("winCondition", ""))
|
||||
var wd : int = int(d.get("winnerRankDelta", 0))
|
||||
var ld : int = int(d.get("loserRankDelta", 0))
|
||||
game_over.emit(winner, wc, wd, ld)
|
||||
@@ -23,6 +23,7 @@ Auth="*res://autoloads/Auth.gd"
|
||||
CollectionCache="*res://autoloads/CollectionCache.gd"
|
||||
Chat="*res://autoloads/Chat.gd"
|
||||
Settings="*res://autoloads/Settings.gd"
|
||||
Game="*res://autoloads/Game.gd"
|
||||
|
||||
[display]
|
||||
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://game_screen"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/game/game_screen.gd" id="1_gscr"]
|
||||
|
||||
[node name="GameScreen" type="Node3D"]
|
||||
script = ExtResource("1_gscr")
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(0.707107, -0.5, 0.5, 0, 0.707107, 0.707107, -0.707107, -0.5, 0.5, 0, 8, 0)
|
||||
light_energy = 1.2
|
||||
shadow_enabled = true
|
||||
|
||||
[node name="CameraRig" type="Node3D" parent="."]
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="CameraRig"]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.766044, 0.642788, 0, -0.642788, 0.766044, 0, 10, 9)
|
||||
|
||||
[node name="BoardRoot" type="Node3D" parent="."]
|
||||
|
||||
[node name="TilesRoot" type="Node3D" parent="BoardRoot"]
|
||||
|
||||
[node name="UnitsRoot" type="Node3D" parent="BoardRoot"]
|
||||
|
||||
[node name="HighlightsRoot" type="Node3D" parent="BoardRoot"]
|
||||
|
||||
[node name="HUD" type="CanvasLayer" parent="."]
|
||||
layer = 10
|
||||
|
||||
[node name="TopBar" type="HBoxContainer" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.0
|
||||
anchor_top = 0.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 0.0
|
||||
offset_bottom = 48.0
|
||||
theme_override_constants/separation = 0
|
||||
|
||||
[node name="PhaseLabel" type="Label" parent="HUD/TopBar"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(140, 48)
|
||||
theme_override_font_sizes/font_size = 13
|
||||
text = "Phase: —"
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="TurnLabel" type="Label" parent="HUD/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="OpponentPanel" type="HBoxContainer" parent="HUD/TopBar"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(240, 48)
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="OppNameLabel" type="Label" parent="HUD/TopBar/OpponentPanel"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "Opponent"
|
||||
vertical_alignment = 1
|
||||
modulate = Color(1, 0.5, 0.5, 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="HandArea" type="PanelContainer" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.75
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -180.0
|
||||
offset_right = 0.0
|
||||
|
||||
[node name="HandScroll" type="ScrollContainer" parent="HUD/HandArea"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
vertical_scroll_mode = 0
|
||||
|
||||
[node name="HandCards" type="HBoxContainer" parent="HUD/HandArea/HandScroll"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
theme_override_constants/separation = -12
|
||||
|
||||
[node name="RightPanel" type="PanelContainer" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.75
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -180.0
|
||||
|
||||
[node name="RightMargin" type="MarginContainer" parent="HUD/RightPanel"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 10
|
||||
theme_override_constants/margin_right = 10
|
||||
theme_override_constants/margin_top = 8
|
||||
theme_override_constants/margin_bottom = 8
|
||||
|
||||
[node name="RightVBox" type="VBoxContainer" parent="HUD/RightPanel/RightMargin"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 6
|
||||
|
||||
[node name="SpLabel" type="Label" parent="HUD/RightPanel/RightMargin/RightVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "SP: 0"
|
||||
|
||||
[node name="StLabel" type="Label" parent="HUD/RightPanel/RightMargin/RightVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "ST: 0"
|
||||
|
||||
[node name="DeckLabel" type="Label" parent="HUD/RightPanel/RightMargin/RightVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "Deck: 0"
|
||||
|
||||
[node name="DiscardBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "View Discard"
|
||||
|
||||
[node name="Spacer" type="Control" parent="HUD/RightPanel/RightMargin/RightVBox"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="DrawBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 36)
|
||||
theme_override_font_sizes/font_size = 13
|
||||
text = "Draw Card"
|
||||
|
||||
[node name="EndTurnBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 36)
|
||||
theme_override_font_sizes/font_size = 13
|
||||
text = "End Turn"
|
||||
|
||||
[node name="ConcedeBtn" type="Button" parent="HUD/RightPanel/RightMargin/RightVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "Concede"
|
||||
|
||||
[node name="ContextPopup" type="PanelContainer" parent="HUD"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -160.0
|
||||
offset_top = -120.0
|
||||
offset_right = 160.0
|
||||
offset_bottom = 120.0
|
||||
visible = false
|
||||
|
||||
[node name="ContextMargin" type="MarginContainer" parent="HUD/ContextPopup"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 12
|
||||
theme_override_constants/margin_right = 12
|
||||
theme_override_constants/margin_top = 8
|
||||
theme_override_constants/margin_bottom = 8
|
||||
|
||||
[node name="ContextVBox" type="VBoxContainer" parent="HUD/ContextPopup/ContextMargin"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 6
|
||||
|
||||
[node name="ContextTileLabel" type="Label" parent="HUD/ContextPopup/ContextMargin/ContextVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 13
|
||||
text = "Tile (0,0) — Void"
|
||||
|
||||
[node name="ContextUnitLabel" type="Label" parent="HUD/ContextPopup/ContextMargin/ContextVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = ""
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="ContextAbilitiesLabel" type="Label" parent="HUD/ContextPopup/ContextMargin/ContextVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 11
|
||||
text = ""
|
||||
autowrap_mode = 3
|
||||
modulate = Color(0.7, 0.7, 0.85, 1)
|
||||
|
||||
[node name="ContextClose" type="Button" parent="HUD/ContextPopup/ContextMargin/ContextVBox"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "Close"
|
||||
|
||||
[node name="DiscardViewer" type="PanelContainer" parent="HUD"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchor_left = 0.1
|
||||
anchor_top = 0.05
|
||||
anchor_right = 0.9
|
||||
anchor_bottom = 0.95
|
||||
visible = false
|
||||
|
||||
[node name="DVMargin" type="MarginContainer" parent="HUD/DiscardViewer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 16
|
||||
theme_override_constants/margin_right = 16
|
||||
theme_override_constants/margin_top = 12
|
||||
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
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 36)
|
||||
theme_override_font_sizes/font_size = 13
|
||||
text = "Close"
|
||||
|
||||
[node name="GameOverOverlay" type="PanelContainer" parent="HUD"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
anchor_left = 0.25
|
||||
anchor_top = 0.25
|
||||
anchor_right = 0.75
|
||||
anchor_bottom = 0.75
|
||||
visible = false
|
||||
|
||||
[node name="GOMargin" type="MarginContainer" parent="HUD/GameOverOverlay"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 24
|
||||
theme_override_constants/margin_right = 24
|
||||
theme_override_constants/margin_top = 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
|
||||
text = ""
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="GOMainMenuBtn" type="Button" parent="HUD/GameOverOverlay/GOMargin/GOVBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 44)
|
||||
theme_override_font_sizes/font_size = 15
|
||||
text = "Return to Main Menu"
|
||||
|
||||
[node name="HoldTimer" type="Timer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
wait_time = 0.5
|
||||
one_shot = true
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@ extends Control
|
||||
@onready var welcome_label : Label = %WelcomeLabel
|
||||
@onready var status_label : Label = %StatusLabel
|
||||
@onready var logout_btn : Button = %LogoutBtn
|
||||
@onready var match_btn : Button = %MatchBtn
|
||||
@onready var collection_btn : Button = %CollectionBtn
|
||||
@onready var bazaar_btn : Button = %BazaarBtn
|
||||
@onready var leaderboard_btn : Button = %LeaderboardBtn
|
||||
@@ -27,6 +28,9 @@ func _ready() -> void:
|
||||
|
||||
logout_btn.pressed.connect(_on_logout_pressed)
|
||||
|
||||
match_btn.pressed.connect(func():
|
||||
get_tree().change_scene_to_file("res://scenes/matchmaking/MatchmakingScreen.tscn"))
|
||||
|
||||
collection_btn.pressed.connect(func():
|
||||
get_tree().change_scene_to_file("res://scenes/collection/CollectionScreen.tscn"))
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://matchmaking_screen"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/matchmaking/matchmaking_screen.gd" id="1_mmscr"]
|
||||
|
||||
[node name="MatchmakingScreen" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource("1_mmscr")
|
||||
|
||||
[node name="BG" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
color = Color(0.08, 0.08, 0.12, 1)
|
||||
|
||||
[node name="Center" type="CenterContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="Center"]
|
||||
custom_minimum_size = Vector2(480, 0)
|
||||
theme_override_constants/separation = 24
|
||||
|
||||
[node name="Title" type="Label" parent="Center/VBox"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 28
|
||||
text = "Ranked Match"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="StatusLabel" type="Label" parent="Center/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 18
|
||||
text = "Loading…"
|
||||
horizontal_alignment = 1
|
||||
modulate = Color(0.8, 0.8, 0.85, 1)
|
||||
|
||||
[node name="SubLabel" type="Label" parent="Center/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 13
|
||||
text = ""
|
||||
horizontal_alignment = 1
|
||||
modulate = Color(0.55, 0.55, 0.6, 1)
|
||||
|
||||
[node name="DeckPanel" type="VBoxContainer" parent="Center/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 8
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="Center/VBox/DeckPanel"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 240)
|
||||
horizontal_scroll_mode = 0
|
||||
|
||||
[node name="DeckList" type="VBoxContainer" parent="Center/VBox/DeckPanel/ScrollContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/separation = 4
|
||||
|
||||
[node name="SearchPanel" type="VBoxContainer" parent="Center/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 12
|
||||
visible = false
|
||||
|
||||
[node name="Spinner" type="Label" parent="Center/VBox/SearchPanel"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 36
|
||||
text = "⏳"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="ElapsedLabel" type="Label" parent="Center/VBox/SearchPanel"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 14
|
||||
text = "Searching… 00:00"
|
||||
horizontal_alignment = 1
|
||||
modulate = Color(0.6, 0.6, 0.7, 1)
|
||||
|
||||
[node name="CancelBtn" type="Button" parent="Center/VBox"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 44)
|
||||
theme_override_font_sizes/font_size = 15
|
||||
text = "Cancel"
|
||||
@@ -0,0 +1,130 @@
|
||||
extends Control
|
||||
## Matchmaking screen — join ranked queue, wait for opponent, cancel.
|
||||
##
|
||||
## Flow:
|
||||
## 1. _ready: fetch player's decks via collection.get_decks
|
||||
## 2. If multiple decks, show deck picker; if one, auto-select
|
||||
## 3. On deck selected: call matchmaking.join → show Searching state
|
||||
## 4. On Game.match_found: navigate to GameScreen
|
||||
## 5. Cancel: matchmaking.leave → back to MainScreen
|
||||
|
||||
@onready var status_label : Label = %StatusLabel
|
||||
@onready var sub_label : Label = %SubLabel
|
||||
@onready var cancel_btn : Button = %CancelBtn
|
||||
@onready var deck_panel : Control = %DeckPanel
|
||||
@onready var deck_list : VBoxContainer = %DeckList
|
||||
@onready var search_panel : Control = %SearchPanel
|
||||
@onready var elapsed_label : Label = %ElapsedLabel
|
||||
|
||||
var _selected_deck_id : String = ""
|
||||
var _search_timer : float = 0.0
|
||||
var _searching : bool = false
|
||||
|
||||
# ── Lifecycle ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _ready() -> void:
|
||||
cancel_btn.pressed.connect(_on_cancel)
|
||||
Game.match_found.connect(_on_match_found)
|
||||
_show_deck_panel()
|
||||
_fetch_decks()
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if Game.match_found.is_connected(_on_match_found):
|
||||
Game.match_found.disconnect(_on_match_found)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _searching:
|
||||
_search_timer += delta
|
||||
var secs := int(_search_timer)
|
||||
elapsed_label.text = "Searching… %02d:%02d" % [secs / 60, secs % 60]
|
||||
|
||||
# ── Deck fetch ────────────────────────────────────────────────────────────────
|
||||
|
||||
func _fetch_decks() -> void:
|
||||
status_label.text = "Loading decks…"
|
||||
Network.request("collection.get_decks", {},
|
||||
_on_decks_response,
|
||||
func(_c: String, _m: String) -> void:
|
||||
status_label.text = "Could not load decks."
|
||||
sub_label.text = "Check your connection and try again."
|
||||
)
|
||||
|
||||
|
||||
func _on_decks_response(_type: String, payload: Variant) -> void:
|
||||
var decks : Array = (payload as Dictionary).get("decks", [])
|
||||
|
||||
if decks.is_empty():
|
||||
status_label.text = "No decks found."
|
||||
sub_label.text = "Build a deck in the Collection first."
|
||||
cancel_btn.text = "Back"
|
||||
return
|
||||
|
||||
for c in deck_list.get_children():
|
||||
c.queue_free()
|
||||
|
||||
if decks.size() == 1:
|
||||
_selected_deck_id = str(decks[0].get("id", ""))
|
||||
_join_queue()
|
||||
return
|
||||
|
||||
# Show deck picker.
|
||||
status_label.text = "Choose a deck"
|
||||
sub_label.text = ""
|
||||
for deck: Dictionary in decks:
|
||||
var btn := Button.new()
|
||||
btn.text = "%s (%d cards)" % [deck.get("name", "Unnamed"), int(deck.get("cardCount", 0))]
|
||||
btn.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
btn.custom_minimum_size = Vector2(0, 44)
|
||||
btn.add_theme_font_size_override("font_size", 14)
|
||||
var did := str(deck.get("id", ""))
|
||||
btn.pressed.connect(func() -> void:
|
||||
_selected_deck_id = did
|
||||
_join_queue())
|
||||
deck_list.add_child(btn)
|
||||
|
||||
# ── Queue actions ─────────────────────────────────────────────────────────────
|
||||
|
||||
func _join_queue() -> void:
|
||||
_show_search_panel()
|
||||
status_label.text = "Finding a match…"
|
||||
sub_label.text = ""
|
||||
_search_timer = 0.0
|
||||
_searching = true
|
||||
|
||||
Network.request("matchmaking.join",
|
||||
{ "deckId": _selected_deck_id },
|
||||
func(_t: String, _p: Variant) -> void: pass,
|
||||
func(_c: String, _m: String) -> void:
|
||||
_searching = false
|
||||
status_label.text = "Failed to join queue."
|
||||
)
|
||||
|
||||
|
||||
func _on_cancel() -> void:
|
||||
if _searching:
|
||||
Network.request("matchmaking.leave", {},
|
||||
func(_t: String, _p: Variant) -> void: pass,
|
||||
func(_c: String, _m: String) -> void: pass)
|
||||
_searching = false
|
||||
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")
|
||||
|
||||
|
||||
func _on_match_found(_sid: String, opponent_name: String, _rank: int) -> void:
|
||||
_searching = false
|
||||
status_label.text = "Match found!"
|
||||
sub_label.text = "Opponent: %s" % opponent_name
|
||||
await get_tree().create_timer(0.8).timeout
|
||||
get_tree().change_scene_to_file("res://scenes/game/GameScreen.tscn")
|
||||
|
||||
# ── Panel helpers ─────────────────────────────────────────────────────────────
|
||||
|
||||
func _show_deck_panel() -> void:
|
||||
deck_panel.visible = true
|
||||
search_panel.visible = false
|
||||
|
||||
|
||||
func _show_search_panel() -> void:
|
||||
deck_panel.visible = false
|
||||
search_panel.visible = true
|
||||
Reference in New Issue
Block a user