Legal docs draft and Client refactor
This commit is contained in:
@@ -0,0 +1,506 @@
|
||||
class_name HandManager
|
||||
extends Node
|
||||
|
||||
signal hand_card_clicked(card_data: Dictionary)
|
||||
|
||||
# ── Preloaded resources ───────────────────────────────────────────────────────
|
||||
|
||||
const _CARD_WIDGET_SCENE: PackedScene = preload("res://scenes/collection/components/CardWidget.tscn")
|
||||
const _HAND_ARROW_REGULAR: Texture2D = preload("res://ui/icons/Green_Gem_Arrow_Button_Regular.png")
|
||||
const _HAND_ARROW_HOVER: Texture2D = preload("res://ui/icons/Green_Gem_Arrow_Button_Hover.png")
|
||||
const _HAND_ARROW_PRESSED: Texture2D = preload("res://ui/icons/Green_Gem_Arrow_Button_Click.png")
|
||||
|
||||
# ── Hand state ────────────────────────────────────────────────────────────────
|
||||
|
||||
var hand_focus_index: int = 0
|
||||
var hand_scroll_time: float = 0.0
|
||||
var hand_hover_iid: String = ""
|
||||
var cached_hand_iids: Array = []
|
||||
var pending_popup_cards: Array = []
|
||||
var popup_layer: CanvasLayer = null
|
||||
var sel_card_id: String = "" # set by selection_controller to highlight
|
||||
|
||||
# ── Node refs (set from parent) ───────────────────────────────────────────────
|
||||
|
||||
var hand_cards: Control = null
|
||||
var hand_area: PanelContainer = null
|
||||
var hand_spin_left: TextureButton = null
|
||||
var hand_spin_right: TextureButton = null
|
||||
var hud: CanvasLayer = null
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
## Called by game_screen when the hand card clicked event fires.
|
||||
## Emits hand_card_clicked so game_screen can handle routing logic.
|
||||
func on_hand_card_clicked(iid: String, _panel: PanelContainer) -> void:
|
||||
var card: Dictionary = find_hand_card(iid)
|
||||
if card.is_empty():
|
||||
return
|
||||
emit_signal("hand_card_clicked", card)
|
||||
|
||||
|
||||
func rebuild_hand(hand: Array, is_spectating: bool) -> void:
|
||||
# Build new IID list.
|
||||
var new_iids: Array = []
|
||||
for card: Dictionary in hand:
|
||||
var raw_iid: Variant = card.get("instanceId")
|
||||
new_iids.append(str(raw_iid) if raw_iid != null else "")
|
||||
if new_iids == cached_hand_iids:
|
||||
refresh_hand_selection()
|
||||
return
|
||||
|
||||
cached_hand_iids = new_iids
|
||||
|
||||
# Spectators have no playable hand — just clear any stale widgets and stop.
|
||||
if is_spectating:
|
||||
apply_display_hand([])
|
||||
return
|
||||
|
||||
# Detect brand-new cards (not in previous server hand, not already queued).
|
||||
var pending_iids: Array = []
|
||||
for c: Dictionary in pending_popup_cards:
|
||||
pending_iids.append(c.get("instanceId", "") as String)
|
||||
|
||||
var brand_new: Array = []
|
||||
if Settings.draw_card_popup:
|
||||
for card: Dictionary in hand:
|
||||
var iid: String = card.get("instanceId", "")
|
||||
if iid not in cached_hand_iids and iid not in pending_iids:
|
||||
brand_new.append(card)
|
||||
|
||||
# Drop pending popups for cards that left the hand (avoid typed-array filter).
|
||||
var kept: Array = []
|
||||
for c: Dictionary in pending_popup_cards:
|
||||
if c.get("instanceId", "") in new_iids:
|
||||
kept.append(c)
|
||||
pending_popup_cards = kept
|
||||
|
||||
# Queue brand-new cards for popup; exclude them from the live hand display.
|
||||
for card: Dictionary in brand_new:
|
||||
pending_popup_cards.append(card)
|
||||
|
||||
var popup_iids: Array = []
|
||||
for c: Dictionary in pending_popup_cards:
|
||||
popup_iids.append(c.get("instanceId", "") as String)
|
||||
|
||||
# Build the display hand (everything except cards waiting in popup queue).
|
||||
var display_hand: Array = []
|
||||
for card: Dictionary in hand:
|
||||
if card.get("instanceId", "") not in popup_iids:
|
||||
display_hand.append(card)
|
||||
|
||||
apply_display_hand(display_hand)
|
||||
|
||||
# Kick off popup for the first pending card if nothing is showing yet.
|
||||
if not pending_popup_cards.is_empty() and (popup_layer == null or not popup_layer.visible):
|
||||
show_next_card_popup()
|
||||
|
||||
|
||||
func apply_display_hand(hand: Array) -> void:
|
||||
if hand.is_empty():
|
||||
for c in hand_cards.get_children():
|
||||
hand_cards.remove_child(c)
|
||||
c.queue_free()
|
||||
hand_focus_index = 0
|
||||
hand_hover_iid = ""
|
||||
sync_hand_spin_buttons()
|
||||
return
|
||||
|
||||
# Map existing widgets by IID so we can reuse them.
|
||||
var existing: Dictionary = {}
|
||||
for child in hand_cards.get_children():
|
||||
if child.has_meta("card_instance_id"):
|
||||
existing[str(child.get_meta("card_instance_id"))] = child
|
||||
|
||||
var hand_iids: Array = []
|
||||
for card: Dictionary in hand:
|
||||
hand_iids.append(card.get("instanceId", "") as String)
|
||||
|
||||
# Remove widgets for cards no longer in the display hand.
|
||||
for iid: String in existing.keys():
|
||||
if iid not in hand_iids:
|
||||
var w: Node = existing[iid]
|
||||
existing.erase(iid)
|
||||
hand_cards.remove_child(w)
|
||||
w.queue_free()
|
||||
|
||||
# Add widgets for new cards, update _fan_slot on all.
|
||||
var slot: int = 0
|
||||
for card: Dictionary in hand:
|
||||
var iid: String = card.get("instanceId", "")
|
||||
if not existing.has(iid):
|
||||
var widget: Control = make_hand_card(card)
|
||||
widget.set_meta("_fan_slot", slot)
|
||||
hand_cards.add_child(widget)
|
||||
else:
|
||||
(existing[iid] as Control).set_meta("_fan_slot", slot)
|
||||
slot += 1
|
||||
|
||||
hand_focus_index = posmod(hand_focus_index, hand.size())
|
||||
queue_hand_layout()
|
||||
sync_hand_spin_buttons()
|
||||
|
||||
|
||||
func show_next_card_popup() -> void:
|
||||
if pending_popup_cards.is_empty():
|
||||
return
|
||||
var card: Dictionary = pending_popup_cards[0]
|
||||
|
||||
# Create (or reuse) a dedicated CanvasLayer above the HUD.
|
||||
if popup_layer == null or not is_instance_valid(popup_layer):
|
||||
popup_layer = CanvasLayer.new()
|
||||
popup_layer.layer = 20
|
||||
get_parent().add_child(popup_layer)
|
||||
|
||||
# Clear any previous content.
|
||||
for c in popup_layer.get_children():
|
||||
c.queue_free()
|
||||
popup_layer.visible = true
|
||||
|
||||
# Dim background — catches clicks that miss the card.
|
||||
var bg: ColorRect = ColorRect.new()
|
||||
bg.color = Color(0.0, 0.0, 0.0, 0.65)
|
||||
bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
bg.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
popup_layer.add_child(bg)
|
||||
|
||||
# Centred column: label + card.
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.set_anchors_preset(Control.PRESET_CENTER)
|
||||
vbox.grow_horizontal = Control.GROW_DIRECTION_BOTH
|
||||
vbox.grow_vertical = Control.GROW_DIRECTION_BOTH
|
||||
vbox.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
popup_layer.add_child(vbox)
|
||||
vbox.add_theme_constant_override("separation", 16)
|
||||
|
||||
var lbl: Label = Label.new()
|
||||
lbl.text = "Card Drawn — click to add to hand"
|
||||
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
vbox.add_child(lbl)
|
||||
lbl.add_theme_font_size_override("font_size", 16)
|
||||
|
||||
var widget: PanelContainer = _CARD_WIDGET_SCENE.instantiate()
|
||||
widget.custom_minimum_size = Vector2(200, 320)
|
||||
widget.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
var def_id: String = str(card.get("cardDefinitionId", ""))
|
||||
var def: Dictionary = ContentCache.get_definition(def_id)
|
||||
if def.is_empty():
|
||||
def = card.duplicate()
|
||||
def["movementPoints"] = card.get("maxMp", def.get("movementPoints", null))
|
||||
widget.setup(card, def)
|
||||
vbox.add_child(widget)
|
||||
|
||||
# Either clicking the card or the background dismisses the popup.
|
||||
bg.gui_input.connect(func(ev: InputEvent) -> void:
|
||||
if ev is InputEventMouseButton and (ev as InputEventMouseButton).pressed:
|
||||
dismiss_card_popup())
|
||||
widget.card_pressed.connect(func(_id: String) -> void: dismiss_card_popup())
|
||||
|
||||
|
||||
func dismiss_card_popup() -> void:
|
||||
if pending_popup_cards.is_empty():
|
||||
return
|
||||
var card: Dictionary = pending_popup_cards.pop_front()
|
||||
|
||||
# Hide the overlay.
|
||||
if is_instance_valid(popup_layer):
|
||||
popup_layer.visible = false
|
||||
|
||||
# Build the updated display hand: currently shown widgets + this newly added card.
|
||||
var display_iids: Array = []
|
||||
for child in hand_cards.get_children():
|
||||
if child.has_meta("card_instance_id"):
|
||||
display_iids.append(str(child.get_meta("card_instance_id")))
|
||||
display_iids.append(card.get("instanceId", "") as String)
|
||||
|
||||
# Reconstruct display hand in server order (from cached_hand_iids).
|
||||
var display_hand: Array = []
|
||||
for iid: String in cached_hand_iids:
|
||||
if iid in display_iids:
|
||||
# Find the card dict; use the drawn card if it matches.
|
||||
if iid == card.get("instanceId", ""):
|
||||
display_hand.append(card)
|
||||
else:
|
||||
# Pull from live Game hand for existing cards.
|
||||
for hc: Dictionary in Game.get_hand():
|
||||
if hc.get("instanceId", "") == iid:
|
||||
display_hand.append(hc)
|
||||
break
|
||||
|
||||
apply_display_hand(display_hand)
|
||||
|
||||
# Show next queued popup if any.
|
||||
if not pending_popup_cards.is_empty():
|
||||
show_next_card_popup()
|
||||
|
||||
|
||||
func make_hand_card(card: Dictionary) -> Control:
|
||||
var iid: String = card.get("instanceId", "")
|
||||
var def_id: String = str(card.get("cardDefinitionId", ""))
|
||||
|
||||
var widget: PanelContainer = _CARD_WIDGET_SCENE.instantiate()
|
||||
widget.top_level = false
|
||||
widget.anchor_left = 0.0
|
||||
widget.anchor_top = 0.0
|
||||
widget.anchor_right = 0.0
|
||||
widget.anchor_bottom = 0.0
|
||||
widget.position = Vector2.ZERO
|
||||
widget.size = widget.custom_minimum_size
|
||||
widget.visible = true
|
||||
widget.set_meta("card_instance_id", iid)
|
||||
|
||||
# Use the full CardDefinitionDto from ContentCache so CardWidget gets the
|
||||
# assets array (Art2D cdnUrl) and can load card art. Fall back to the
|
||||
# instance data if the definition hasn't been synced yet.
|
||||
var def: Dictionary = ContentCache.get_definition(def_id)
|
||||
if def.is_empty():
|
||||
def = card.duplicate()
|
||||
|
||||
# CardWidget._load_stats reads "movementPoints"; the CardInstanceDto calls
|
||||
# it "maxMp", so alias it into the def dict before passing.
|
||||
def["movementPoints"] = card.get("maxMp", def.get("movementPoints", null))
|
||||
|
||||
widget.setup(card, def)
|
||||
|
||||
# CardWidget emits card_pressed(definition_id); forward as hand-card click.
|
||||
# Note: focus_hand_card is intentionally NOT called here — clicking a card
|
||||
# brings it to front visually (via selection z_index boost) without shifting
|
||||
# its position in the fan rotation.
|
||||
widget.card_pressed.connect(func(_def_id: String) -> void:
|
||||
on_hand_card_clicked(iid, widget))
|
||||
|
||||
return widget
|
||||
|
||||
|
||||
func refresh_hand_selection() -> void:
|
||||
var needs_layout: bool = false
|
||||
for widget in hand_cards.get_children():
|
||||
if not widget.has_meta("card_instance_id"):
|
||||
continue
|
||||
var iid: String = str(widget.get_meta("card_instance_id"))
|
||||
var sel: bool = sel_card_id == iid and not sel_card_id.is_empty()
|
||||
if widget.has_method("set_selected"):
|
||||
widget.set_selected(sel)
|
||||
# Tween scale on selection change.
|
||||
# IMPORTANT: defer the tween + z_index update so they run AFTER the
|
||||
# current input event is fully processed. Setting z_index synchronously
|
||||
# while a mouse button is held causes Godot 4 to re-evaluate GUI focus
|
||||
# and deliver a synthetic second pressed=true event → immediate deselect.
|
||||
if sel != bool(widget.get_meta("_sel", false)):
|
||||
widget.set_meta("_sel", sel)
|
||||
needs_layout = true
|
||||
if needs_layout:
|
||||
queue_hand_layout()
|
||||
|
||||
|
||||
func tween_hand_card(widget: Control, sel: bool) -> void:
|
||||
if not is_instance_valid(widget):
|
||||
return
|
||||
widget.set_meta("_sel", sel)
|
||||
queue_hand_layout()
|
||||
|
||||
|
||||
func find_hand_card(iid: String) -> Dictionary:
|
||||
for card: Dictionary in Game.get_hand():
|
||||
if card.get("instanceId", "") == iid:
|
||||
return card
|
||||
return {}
|
||||
|
||||
|
||||
func configure_hand_spin_buttons() -> void:
|
||||
hand_spin_left.texture_normal = _HAND_ARROW_REGULAR
|
||||
hand_spin_left.texture_hover = _HAND_ARROW_HOVER
|
||||
hand_spin_left.texture_pressed = _HAND_ARROW_PRESSED
|
||||
hand_spin_left.modulate = Color(1, 1, 1, 0.92)
|
||||
hand_spin_left.focus_mode = Control.FOCUS_NONE
|
||||
hand_spin_left.rotation_degrees = 0.0
|
||||
|
||||
hand_spin_right.texture_normal = _HAND_ARROW_REGULAR
|
||||
hand_spin_right.texture_hover = _HAND_ARROW_HOVER
|
||||
hand_spin_right.texture_pressed = _HAND_ARROW_PRESSED
|
||||
hand_spin_right.modulate = Color(1, 1, 1, 0.92)
|
||||
hand_spin_right.focus_mode = Control.FOCUS_NONE
|
||||
hand_spin_right.rotation_degrees = 0.0
|
||||
layout_hand_spin_buttons()
|
||||
|
||||
|
||||
func layout_hand_spin_buttons() -> void:
|
||||
hand_spin_left.anchor_left = 0.0
|
||||
hand_spin_left.anchor_top = 0.5
|
||||
hand_spin_left.anchor_right = 0.0
|
||||
hand_spin_left.anchor_bottom = 0.5
|
||||
hand_spin_left.offset_left = 8.0
|
||||
hand_spin_left.offset_top = -22.0
|
||||
hand_spin_left.offset_right = 52.0
|
||||
hand_spin_left.offset_bottom = 22.0
|
||||
hand_spin_left.custom_minimum_size = Vector2(44, 44)
|
||||
hand_spin_left.size = Vector2(44, 44)
|
||||
|
||||
hand_spin_right.anchor_left = 1.0
|
||||
hand_spin_right.anchor_top = 0.5
|
||||
hand_spin_right.anchor_right = 1.0
|
||||
hand_spin_right.anchor_bottom = 0.5
|
||||
hand_spin_right.offset_left = -52.0
|
||||
hand_spin_right.offset_top = -22.0
|
||||
hand_spin_right.offset_right = -8.0
|
||||
hand_spin_right.offset_bottom = 22.0
|
||||
hand_spin_right.custom_minimum_size = Vector2(44, 44)
|
||||
hand_spin_right.size = Vector2(44, 44)
|
||||
|
||||
|
||||
func sync_hand_spin_buttons() -> void:
|
||||
var enabled: bool = hand_cards.get_child_count() > 1
|
||||
hand_spin_left.visible = enabled
|
||||
hand_spin_right.visible = enabled
|
||||
hand_spin_left.disabled = not enabled
|
||||
hand_spin_right.disabled = not enabled
|
||||
|
||||
|
||||
func spin_hand(direction: int) -> void:
|
||||
var card_count: int = hand_cards.get_child_count()
|
||||
if card_count <= 1:
|
||||
return
|
||||
hand_focus_index = posmod(hand_focus_index + direction, card_count)
|
||||
layout_hand_cards()
|
||||
|
||||
|
||||
func focus_hand_card(iid: String) -> void:
|
||||
var idx: int = 0
|
||||
for widget in hand_cards.get_children():
|
||||
if str(widget.get_meta("card_instance_id", "")) == iid:
|
||||
hand_focus_index = idx
|
||||
layout_hand_cards()
|
||||
return
|
||||
idx += 1
|
||||
|
||||
|
||||
func queue_hand_layout() -> void:
|
||||
if not is_inside_tree():
|
||||
return
|
||||
layout_hand_cards.call_deferred()
|
||||
|
||||
|
||||
func layout_hand_cards() -> void:
|
||||
var widgets: Array = hand_cards.get_children()
|
||||
var widget_count: int = widgets.size()
|
||||
if widget_count == 0:
|
||||
return
|
||||
|
||||
hand_focus_index = posmod(hand_focus_index, widget_count)
|
||||
hand_cards.position = Vector2.ZERO
|
||||
hand_cards.size = hand_area.size
|
||||
var viewport_size: Vector2 = hand_area.size
|
||||
if viewport_size.x <= 0.0 or viewport_size.y <= 0.0:
|
||||
return
|
||||
|
||||
var sample: Control = widgets[0] as Control
|
||||
sample.size = sample.custom_minimum_size
|
||||
var sample_size: Vector2 = hand_card_size(sample)
|
||||
var side_margin: float = 40.0
|
||||
var usable_width: float = maxf(120.0, viewport_size.x - side_margin * 2.0)
|
||||
var max_rel: int = 0
|
||||
var fan_half_width: float = minf(usable_width * 0.5 - sample_size.x * 0.5, 120.0 + widget_count * 18.0)
|
||||
fan_half_width = maxf(fan_half_width, 0.0)
|
||||
var fit_scale: float = minf(0.92, maxf(0.52, (viewport_size.y - 36.0) / sample_size.y))
|
||||
var scaled_height: float = sample_size.y * fit_scale
|
||||
var base_y: float = maxf(0.0, viewport_size.y - scaled_height - 28.0)
|
||||
var arc_height: float = minf(34.0, viewport_size.y * 0.14)
|
||||
var max_angle_deg: float = clampf(14.0 + widget_count * 2.4, 18.0, 34.0)
|
||||
|
||||
for i in range(widget_count):
|
||||
var slot_i: int = int((widgets[i] as Control).get_meta("_fan_slot", i))
|
||||
max_rel = max(max_rel, abs(wrapped_hand_delta(slot_i, widget_count)))
|
||||
|
||||
for i in range(widget_count):
|
||||
var widget: Control = widgets[i] as Control
|
||||
if widget == null:
|
||||
continue
|
||||
widget.size = widget.custom_minimum_size
|
||||
|
||||
var slot: int = int(widget.get_meta("_fan_slot", i))
|
||||
var rel: int = wrapped_hand_delta(slot, widget_count)
|
||||
var t: float = 0.0 if max_rel == 0 else float(rel) / float(max_rel)
|
||||
var angle_deg: float = t * max_angle_deg
|
||||
var card_size: Vector2 = hand_card_size(widget)
|
||||
var edge_factor: float = absf(t)
|
||||
var lift: float = 0.0
|
||||
var scale_amt: float = fit_scale * lerpf(1.0, 0.84, edge_factor)
|
||||
var is_selected: bool = bool(widget.get_meta("_sel", false))
|
||||
|
||||
if is_selected:
|
||||
scale_amt += 0.08
|
||||
lift += 16.0
|
||||
|
||||
var pos: Vector2 = Vector2.ZERO
|
||||
pos.x = viewport_size.x * 0.5 + t * fan_half_width - (card_size.x * scale_amt) * 0.5
|
||||
pos.y = base_y + float(pow(edge_factor, 1.35)) * arc_height - lift
|
||||
pos.x = clampf(pos.x, side_margin, maxf(side_margin, viewport_size.x - side_margin - card_size.x * scale_amt))
|
||||
pos.y = clampf(pos.y, 0.0, maxf(0.0, viewport_size.y - card_size.y * scale_amt))
|
||||
var z: int = 20 + int((1.0 - edge_factor) * 100.0)
|
||||
if is_selected:
|
||||
z += 120
|
||||
widget.set_meta("_hand_stack", z)
|
||||
|
||||
apply_hand_card_transform(widget, pos, deg_to_rad(angle_deg * 0.35), scale_amt, z)
|
||||
|
||||
# Reorder children by z so Godot routes GUI input to the visually topmost card.
|
||||
# Positions are stable because we use _fan_slot metadata, not child index.
|
||||
restack_hand_cards()
|
||||
|
||||
|
||||
func restack_hand_cards() -> void:
|
||||
var ordered: Array = []
|
||||
for child in hand_cards.get_children():
|
||||
if child is Control:
|
||||
ordered.append(child as Control)
|
||||
ordered.sort_custom(func(a: Control, b: Control) -> bool:
|
||||
return int(a.get_meta("_hand_stack", 0)) < int(b.get_meta("_hand_stack", 0))
|
||||
)
|
||||
for i in range(ordered.size()):
|
||||
hand_cards.move_child(ordered[i], i)
|
||||
|
||||
|
||||
func apply_hand_card_transform(widget: Control, pos: Vector2, rot: float, scale_amt: float, z: int) -> void:
|
||||
widget.pivot_offset = hand_card_size(widget) * 0.5
|
||||
widget.z_index = z
|
||||
var existing: Variant = widget.get_meta("_hand_tween", null)
|
||||
if existing is Tween and is_instance_valid(existing):
|
||||
(existing as Tween).kill()
|
||||
|
||||
# New widgets have never been positioned — snap them in place so they don't
|
||||
# slide in from (0,0). All subsequent layout calls tween normally.
|
||||
if not widget.has_meta("_hand_positioned"):
|
||||
widget.set_meta("_hand_positioned", true)
|
||||
widget.position = pos
|
||||
widget.rotation = rot
|
||||
widget.scale = Vector2.ONE * scale_amt
|
||||
return
|
||||
|
||||
var tw: Tween = create_tween().set_parallel(true)
|
||||
tw.set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
|
||||
tw.tween_property(widget, "position", pos, 0.18)
|
||||
tw.tween_property(widget, "rotation", rot, 0.18)
|
||||
tw.tween_property(widget, "scale", Vector2.ONE * scale_amt, 0.18)
|
||||
widget.set_meta("_hand_tween", tw)
|
||||
|
||||
|
||||
func hand_card_size(widget: Control) -> Vector2:
|
||||
var size_v: Vector2 = widget.size
|
||||
if size_v.x <= 0.0 or size_v.y <= 0.0:
|
||||
size_v = widget.custom_minimum_size
|
||||
if size_v.x <= 0.0:
|
||||
size_v.x = 160.0
|
||||
if size_v.y <= 0.0:
|
||||
size_v.y = 257.0
|
||||
return size_v
|
||||
|
||||
|
||||
func wrapped_hand_delta(index: int, total: int) -> int:
|
||||
var delta: int = index - hand_focus_index
|
||||
if total <= 1:
|
||||
return 0
|
||||
if delta > total / 2:
|
||||
delta -= total
|
||||
elif delta < -int(ceil(total * 0.5)):
|
||||
delta += total
|
||||
return delta
|
||||
@@ -0,0 +1 @@
|
||||
uid://cjntlh271gouc
|
||||
@@ -0,0 +1,304 @@
|
||||
class_name HudController
|
||||
extends Node
|
||||
|
||||
# ── Node refs (set from game_screen) ─────────────────────────────────────────
|
||||
|
||||
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
|
||||
|
||||
# ── Public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
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())
|
||||
|
||||
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
|
||||
rebuild_turn_order_strip(state)
|
||||
else:
|
||||
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
|
||||
|
||||
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"
|
||||
else:
|
||||
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)
|
||||
|
||||
# Always hide the 2-player opponent panel; show turn strip for all player counts.
|
||||
opp_panel.visible = false
|
||||
var all_players: Array = state.get("players", [])
|
||||
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
|
||||
|
||||
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():
|
||||
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", {})
|
||||
|
||||
players.sort_custom(func(a: Dictionary, b: Dictionary) -> bool:
|
||||
return int(a.get("seatIndex", 0)) < int(b.get("seatIndex", 0)))
|
||||
|
||||
for p: Dictionary in players:
|
||||
var pid: String = str(p.get("accountId", ""))
|
||||
var is_active: bool = pid == active_id
|
||||
var eliminated: bool = bool(p.get("isEliminated", false))
|
||||
var team_idx: int = int(p.get("teamIndex", -1))
|
||||
var hex_str: String = str(team_colors.get(str(team_idx), ""))
|
||||
var display: String = Game.get_display_name(pid)
|
||||
|
||||
var row: PanelContainer = PanelContainer.new()
|
||||
row.custom_minimum_size = Vector2(0, 40)
|
||||
row.self_modulate = Color(1, 1, 1, 0.4 if eliminated else 1.0)
|
||||
|
||||
var style: StyleBoxFlat = StyleBoxFlat.new()
|
||||
style.bg_color = Color(0.18, 0.16, 0.08, 0.92) if is_active else Color(0.10, 0.10, 0.13, 0.85)
|
||||
style.border_width_left = 4
|
||||
style.border_color = Color(1.0, 0.85, 0.2) if is_active \
|
||||
else (Color.html("#" + hex_str) if not hex_str.is_empty() else Color(0.4, 0.4, 0.4))
|
||||
row.add_theme_stylebox_override("panel", style)
|
||||
|
||||
var margin: MarginContainer = MarginContainer.new()
|
||||
margin.add_theme_constant_override("margin_left", 8)
|
||||
margin.add_theme_constant_override("margin_right", 8)
|
||||
margin.add_theme_constant_override("margin_top", 4)
|
||||
margin.add_theme_constant_override("margin_bottom", 4)
|
||||
row.add_child(margin)
|
||||
|
||||
var hbox: HBoxContainer = HBoxContainer.new()
|
||||
hbox.add_theme_constant_override("separation", 12)
|
||||
margin.add_child(hbox)
|
||||
|
||||
var name_lbl: Label = Label.new()
|
||||
name_lbl.text = ("★ " if is_active else "") + display + (" [X]" if eliminated else "")
|
||||
name_lbl.add_theme_font_size_override("font_size", 12)
|
||||
name_lbl.custom_minimum_size = Vector2(120, 0)
|
||||
name_lbl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
name_lbl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
if is_active:
|
||||
name_lbl.add_theme_color_override("font_color", Color(1.0, 0.9, 0.3))
|
||||
elif eliminated:
|
||||
name_lbl.add_theme_color_override("font_color", Color(0.4, 0.4, 0.4))
|
||||
hbox.add_child(name_lbl)
|
||||
|
||||
var sp_lbl_row: Label = Label.new()
|
||||
sp_lbl_row.text = "SP: %d" % int(p.get("currentSp", 0))
|
||||
sp_lbl_row.add_theme_font_size_override("font_size", 11)
|
||||
sp_lbl_row.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
sp_lbl_row.tooltip_text = "Spirit Points"
|
||||
hbox.add_child(sp_lbl_row)
|
||||
|
||||
var st_lbl_row: Label = Label.new()
|
||||
st_lbl_row.text = "ST: %d" % int(p.get("currentSt", 0))
|
||||
st_lbl_row.add_theme_font_size_override("font_size", 11)
|
||||
st_lbl_row.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
st_lbl_row.tooltip_text = "Sacrifice Tokens"
|
||||
hbox.add_child(st_lbl_row)
|
||||
|
||||
var deck_lbl_row: Label = Label.new()
|
||||
deck_lbl_row.text = "Deck: %d" % int(p.get("deckCount", 0))
|
||||
deck_lbl_row.add_theme_font_size_override("font_size", 11)
|
||||
deck_lbl_row.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
hbox.add_child(deck_lbl_row)
|
||||
|
||||
var disc_cards: Array = p.get("discard", [])
|
||||
var disc_count: int = disc_cards.size() if not disc_cards.is_empty() else int(p.get("discardCount", 0))
|
||||
var disc_btn: Button = Button.new()
|
||||
disc_btn.text = "Discard: %d" % disc_count
|
||||
disc_btn.add_theme_font_size_override("font_size", 11)
|
||||
disc_btn.custom_minimum_size = Vector2(80, 0)
|
||||
if not disc_cards.is_empty():
|
||||
var cap_display: String = display
|
||||
var cap_cards: Array = disc_cards
|
||||
disc_btn.pressed.connect(func() -> void:
|
||||
show_discard_for("%s Discard" % cap_display, cap_cards))
|
||||
else:
|
||||
disc_btn.disabled = true
|
||||
hbox.add_child(disc_btn)
|
||||
|
||||
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():
|
||||
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)))
|
||||
|
||||
for p: Dictionary in players:
|
||||
var pid: String = str(p.get("accountId", ""))
|
||||
var is_me: bool = (not is_spectating) and pid == Auth.user_id
|
||||
var is_active: bool = pid == active_id
|
||||
var eliminated: bool = bool(p.get("isEliminated", false))
|
||||
var team_idx: int = int(p.get("teamIndex", -1))
|
||||
var hex_str: String = str(team_colors.get(str(team_idx), ""))
|
||||
var display: String = "You" if is_me else Game.get_display_name(pid)
|
||||
|
||||
var chip: PanelContainer = PanelContainer.new()
|
||||
chip.custom_minimum_size = Vector2(72, 36)
|
||||
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
|
||||
if not hex_str.is_empty():
|
||||
style.border_color = Color.html("#" + hex_str)
|
||||
else:
|
||||
style.border_color = Color(0.4, 0.4, 0.4)
|
||||
chip.add_theme_stylebox_override("panel", style)
|
||||
|
||||
var lbl: Label = Label.new()
|
||||
lbl.text = ("★ " if is_active else "") + display + (" ✗" if eliminated else "")
|
||||
lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
lbl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
lbl.add_theme_font_size_override("font_size", 10)
|
||||
lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
if is_active:
|
||||
lbl.add_theme_color_override("font_color", Color(1.0, 0.9, 0.3))
|
||||
elif eliminated:
|
||||
lbl.add_theme_color_override("font_color", Color(0.4, 0.4, 0.4))
|
||||
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))
|
||||
var hand: int = int(p.get("handCount", 0))
|
||||
var deck: int = int(p.get("deckCount", 0))
|
||||
chip.tooltip_text = "%s\nSP: %d ST: %d\nHand: %d Deck: %d" % [
|
||||
display, sp, st, hand, deck]
|
||||
|
||||
chip.add_child(lbl)
|
||||
turn_order_strip.add_child(chip)
|
||||
|
||||
|
||||
func show_own_discard(state: Dictionary) -> void:
|
||||
show_discard_for("Your Discard", Game.get_my_player().get("discard", []))
|
||||
|
||||
|
||||
func show_opp_discard(state: Dictionary) -> void:
|
||||
show_discard_for("Opponent Discard", Game.get_opponent().get("discard", []))
|
||||
|
||||
|
||||
func show_discard_for(title: String, cards: Array) -> void:
|
||||
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)
|
||||
else:
|
||||
for card: Dictionary in cards:
|
||||
dv_list.add_child(make_discard_row(card))
|
||||
dv_overlay.visible = true
|
||||
|
||||
|
||||
func make_discard_row(card: Dictionary) -> Control:
|
||||
var hbox: HBoxContainer = HBoxContainer.new()
|
||||
hbox.add_theme_constant_override("separation", 8)
|
||||
hbox.custom_minimum_size = Vector2(0, 32)
|
||||
var type_lbl: Label = Label.new()
|
||||
type_lbl.text = "[%s]" % card.get("cardType", "?")
|
||||
type_lbl.add_theme_font_size_override("font_size", 11)
|
||||
type_lbl.add_theme_color_override("font_color", Color(0.6, 0.6, 0.7))
|
||||
type_lbl.custom_minimum_size = Vector2(90, 0)
|
||||
type_lbl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
hbox.add_child(type_lbl)
|
||||
var name_lbl: Label = Label.new()
|
||||
name_lbl.text = card.get("name", "Unknown")
|
||||
name_lbl.add_theme_font_size_override("font_size", 13)
|
||||
name_lbl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
name_lbl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
hbox.add_child(name_lbl)
|
||||
var aff_lbl: Label = Label.new()
|
||||
aff_lbl.text = card.get("affinity", "")
|
||||
aff_lbl.add_theme_font_size_override("font_size", 11)
|
||||
aff_lbl.add_theme_color_override("font_color", Color(0.6, 0.7, 0.85))
|
||||
aff_lbl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
hbox.add_child(aff_lbl)
|
||||
return hbox
|
||||
@@ -0,0 +1 @@
|
||||
uid://c0cr5qgneoab1
|
||||
@@ -0,0 +1,513 @@
|
||||
class_name TileDrawer
|
||||
extends Node
|
||||
|
||||
signal focus_camera_on_tile(world_pos: Vector3)
|
||||
|
||||
const TILE_DRAWER_WIDTH: float = 260.0
|
||||
const TILE_DRAWER_TOGGLE_WIDTH: float = 36.0
|
||||
const TILE_DRAWER_TOGGLE_MARGIN: float = 12.0
|
||||
|
||||
var tile_drawer: PanelContainer = null
|
||||
var tile_drawer_open: bool = false
|
||||
var tile_drawer_tween: Tween = null
|
||||
var tile_drawer_last_tile: Dictionary = {}
|
||||
var tile_drawer_tile_labels: Array = []
|
||||
var tile_drawer_spirit_labels: Array = []
|
||||
var tile_drawer_token_labels: Array = []
|
||||
var tile_drawer_arch_labels: Array = []
|
||||
var tile_drawer_ruin_labels: Array = []
|
||||
var tile_drawer_tile_section: Dictionary = {}
|
||||
var tile_drawer_spirit_section: Dictionary = {}
|
||||
var tile_drawer_token_section: Dictionary = {}
|
||||
var tile_drawer_arch_section: Dictionary = {}
|
||||
var tile_drawer_ruin_section: Dictionary = {}
|
||||
var tile_drawer_spirit_effects_section: Dictionary = {}
|
||||
var tile_drawer_token_effects_section: Dictionary = {}
|
||||
var tile_drawer_arch_effects_section: Dictionary = {}
|
||||
var tile_drawer_ruin_effects_section: Dictionary = {}
|
||||
var tile_drawer_spirit_effects_labels: Array = []
|
||||
var tile_drawer_token_effects_labels: Array = []
|
||||
var tile_drawer_arch_effects_labels: Array = []
|
||||
var tile_drawer_ruin_effects_labels: Array = []
|
||||
|
||||
# Set by parent
|
||||
var hud: CanvasLayer = null
|
||||
var tile_drawer_toggle_btn: Button = null
|
||||
|
||||
|
||||
func create_tile_drawer() -> void:
|
||||
var panel: PanelContainer = PanelContainer.new()
|
||||
panel.anchor_left = 1.0
|
||||
panel.anchor_right = 1.0
|
||||
panel.anchor_top = 0.0
|
||||
panel.anchor_bottom = 1.0
|
||||
panel.offset_left = 0.0
|
||||
panel.offset_right = 0.0
|
||||
panel.offset_top = 0.0
|
||||
panel.offset_bottom = 0.0
|
||||
panel.visible = false
|
||||
hud.add_child(panel)
|
||||
tile_drawer = panel
|
||||
|
||||
var margin: MarginContainer = MarginContainer.new()
|
||||
margin.layout_mode = 2
|
||||
margin.add_theme_constant_override("margin_left", 12)
|
||||
margin.add_theme_constant_override("margin_right", 12)
|
||||
margin.add_theme_constant_override("margin_top", 12)
|
||||
margin.add_theme_constant_override("margin_bottom", 12)
|
||||
panel.add_child(margin)
|
||||
|
||||
var vbox: VBoxContainer = VBoxContainer.new()
|
||||
vbox.layout_mode = 2
|
||||
vbox.add_theme_constant_override("separation", 6)
|
||||
margin.add_child(vbox)
|
||||
|
||||
# Title row with close button.
|
||||
var title_row: HBoxContainer = HBoxContainer.new()
|
||||
title_row.layout_mode = 2
|
||||
var title_lbl: Label = Label.new()
|
||||
title_lbl.text = "Tile Details"
|
||||
title_lbl.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
title_lbl.add_theme_font_size_override("font_size", 15)
|
||||
var close_btn: Button = Button.new()
|
||||
close_btn.text = "×"
|
||||
close_btn.custom_minimum_size = Vector2(28, 28)
|
||||
close_btn.pressed.connect(close_tile_drawer)
|
||||
title_row.add_child(title_lbl)
|
||||
title_row.add_child(close_btn)
|
||||
vbox.add_child(title_row)
|
||||
|
||||
var sep: HSeparator = HSeparator.new()
|
||||
sep.layout_mode = 2
|
||||
vbox.add_child(sep)
|
||||
|
||||
tile_drawer_tile_section = create_tile_drawer_section(vbox, "Tile Details", true)
|
||||
tile_drawer_spirit_section = create_tile_drawer_section(vbox, "Spirit Details", false)
|
||||
tile_drawer_spirit_effects_section = create_scrollable_section(vbox, "Active Effects")
|
||||
tile_drawer_token_section = create_tile_drawer_section(vbox, "Spirit Token Details", false)
|
||||
tile_drawer_token_effects_section = create_scrollable_section(vbox, "Active Effects")
|
||||
tile_drawer_arch_section = create_tile_drawer_section(vbox, "ArchSpirit Details", false)
|
||||
tile_drawer_arch_effects_section = create_scrollable_section(vbox, "Active Effects")
|
||||
tile_drawer_ruin_section = create_tile_drawer_section(vbox, "Ruin Details", false)
|
||||
tile_drawer_ruin_effects_section = create_scrollable_section(vbox, "Active Effects")
|
||||
|
||||
tile_drawer_tile_labels = create_detail_labels(tile_drawer_tile_section["content"], 5)
|
||||
tile_drawer_spirit_labels = create_detail_labels(tile_drawer_spirit_section["content"], 5)
|
||||
tile_drawer_token_labels = create_detail_labels(tile_drawer_token_section["content"], 5)
|
||||
tile_drawer_arch_labels = create_detail_labels(tile_drawer_arch_section["content"], 6)
|
||||
tile_drawer_ruin_labels = create_detail_labels(tile_drawer_ruin_section["content"], 2)
|
||||
|
||||
set_tile_drawer_button_state()
|
||||
|
||||
|
||||
func create_tile_drawer_section(parent: VBoxContainer, title: String,
|
||||
expanded: bool) -> Dictionary:
|
||||
var section: VBoxContainer = VBoxContainer.new()
|
||||
section.layout_mode = 2
|
||||
section.add_theme_constant_override("separation", 4)
|
||||
parent.add_child(section)
|
||||
|
||||
var header: Button = Button.new()
|
||||
header.layout_mode = 2
|
||||
header.toggle_mode = true
|
||||
header.button_pressed = expanded
|
||||
header.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
header.text = tile_drawer_section_title(title, expanded)
|
||||
section.add_child(header)
|
||||
|
||||
var content: VBoxContainer = VBoxContainer.new()
|
||||
content.layout_mode = 2
|
||||
content.visible = expanded
|
||||
content.add_theme_constant_override("separation", 2)
|
||||
section.add_child(content)
|
||||
|
||||
section.visible = expanded
|
||||
|
||||
header.toggled.connect(func(is_pressed: bool) -> void:
|
||||
content.visible = is_pressed
|
||||
header.text = tile_drawer_section_title(title, is_pressed))
|
||||
|
||||
return {
|
||||
"root": section,
|
||||
"header": header,
|
||||
"content": content,
|
||||
"title": title,
|
||||
}
|
||||
|
||||
|
||||
func tile_drawer_section_title(title: String, expanded: bool) -> String:
|
||||
return "%s %s" % ["[-]" if expanded else "[+]", title]
|
||||
|
||||
|
||||
## Creates a collapsible section whose content sits inside a ScrollContainer so that
|
||||
## long effect lists don't overflow the drawer. The returned dict has the same keys
|
||||
## as create_tile_drawer_section ("root", "header", "content", "title") plus "scroll"
|
||||
## and a mutable "count" entry used to keep the header label up-to-date.
|
||||
func create_scrollable_section(parent: VBoxContainer, title: String) -> Dictionary:
|
||||
var section: VBoxContainer = VBoxContainer.new()
|
||||
section.layout_mode = 2
|
||||
section.add_theme_constant_override("separation", 4)
|
||||
parent.add_child(section)
|
||||
|
||||
var header: Button = Button.new()
|
||||
header.layout_mode = 2
|
||||
header.toggle_mode = true
|
||||
header.button_pressed = false
|
||||
header.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
header.text = tile_drawer_section_title(title, false)
|
||||
section.add_child(header)
|
||||
|
||||
var scroll: ScrollContainer = ScrollContainer.new()
|
||||
scroll.layout_mode = 2
|
||||
scroll.custom_minimum_size = Vector2(0, 90)
|
||||
scroll.vertical_scroll_mode = ScrollContainer.SCROLL_MODE_AUTO
|
||||
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
scroll.visible = false
|
||||
section.add_child(scroll)
|
||||
|
||||
var content: VBoxContainer = VBoxContainer.new()
|
||||
content.layout_mode = 2
|
||||
content.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
content.add_theme_constant_override("separation", 2)
|
||||
scroll.add_child(content)
|
||||
|
||||
section.visible = false
|
||||
|
||||
var data: Dictionary = {
|
||||
"root": section,
|
||||
"header": header,
|
||||
"scroll": scroll,
|
||||
"content": content,
|
||||
"title": title,
|
||||
"count": 0,
|
||||
}
|
||||
|
||||
header.toggled.connect(func(is_pressed: bool) -> void:
|
||||
scroll.visible = is_pressed
|
||||
var n: int = data.get("count", 0)
|
||||
var t: String = data.get("title", "Active Effects")
|
||||
var display: String = ("%s (%d)" % [t, n]) if n > 0 else t
|
||||
header.text = tile_drawer_section_title(display, is_pressed))
|
||||
|
||||
return data
|
||||
|
||||
|
||||
## Updates the effects section header text (e.g. "Active Effects (3)") and stores
|
||||
## the count so the toggle signal can rebuild the label correctly.
|
||||
func update_effects_section_header(section: Dictionary, count: int) -> void:
|
||||
section["count"] = count
|
||||
var header: Button = section.get("header") as Button
|
||||
if not is_instance_valid(header):
|
||||
return
|
||||
var title: String = section.get("title", "Active Effects")
|
||||
var display: String = ("%s (%d)" % [title, count]) if count > 0 else title
|
||||
header.text = tile_drawer_section_title(display, header.button_pressed)
|
||||
|
||||
|
||||
func create_detail_labels(parent: VBoxContainer, count: int) -> Array:
|
||||
var labels: Array = []
|
||||
for _i in range(count):
|
||||
var lbl: Label = Label.new()
|
||||
lbl.layout_mode = 2
|
||||
lbl.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
lbl.add_theme_font_size_override("font_size", 12)
|
||||
lbl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
parent.add_child(lbl)
|
||||
labels.append(lbl)
|
||||
return labels
|
||||
|
||||
|
||||
func append_tile_drawer_label(parent: VBoxContainer, labels: Array) -> void:
|
||||
var lbl: Label = Label.new()
|
||||
lbl.layout_mode = 2
|
||||
lbl.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
lbl.add_theme_font_size_override("font_size", 12)
|
||||
lbl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
parent.add_child(lbl)
|
||||
labels.append(lbl)
|
||||
|
||||
|
||||
func set_tile_drawer_lines(section: Dictionary, labels: Array, lines: Array,
|
||||
tooltips: Array = []) -> void:
|
||||
var root: Control = section.get("root") as Control
|
||||
var content: VBoxContainer = section.get("content") as VBoxContainer
|
||||
if root == null:
|
||||
return
|
||||
if content == null:
|
||||
return
|
||||
while labels.size() < lines.size():
|
||||
append_tile_drawer_label(content, labels)
|
||||
root.visible = not lines.is_empty()
|
||||
for i in range(labels.size()):
|
||||
var lbl: Label = labels[i] as Label
|
||||
var show_line: bool = i < lines.size()
|
||||
lbl.visible = show_line
|
||||
if show_line:
|
||||
lbl.text = str(lines[i])
|
||||
lbl.tooltip_text = str(tooltips[i]) if i < tooltips.size() else ""
|
||||
else:
|
||||
lbl.tooltip_text = ""
|
||||
|
||||
|
||||
## Clears a scrollable effects section and resets its cached header/toggle state so
|
||||
## the next inspected tile does not inherit a stale count or expanded body.
|
||||
func clear_effects_section(section: Dictionary, labels: Array) -> void:
|
||||
set_tile_drawer_lines(section, labels, [])
|
||||
section["count"] = 0
|
||||
var header: Button = section.get("header") as Button
|
||||
if is_instance_valid(header):
|
||||
header.button_pressed = false
|
||||
header.text = tile_drawer_section_title(str(section.get("title", "Active Effects")), false)
|
||||
var scroll: ScrollContainer = section.get("scroll") as ScrollContainer
|
||||
if is_instance_valid(scroll):
|
||||
scroll.visible = false
|
||||
scroll.scroll_vertical = 0
|
||||
|
||||
|
||||
func find_unit_owner_account_id(unit_id: String) -> String:
|
||||
if unit_id.is_empty():
|
||||
return ""
|
||||
for player: Dictionary in Game.state.get("players", []):
|
||||
for unit: Dictionary in player.get("field", []):
|
||||
if str(unit.get("instanceId", "")) == unit_id:
|
||||
return str(player.get("accountId", ""))
|
||||
var arch: Dictionary = player.get("archSpirit", {})
|
||||
if str(arch.get("instanceId", "")) == unit_id:
|
||||
return str(player.get("accountId", ""))
|
||||
return ""
|
||||
|
||||
|
||||
func build_unit_detail_lines(unit: Dictionary, owner_id: String,
|
||||
include_tier: bool = false) -> Dictionary:
|
||||
var lines: Array = [
|
||||
"Name: %s" % str(unit.get("name", "?")),
|
||||
"Owner: %s" % Game.get_display_name(owner_id),
|
||||
]
|
||||
var tooltips: Array = ["", ""]
|
||||
if include_tier:
|
||||
lines.append("Tier: %d" % int(unit.get("tier", 0)))
|
||||
tooltips.append("")
|
||||
lines.append("HP: %d / %d" % [int(unit.get("currentHealth", 0)), int(unit.get("maxHealth", 0))])
|
||||
lines.append("DEF: %d / %d" % [int(unit.get("currentDefense", 0)), int(unit.get("maxDefense", 0))])
|
||||
lines.append("ATK: %d" % int(unit.get("damage", 0)))
|
||||
lines.append("MP: %d / %d" % [int(unit.get("currentMp", 0)), int(unit.get("maxMp", 0))])
|
||||
lines.append("Can Move: %s" % ("Yes" if bool(unit.get("canMove", false)) else "No"))
|
||||
lines.append("Can Attack: %s" % ("Yes" if bool(unit.get("canAttack", false)) else "No"))
|
||||
tooltips.append_array(["", "", "", "", "", ""])
|
||||
|
||||
var raw_abilities: Variant = unit.get("abilitiesJson")
|
||||
var parsed_abilities: Variant = JSON.parse_string("[]" if raw_abilities == null else str(raw_abilities))
|
||||
if parsed_abilities is Array:
|
||||
for ability_index: int in range((parsed_abilities as Array).size()):
|
||||
var ability: Dictionary = (parsed_abilities as Array)[ability_index] as Dictionary
|
||||
var ability_name: String = str(ability.get("name", ability.get("Name", "Ability %d" % ability_index)))
|
||||
var ability_desc: String = str(ability.get("description", ability.get("Description", "")))
|
||||
lines.append("Ability: %s" % ability_name)
|
||||
tooltips.append(ability_desc)
|
||||
|
||||
return {
|
||||
"lines": lines,
|
||||
"tooltips": tooltips,
|
||||
}
|
||||
|
||||
|
||||
## Appends any active effects targeting [param target_ref] (unit instanceId or ruinId)
|
||||
## into the provided [param lines] and [param tooltips] arrays.
|
||||
func append_active_effect_lines(target_ref: String, lines: Array, tooltips: Array) -> void:
|
||||
if target_ref.is_empty():
|
||||
return
|
||||
var all_effects: Variant = Game.state.get("activeEffects")
|
||||
if not all_effects is Array:
|
||||
return
|
||||
for ae: Dictionary in (all_effects as Array):
|
||||
if str(ae.get("targetRef", "")) != target_ref:
|
||||
continue
|
||||
var label: String = str(ae.get("label", "?"))
|
||||
var source_name: String = str(ae.get("sourceName", ""))
|
||||
var dur_type: String = str(ae.get("durationType", ""))
|
||||
var turns: int = int(ae.get("turnsRemaining", 0))
|
||||
var dur_text: String
|
||||
match dur_type:
|
||||
"ForNTurns": dur_text = "%d turn%s" % [turns, "s" if turns != 1 else ""]
|
||||
"UntilEndOfTurn": dur_text = "until end of turn"
|
||||
"UntilStartOfOwnerTurn": dur_text = "until owner's next turn"
|
||||
"UntilStartOfSourceOwnerTurn": dur_text = "until source's next turn"
|
||||
"WhileSourceOnBattlefield": dur_text = "while source lives"
|
||||
"WhileCondition": dur_text = "conditional"
|
||||
_: dur_text = dur_type.to_lower().replace("_", " ")
|
||||
var line: String
|
||||
if source_name.is_empty() or source_name == ae.get("sourceInstanceId", ""):
|
||||
line = "[Effect] %s (%s)" % [label, dur_text]
|
||||
else:
|
||||
line = "[Effect] %s (%s, from %s)" % [label, dur_text, source_name]
|
||||
lines.append(line)
|
||||
tooltips.append("")
|
||||
|
||||
|
||||
func set_tile_drawer_content(tile_data: Dictionary, state: Dictionary) -> void:
|
||||
tile_drawer_last_tile = tile_data.duplicate(true)
|
||||
set_tile_drawer_button_state()
|
||||
if tile_data.is_empty():
|
||||
set_tile_drawer_lines(tile_drawer_tile_section, tile_drawer_tile_labels, [])
|
||||
set_tile_drawer_lines(tile_drawer_spirit_section, tile_drawer_spirit_labels, [])
|
||||
set_tile_drawer_lines(tile_drawer_token_section, tile_drawer_token_labels, [])
|
||||
set_tile_drawer_lines(tile_drawer_arch_section, tile_drawer_arch_labels, [])
|
||||
set_tile_drawer_lines(tile_drawer_ruin_section, tile_drawer_ruin_labels, [])
|
||||
clear_effects_section(tile_drawer_spirit_effects_section, tile_drawer_spirit_effects_labels)
|
||||
clear_effects_section(tile_drawer_token_effects_section, tile_drawer_token_effects_labels)
|
||||
clear_effects_section(tile_drawer_arch_effects_section, tile_drawer_arch_effects_labels)
|
||||
clear_effects_section(tile_drawer_ruin_effects_section, tile_drawer_ruin_effects_labels)
|
||||
return
|
||||
|
||||
var coord: Dictionary = tile_data.get("coord", {})
|
||||
var cx: int = int(coord.get("x", 0))
|
||||
var cy: int = int(coord.get("y", 0))
|
||||
var aff: String = str(tile_data.get("resolvedAffinity", "?"))
|
||||
var b1: String = str(tile_data.get("base1", "?"))
|
||||
var b2: String = str(tile_data.get("base2", "?"))
|
||||
var ruin_id_value: Variant = tile_data.get("ruinId", "")
|
||||
var ruin_id: String = "" if ruin_id_value == null else str(ruin_id_value)
|
||||
var ruin_owner_id: String = str(tile_data.get("ruinOwner", ""))
|
||||
var occ_id: String = str(tile_data.get("occupantId", ""))
|
||||
var occ_owner_id: String = str(tile_data.get("occupantOwner", ""))
|
||||
var occ_unit: Dictionary = Game.get_unit_by_id(occ_id)
|
||||
var occ_type: String = str(occ_unit.get("cardType", ""))
|
||||
var occ_name: String = str(occ_unit.get("name", occ_id))
|
||||
|
||||
var tile_lines: Array = [
|
||||
"Coord: (%d, %d)" % [cx, cy],
|
||||
"Affinity: %s" % aff,
|
||||
"Base1: %s" % b1,
|
||||
"Base2: %s" % b2,
|
||||
"Occupant: %s" % ("None" if occ_id.is_empty() or occ_id == "null" else "%s (%s)" % [occ_name, occ_type]),
|
||||
]
|
||||
set_tile_drawer_lines(tile_drawer_tile_section, tile_drawer_tile_labels, tile_lines)
|
||||
|
||||
if not occ_id.is_empty() and occ_id != "null" and occ_type == "Spirit":
|
||||
var spirit_owner_id: String = occ_owner_id if not occ_owner_id.is_empty() else find_unit_owner_account_id(occ_id)
|
||||
var spirit_detail: Dictionary = build_unit_detail_lines(occ_unit, spirit_owner_id)
|
||||
set_tile_drawer_lines(
|
||||
tile_drawer_spirit_section, tile_drawer_spirit_labels,
|
||||
spirit_detail.get("lines", []), spirit_detail.get("tooltips", []))
|
||||
set_effects_section(occ_id, tile_drawer_spirit_effects_section, tile_drawer_spirit_effects_labels)
|
||||
else:
|
||||
set_tile_drawer_lines(tile_drawer_spirit_section, tile_drawer_spirit_labels, [])
|
||||
clear_effects_section(tile_drawer_spirit_effects_section, tile_drawer_spirit_effects_labels)
|
||||
|
||||
if not occ_id.is_empty() and occ_id != "null" and occ_type == "SpiritToken":
|
||||
var token_owner_id: String = occ_owner_id if not occ_owner_id.is_empty() else find_unit_owner_account_id(occ_id)
|
||||
var token_detail: Dictionary = build_unit_detail_lines(occ_unit, token_owner_id)
|
||||
set_tile_drawer_lines(
|
||||
tile_drawer_token_section, tile_drawer_token_labels,
|
||||
token_detail.get("lines", []), token_detail.get("tooltips", []))
|
||||
set_effects_section(occ_id, tile_drawer_token_effects_section, tile_drawer_token_effects_labels)
|
||||
else:
|
||||
set_tile_drawer_lines(tile_drawer_token_section, tile_drawer_token_labels, [])
|
||||
clear_effects_section(tile_drawer_token_effects_section, tile_drawer_token_effects_labels)
|
||||
|
||||
if not occ_id.is_empty() and occ_id != "null" and occ_type == "ArchSpirit":
|
||||
var arch_owner_id: String = occ_owner_id if not occ_owner_id.is_empty() else find_unit_owner_account_id(occ_id)
|
||||
var arch_detail: Dictionary = build_unit_detail_lines(occ_unit, arch_owner_id, true)
|
||||
set_tile_drawer_lines(
|
||||
tile_drawer_arch_section, tile_drawer_arch_labels,
|
||||
arch_detail.get("lines", []), arch_detail.get("tooltips", []))
|
||||
set_effects_section(occ_id, tile_drawer_arch_effects_section, tile_drawer_arch_effects_labels)
|
||||
else:
|
||||
set_tile_drawer_lines(tile_drawer_arch_section, tile_drawer_arch_labels, [])
|
||||
clear_effects_section(tile_drawer_arch_effects_section, tile_drawer_arch_effects_labels)
|
||||
|
||||
if ruin_id_value != null and not ruin_id.is_empty() and ruin_id != "null":
|
||||
var ruin_lines: Array = ["Ruin: %s" % ruin_id, "Owner: %s" % Game.get_display_name(ruin_owner_id)]
|
||||
var ruin_tooltips: Array = ["", ""]
|
||||
set_tile_drawer_lines(tile_drawer_ruin_section, tile_drawer_ruin_labels, ruin_lines, ruin_tooltips)
|
||||
set_effects_section(ruin_id, tile_drawer_ruin_effects_section, tile_drawer_ruin_effects_labels)
|
||||
else:
|
||||
set_tile_drawer_lines(tile_drawer_ruin_section, tile_drawer_ruin_labels, [])
|
||||
clear_effects_section(tile_drawer_ruin_effects_section, tile_drawer_ruin_effects_labels)
|
||||
|
||||
|
||||
## Populates [param section] (a scrollable effects section) with effects targeting
|
||||
## [param target_ref], then updates the header count badge.
|
||||
func set_effects_section(target_ref: String, section: Dictionary, labels: Array) -> void:
|
||||
var effect_lines: Array = []
|
||||
var effect_tooltips: Array = []
|
||||
append_active_effect_lines(target_ref, effect_lines, effect_tooltips)
|
||||
set_tile_drawer_lines(section, labels, effect_lines, effect_tooltips)
|
||||
update_effects_section_header(section, effect_lines.size())
|
||||
|
||||
|
||||
func set_tile_drawer_button_state() -> void:
|
||||
if not is_instance_valid(tile_drawer_toggle_btn):
|
||||
return
|
||||
var has_tile: bool = not tile_drawer_last_tile.is_empty()
|
||||
tile_drawer_toggle_btn.disabled = not has_tile
|
||||
tile_drawer_toggle_btn.text = ">" if tile_drawer_open else "<"
|
||||
layout_tile_drawer_toggle_button()
|
||||
|
||||
|
||||
func layout_tile_drawer_toggle_button() -> void:
|
||||
if not is_instance_valid(tile_drawer_toggle_btn):
|
||||
return
|
||||
if tile_drawer_open:
|
||||
tile_drawer_toggle_btn.offset_left = -TILE_DRAWER_WIDTH - TILE_DRAWER_TOGGLE_WIDTH
|
||||
tile_drawer_toggle_btn.offset_right = -TILE_DRAWER_WIDTH
|
||||
else:
|
||||
tile_drawer_toggle_btn.offset_left = -(TILE_DRAWER_TOGGLE_WIDTH + TILE_DRAWER_TOGGLE_MARGIN)
|
||||
tile_drawer_toggle_btn.offset_right = -TILE_DRAWER_TOGGLE_MARGIN
|
||||
tile_drawer_toggle_btn.offset_top = -24.0
|
||||
tile_drawer_toggle_btn.offset_bottom = 24.0
|
||||
|
||||
|
||||
func on_tile_drawer_toggle_pressed() -> void:
|
||||
if tile_drawer_open:
|
||||
close_tile_drawer()
|
||||
return
|
||||
if tile_drawer_last_tile.is_empty():
|
||||
return
|
||||
open_tile_drawer(tile_drawer_last_tile)
|
||||
|
||||
|
||||
func open_tile_drawer(tile: Dictionary) -> void:
|
||||
if not is_instance_valid(tile_drawer): return
|
||||
set_tile_drawer_content(tile, Game.state)
|
||||
|
||||
if tile_drawer_open:
|
||||
set_tile_drawer_button_state()
|
||||
return # already open, content updated above
|
||||
tile_drawer_open = true
|
||||
tile_drawer.visible = true
|
||||
set_tile_drawer_button_state()
|
||||
if tile_drawer_tween: tile_drawer_tween.kill()
|
||||
tile_drawer.offset_left = 0.0
|
||||
tile_drawer_tween = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_CUBIC)
|
||||
tile_drawer_tween.parallel().tween_property(tile_drawer, "offset_left", -TILE_DRAWER_WIDTH, 0.3)
|
||||
tile_drawer_tween.parallel().tween_property(
|
||||
tile_drawer_toggle_btn, "offset_left",
|
||||
-TILE_DRAWER_WIDTH - TILE_DRAWER_TOGGLE_WIDTH, 0.3)
|
||||
tile_drawer_tween.parallel().tween_property(
|
||||
tile_drawer_toggle_btn, "offset_right",
|
||||
-TILE_DRAWER_WIDTH, 0.3)
|
||||
|
||||
|
||||
func close_tile_drawer() -> void:
|
||||
if not is_instance_valid(tile_drawer) or not tile_drawer_open: return
|
||||
tile_drawer_open = false
|
||||
set_tile_drawer_button_state()
|
||||
if tile_drawer_tween: tile_drawer_tween.kill()
|
||||
tile_drawer_tween = create_tween().set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_CUBIC)
|
||||
tile_drawer_tween.parallel().tween_property(tile_drawer, "offset_left", 0.0, 0.25)
|
||||
tile_drawer_tween.parallel().tween_property(
|
||||
tile_drawer_toggle_btn, "offset_left",
|
||||
-(TILE_DRAWER_TOGGLE_WIDTH + TILE_DRAWER_TOGGLE_MARGIN), 0.25)
|
||||
tile_drawer_tween.parallel().tween_property(
|
||||
tile_drawer_toggle_btn, "offset_right",
|
||||
-TILE_DRAWER_TOGGLE_MARGIN, 0.25)
|
||||
tile_drawer_tween.tween_callback(func() -> void:
|
||||
if is_instance_valid(tile_drawer): tile_drawer.visible = false)
|
||||
|
||||
|
||||
## Emits focus_camera_on_tile with the world position of the given coord.
|
||||
## Accepts a pathfinder to resolve the coordinate to world space.
|
||||
func focus_camera_on_tile_at(coord: Vector2i, state: Dictionary, pathfinder: Pathfinder) -> void:
|
||||
var world_pos: Vector3 = pathfinder.coord_to_world(coord.x, coord.y)
|
||||
focus_camera_on_tile.emit(world_pos)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cbvcxlj28mwp3
|
||||
Reference in New Issue
Block a user