Files
sor/Client/origin-client/scenes/leaderboard/leaderboard_screen.gd
T
b1a51cb862 Standardize programmatic UI to scene-based instantiation (Phases 1-5)
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>
2026-03-21 12:33:15 -04:00

84 lines
2.5 KiB
GDScript

extends Control
## Leaderboard screen — top players ranked by RankScore.
const ROW = preload("res://scenes/leaderboard/components/LeaderboardRow.tscn")
@onready var back_btn : Button = %BackBtn
@onready var entry_list : VBoxContainer = %EntryList
@onready var loading_lbl : Label = %LoadingLabel
@onready var prev_btn : Button = %PrevBtn
@onready var next_btn : Button = %NextBtn
@onready var page_label : Label = %PageLabel
const PAGE_SIZE := 25
var _page : int = 0
var _total : int = 0
var _page_count : int = 1
# ── Lifecycle ─────────────────────────────────────────────────────────────────
func _ready() -> void:
back_btn.pressed.connect(_on_back)
prev_btn.pressed.connect(func(): _go_page(_page - 1))
next_btn.pressed.connect(func(): _go_page(_page + 1))
_load_page(0)
# ── Loading ───────────────────────────────────────────────────────────────────
func _load_page(page: int) -> void:
_page = page
loading_lbl.visible = true
for c in entry_list.get_children():
c.queue_free()
Network.request(
"leaderboard.get",
{ "page": _page, "pageSize": PAGE_SIZE },
func(_type: String, p: Variant): _on_leaderboard_ok(p),
func(_c: String, _m: String):
loading_lbl.text = "Failed to load."
)
func _on_leaderboard_ok(p: Variant) -> void:
loading_lbl.visible = false
var d := p as Dictionary
var entries : Array = d.get("entries", []) as Array
_total = int(d.get("totalCount", 0))
_page_count = max(1, int(ceil(_total / float(PAGE_SIZE))))
_update_pagination()
if entries.is_empty():
loading_lbl.text = "No players yet."
loading_lbl.visible = true
return
for entry in entries:
var e := entry as Dictionary
var row := ROW.instantiate()
row.setup(
int(e.get("rank", 0)),
e.get("displayName", "???"),
int(e.get("rankScore", 0)),
e.get("accountId", "") == Auth.user_id,
int(e.get("rank", 99)) <= 3
)
entry_list.add_child(row)
func _update_pagination() -> void:
page_label.text = "Page %d / %d" % [_page + 1, _page_count]
prev_btn.disabled = _page <= 0
next_btn.disabled = _page >= _page_count - 1
func _go_page(p: int) -> void:
_load_page(clamp(p, 0, _page_count - 1))
func _on_back() -> void:
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")