Convert all screens that built UI nodes in GDScript into proper .tscn
scene files. Each component gets its own scene; parent screens use
preload + instantiate; data flows through setup() methods; actions use
signals. Eliminates ~1000 lines of boilerplate node-creation code.
Phase 1 — Simple row components (6 new scenes):
LeaderboardRow, NotificationRow, StarterDeckCard, DeckPickerButton,
StatRow, AbilityRow
Modifies: leaderboard_screen, account_screen, starter_deck_screen,
matchmaking_screen, card_detail_popup (GridContainer→VBox)
Phase 2 — Lobby browser rows (2 new scenes):
LobbyBrowserRow (signal join_requested), ActiveGameRow (signal spectate_requested)
Modifies: free_play_screen
Phase 3 — RulesEditorDialog (1 new scene):
Replaces 150+ line _open_rules_editor() in lobby_room_screen with
4-line instantiate pattern; signal confirmed(overrides)
Phase 4 — DeckEditorPanel.tscn:
Moves split-pane deck editor into scene file; removes _setup_ui(),
_make_left_pane(), _make_right_pane(); switches to @onready refs;
DecksView.tscn updated to instance the scene
Phase 5 — ChatOverlay.tscn:
Fully populates ChatPanel with header, 7 tab buttons, 7 content panes
(FriendsPane/PresencePane/GlobalPane/LobbyPane/GamePane/PartyPane/DmsPane),
and InputBar; removes _build_panel() and all _make_*/_build_*_tab()
functions from chat_overlay.gd; replaces with @onready refs and
_ready() wiring from scene children
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>
133 lines
4.4 KiB
GDScript
133 lines
4.4 KiB
GDScript
extends Control
|
|
## Matchmaking screen — join ranked queue, wait for opponent, cancel.
|
|
|
|
const DECK_BTN = preload("res://scenes/common/components/DeckPickerButton.tscn")
|
|
##
|
|
## 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 := DECK_BTN.instantiate()
|
|
btn.setup(
|
|
str(deck.get("id", "")),
|
|
str(deck.get("name", "Unnamed")),
|
|
int(deck.get("cardCount", 0))
|
|
)
|
|
btn.picked.connect(func(id: String) -> void:
|
|
_selected_deck_id = id
|
|
_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
|