81 lines
2.6 KiB
GDScript
81 lines
2.6 KiB
GDScript
extends PanelContainer
|
|
|
|
signal join_pressed(dungeon_id: String)
|
|
|
|
var dungeon_id: String = ""
|
|
var join_window_end: float = 0
|
|
var is_join_window_open: bool = false
|
|
|
|
var tier_label: Label
|
|
var creator_label: Label
|
|
var players_label: Label
|
|
var status_label: Label
|
|
var timer_label: Label
|
|
var join_button: Button
|
|
|
|
func _ready():
|
|
tier_label = $HBoxContainer/InfoContainer/TierLabel
|
|
creator_label = $HBoxContainer/InfoContainer/CreatorLabel
|
|
players_label = $HBoxContainer/InfoContainer/PlayersLabel
|
|
status_label = $HBoxContainer/StatusContainer/StatusLabel
|
|
timer_label = $HBoxContainer/StatusContainer/TimerLabel
|
|
join_button = $HBoxContainer/JoinButton
|
|
join_button.pressed.connect(_on_join_pressed)
|
|
|
|
func setup(data: Dictionary, is_persisted: bool):
|
|
# Defer setup to ensure nodes are ready
|
|
call_deferred("_do_setup", data, is_persisted)
|
|
|
|
func _do_setup(data: Dictionary, is_persisted: bool):
|
|
dungeon_id = data.get("id", "")
|
|
|
|
var tier = data.get("tier", 1)
|
|
var bracket = data.get("levelBracket", "1-10")
|
|
var creator = data.get("creatorName", "Unknown")
|
|
var creator_level = data.get("creatorLevel", 1)
|
|
var player_count = data.get("playerCount", 0)
|
|
var max_players = data.get("maxPlayers", 20)
|
|
is_join_window_open = data.get("isJoinWindowOpen", false)
|
|
var seconds_remaining = data.get("secondsRemaining", 0)
|
|
|
|
tier_label.text = "Tier %d [%s]" % [tier, bracket]
|
|
creator_label.text = "Created by: %s (Lv.%d)" % [creator, creator_level]
|
|
players_label.text = "Players: %d/%d" % [player_count, max_players]
|
|
|
|
if is_persisted:
|
|
status_label.text = "Saved"
|
|
status_label.modulate = Color.GRAY
|
|
timer_label.text = "Empty - will resume"
|
|
join_button.text = "Resume"
|
|
elif is_join_window_open:
|
|
status_label.text = "Open"
|
|
status_label.modulate = Color.GREEN
|
|
join_window_end = Time.get_ticks_msec() / 1000.0 + seconds_remaining
|
|
timer_label.text = "%ds remaining" % seconds_remaining
|
|
join_button.text = "Join"
|
|
else:
|
|
status_label.text = "In Progress"
|
|
status_label.modulate = Color.YELLOW
|
|
timer_label.text = "Join window closed"
|
|
join_button.text = "Join"
|
|
|
|
# Disable join if full
|
|
if player_count >= max_players:
|
|
join_button.disabled = true
|
|
join_button.text = "Full"
|
|
|
|
func _process(_delta: float):
|
|
if is_join_window_open and timer_label:
|
|
var now = Time.get_ticks_msec() / 1000.0
|
|
var remaining = max(0, join_window_end - now)
|
|
if remaining > 0:
|
|
timer_label.text = "%ds remaining" % int(remaining)
|
|
else:
|
|
is_join_window_open = false
|
|
status_label.text = "In Progress"
|
|
status_label.modulate = Color.YELLOW
|
|
timer_label.text = "Join window closed"
|
|
|
|
func _on_join_pressed():
|
|
join_pressed.emit(dungeon_id)
|