- Cards, result chips and the Earlier list render BBCode with RichTextLabel;
Play rows show [[refs]] as teal chips and {vars} in brass, lit rows show the
rolled text; missing/unset/too-deep markers are red.
- Hover pop-up (DetailsPopup) for table headers, entries with details, result
chips and [url] metas in rendered text; items with details get a small ⓘ.
- Card-mode tables show cards left and Reshuffle; chips note reshuffles.
- Local state: decks, persistent variables and history per collection via
StateStore (memory only when saving is off); delete_table forgets its state.
- Result tray: Copy menu (text / BBCode / with details) and a Variables tab
(edit, re-roll, clear; last roll's chain variables read-only).
- Reference pipes drawn dashed from TextExpander.references; lit when used.
- Build mode: weight field, per-entry and table details editors, a gear
button for table settings, pipe popover (count, save as, remove), range
clamps use min_value(); Build cards are 300px wide.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
269 lines
9.4 KiB
GDScript
269 lines
9.4 KiB
GDScript
class_name ResultTray
|
|
extends PanelContainer
|
|
## The strip along the bottom: the current roll as a chain of result chips
|
|
## joined by brass pipe pieces, a Copy menu, and on the right either the
|
|
## earlier rolls (default) or the Variables tab.
|
|
|
|
enum Side { EARLIER, VARIABLES }
|
|
|
|
const COPY_TEXT := 0
|
|
const COPY_BBCODE := 1
|
|
const COPY_DETAILS := 2
|
|
|
|
var main: Main
|
|
var side: int = Side.EARLIER
|
|
var _title: Label
|
|
var _again: Button
|
|
var _copy: MenuButton
|
|
var _flow: HFlowContainer
|
|
var _empty: Label
|
|
var _earlier_box: VBoxContainer
|
|
var _earlier: VBoxContainer
|
|
var _earlier_empty: Label
|
|
var _vars: VariablesPanel
|
|
var _tab_earlier: Button
|
|
var _tab_vars: Button
|
|
var _shown_for: Dictionary = {}
|
|
var _shown_count := 0
|
|
|
|
|
|
func setup(p_main: Main) -> void:
|
|
main = p_main
|
|
var sb := Style.box(Style.FELT_DEEP, 0, [16, 14, 16, 16])
|
|
sb.border_width_top = 1
|
|
sb.border_color = Color(1, 1, 1, 0.08)
|
|
add_theme_stylebox_override("panel", sb)
|
|
|
|
var h := HBoxContainer.new()
|
|
h.add_theme_constant_override("separation", 28)
|
|
add_child(h)
|
|
|
|
var now := VBoxContainer.new()
|
|
now.add_theme_constant_override("separation", 10)
|
|
now.size_flags_horizontal = SIZE_EXPAND_FILL
|
|
h.add_child(now)
|
|
var head := HBoxContainer.new()
|
|
head.add_theme_constant_override("separation", 12)
|
|
now.add_child(head)
|
|
_title = Style.make_label("RESULT", Style.caps(), 12, Style.ON_FELT_MUTED)
|
|
_title.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
head.add_child(_title)
|
|
_again = Style.bar_button("Roll again")
|
|
_again.pressed.connect(func() -> void:
|
|
if not main.current.is_empty():
|
|
main.start_roll(main.current["root"])
|
|
)
|
|
head.add_child(_again)
|
|
_copy = _make_copy_menu()
|
|
head.add_child(_copy)
|
|
_flow = HFlowContainer.new()
|
|
_flow.add_theme_constant_override("h_separation", 0)
|
|
_flow.add_theme_constant_override("v_separation", 8)
|
|
# Keep the tray's height steady while a new roll's chips arrive.
|
|
_flow.custom_minimum_size = Vector2(0, 58)
|
|
now.add_child(_flow)
|
|
_empty = Style.make_label("Click a die on any table to roll.", Style.body(), 16, Style.ON_FELT_MUTED)
|
|
now.add_child(_empty)
|
|
|
|
var right := VBoxContainer.new()
|
|
right.add_theme_constant_override("separation", 8)
|
|
right.custom_minimum_size = Vector2(340, 0)
|
|
h.add_child(right)
|
|
var tabs := HBoxContainer.new()
|
|
tabs.add_theme_constant_override("separation", 14)
|
|
right.add_child(tabs)
|
|
_tab_earlier = _tab("EARLIER")
|
|
_tab_earlier.pressed.connect(func() -> void: set_side(Side.EARLIER))
|
|
tabs.add_child(_tab_earlier)
|
|
_tab_vars = _tab("VARIABLES")
|
|
_tab_vars.tooltip_text = "Saved variables for this collection"
|
|
_tab_vars.pressed.connect(func() -> void: set_side(Side.VARIABLES))
|
|
tabs.add_child(_tab_vars)
|
|
|
|
_earlier_box = VBoxContainer.new()
|
|
_earlier_box.add_theme_constant_override("separation", 6)
|
|
right.add_child(_earlier_box)
|
|
_earlier = VBoxContainer.new()
|
|
_earlier.add_theme_constant_override("separation", 6)
|
|
_earlier_box.add_child(_earlier)
|
|
_earlier_empty = Style.make_label("Older rolls show here.", Style.body(), 15, Style.ON_FELT_MUTED)
|
|
_earlier_box.add_child(_earlier_empty)
|
|
_vars = VariablesPanel.new()
|
|
_vars.setup(main)
|
|
right.add_child(_vars)
|
|
set_side(Side.EARLIER)
|
|
|
|
|
|
func _tab(text: String) -> Button:
|
|
var b := Button.new()
|
|
b.text = text
|
|
b.toggle_mode = true
|
|
b.add_theme_font_override("font", Style.caps())
|
|
b.add_theme_font_size_override("font_size", 12)
|
|
var n := Style.box(Color(0, 0, 0, 0), 0, [0, 0, 0, 3])
|
|
var on := Style.box(Color(0, 0, 0, 0), 0, [0, 0, 0, 1])
|
|
on.border_width_bottom = 2
|
|
on.border_color = Style.BRASS
|
|
Style.skin_button(b, n, n, on, Style.ON_FELT_MUTED, Style.ON_FELT, Style.ON_FELT)
|
|
b.add_theme_stylebox_override("focus", Style.box(Color(0, 0, 0, 0)))
|
|
return b
|
|
|
|
|
|
func set_side(s: int) -> void:
|
|
side = s
|
|
_tab_earlier.set_pressed_no_signal(s == Side.EARLIER)
|
|
_tab_vars.set_pressed_no_signal(s == Side.VARIABLES)
|
|
_earlier_box.visible = s == Side.EARLIER
|
|
_vars.visible = s == Side.VARIABLES
|
|
if s == Side.VARIABLES:
|
|
_vars.render()
|
|
|
|
|
|
func _make_copy_menu() -> MenuButton:
|
|
var m := MenuButton.new()
|
|
m.text = "Copy"
|
|
m.tooltip_text = "Copy this result"
|
|
m.flat = false
|
|
var normal := Style.bordered(Style.box(Color(1, 1, 1, 0.04), 8, [12, 6, 12, 6]), 1, Color(1, 1, 1, 0.16))
|
|
var hover := Style.bordered(Style.box(Color(1, 1, 1, 0.1), 8, [12, 6, 12, 6]), 1, Color(1, 1, 1, 0.16))
|
|
Style.skin_button(m, normal, hover, hover, Style.ON_FELT)
|
|
m.add_theme_font_size_override("font_size", 15)
|
|
var pm := m.get_popup()
|
|
pm.add_item("Copy as text", COPY_TEXT)
|
|
pm.add_item("Copy as BBCode", COPY_BBCODE)
|
|
pm.add_item("Copy with details", COPY_DETAILS)
|
|
pm.add_theme_stylebox_override("panel", Style.bordered(Style.box(Style.CARD, 8, [6, 6, 6, 6]), 1, Style.RULE))
|
|
pm.add_theme_stylebox_override("hover", Style.box(Style.LIT, 5, [8, 4, 8, 4]))
|
|
pm.add_theme_color_override("font_color", Style.INK)
|
|
pm.add_theme_color_override("font_hover_color", Style.INK)
|
|
pm.add_theme_font_override("font", Style.body())
|
|
pm.add_theme_font_size_override("font_size", 15)
|
|
pm.id_pressed.connect(func(id: int) -> void: main.copy_current(id))
|
|
return m
|
|
|
|
|
|
func render() -> void:
|
|
var current := main.current
|
|
var steps: Array = current.get("steps", [])
|
|
var fresh_from := 0
|
|
if is_same(current, _shown_for):
|
|
fresh_from = _shown_count
|
|
_shown_for = current
|
|
_shown_count = steps.size()
|
|
|
|
for c in _flow.get_children():
|
|
_flow.remove_child(c)
|
|
c.queue_free()
|
|
_empty.visible = current.is_empty()
|
|
if current.is_empty():
|
|
_title.text = "RESULT"
|
|
_again.hide()
|
|
_copy.hide()
|
|
else:
|
|
var root_name := Formatter.strip_tags(str(current["root_name"]))
|
|
_title.text = ("Result · %s" % root_name).to_upper()
|
|
_again.text = "Roll %s again" % root_name
|
|
_again.visible = main.data.get_table(current["root"]) != null
|
|
var done: bool = current.get("done", false)
|
|
_copy.visible = done
|
|
for i in steps.size():
|
|
var step: Dictionary = steps[i]
|
|
if i > 0:
|
|
_flow.add_child(_link(step.get("inline", false)))
|
|
var chip := _chip(step, done and i == steps.size() - 1)
|
|
_flow.add_child(chip)
|
|
if i >= fresh_from:
|
|
chip.modulate.a = 0.3
|
|
create_tween().tween_property(chip, "modulate:a", 1.0, 0.25)
|
|
|
|
for c in _earlier.get_children():
|
|
_earlier.remove_child(c)
|
|
c.queue_free()
|
|
_earlier_empty.visible = main.history.is_empty()
|
|
for rec in main.history:
|
|
var row := HBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 8)
|
|
var time := Style.make_label(clock(rec["time"]), Style.body(), 14, Style.ON_FELT_MUTED)
|
|
time.custom_minimum_size = Vector2(44, 0)
|
|
time.size_flags_vertical = SIZE_SHRINK_BEGIN
|
|
row.add_child(time)
|
|
var texts := PackedStringArray()
|
|
for s: Dictionary in rec["steps"]:
|
|
if not s.get("inline", false):
|
|
texts.append(RichText.decorate(str(s["text"]), true))
|
|
var line := RichText.label("[color=#%s]%s:[/color] %s" % [Style.ON_FELT_MUTED.to_html(false),
|
|
RichText.plain(Formatter.strip_tags(str(rec["root_name"]))), " → ".join(texts)], 14, Style.ON_FELT, false)
|
|
line.size_flags_horizontal = SIZE_EXPAND_FILL
|
|
RichText.hook_hover(line, main)
|
|
row.add_child(line)
|
|
_earlier.add_child(row)
|
|
|
|
var n := main.persistent_vars.size()
|
|
_tab_vars.text = "VARIABLES · %d" % n if n > 0 else "VARIABLES"
|
|
if side == Side.VARIABLES:
|
|
_vars.render()
|
|
|
|
|
|
func _chip(step: Dictionary, last: bool) -> Control:
|
|
var inline: bool = step.get("inline", false)
|
|
var p := PanelContainer.new()
|
|
var sb := Style.box(Style.LIT if last else Style.CARD, 9, [10, 5, 10, 6] if inline else [12, 7, 12, 8])
|
|
sb.shadow_color = Color(0, 0, 0, 0.25)
|
|
sb.shadow_size = 1
|
|
sb.shadow_offset = Vector2(0, 3)
|
|
if last:
|
|
Style.bordered(sb, 2, Style.BRASS)
|
|
sb.set_expand_margin_all(2)
|
|
if inline:
|
|
sb.bg_color = sb.bg_color.darkened(0.04)
|
|
p.add_theme_stylebox_override("panel", sb)
|
|
p.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
p.mouse_filter = MOUSE_FILTER_PASS
|
|
var v := VBoxContainer.new()
|
|
v.add_theme_constant_override("separation", 1)
|
|
p.add_child(v)
|
|
var num: String = step["num"]
|
|
var caption := Formatter.strip_tags(str(step["table"]))
|
|
if num != "":
|
|
caption += " · rolled %s on %s" % [num, step.get("dice", "d%d" % int(step["die"]))]
|
|
if step.get("reshuffled", false):
|
|
caption += " · deck reshuffled"
|
|
if str(step.get("save_as", "")) != "":
|
|
caption += " · saved as {%s}" % step["save_as"]
|
|
var has_details := main.details().step_has_details(step)
|
|
if has_details:
|
|
caption += " " + RichText.INFO_MARK
|
|
var cap := Style.make_label(caption, Style.body(), 11 if inline else 12, Style.MUTED)
|
|
cap.mouse_filter = MOUSE_FILTER_IGNORE
|
|
v.add_child(cap)
|
|
var shown := RichText.decorate(str(step["text"]))
|
|
var body := RichText.display_label(shown, 16 if inline else 20, Style.DANGER_INK if step.get("stop", false) else Style.INK)
|
|
if Formatter.strip_tags(shown).length() > 56:
|
|
body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
body.custom_minimum_size = Vector2(420, 0)
|
|
RichText.hook_hover(body, main)
|
|
v.add_child(body)
|
|
if has_details:
|
|
p.mouse_entered.connect(func() -> void: main.details().show_step(p, step))
|
|
return p
|
|
|
|
|
|
func _link(inline: bool = false) -> Control:
|
|
var link := Panel.new()
|
|
var sb := Style.box(Style.BRASS)
|
|
sb.border_width_top = 2
|
|
sb.border_width_bottom = 2
|
|
sb.border_color = Style.BRASS_DARK
|
|
if inline:
|
|
sb = Style.box(Color(Style.BRASS, 0.55))
|
|
link.add_theme_stylebox_override("panel", sb)
|
|
link.custom_minimum_size = Vector2(16, 4) if inline else Vector2(22, 8)
|
|
link.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
link.mouse_filter = MOUSE_FILTER_IGNORE
|
|
return link
|
|
|
|
|
|
static func clock(unix: float) -> String:
|
|
var bias: int = Time.get_time_zone_from_system().get("bias", 0)
|
|
var d := Time.get_datetime_dict_from_unix_time(int(unix) + bias * 60)
|
|
return "%02d:%02d" % [d["hour"], d["minute"]]
|