TableTower/ui/earlier_rolls.gd
RobinFiredrake ebe81d9f1e Theme system: runtime colour tokens, theme sets and a Theme dialog
Style's colours become static vars named by role (BG, PANEL, CARD, THREAD,
ACCENT, TRIM, GLOW…) instead of materials (felt, copper, brass), so a theme
can replace them. Stray hard-coded colours moved into tokens.

ThemeStore applies built-in sets (Tarot, the new default: jewel-purple
cloth with a shine; Felt, the old look) and the user's own sets from
user://themes/. Fills for the background and panels can be gradients; the
background pattern (dots, stars, none) and logo are per set. View ▾ →
Theme… edits a set; changes to a built-in save as a new set. Using a theme
reloads the UI and keeps the open spread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:10:16 -06:00

74 lines
2.5 KiB
GDScript

class_name EarlierRolls
extends VBoxContainer
## ResultTray's Earlier tab: one row per past roll, newest first, as
## "12:04 Root: a → b → c". The rows scroll inside the tray.
var main: Main
var scroll: ScrollContainer
var _rows: VBoxContainer
var _empty: Label
func setup(p_main: Main) -> void:
main = p_main
add_theme_constant_override("separation", 6)
size_flags_vertical = SIZE_EXPAND_FILL
scroll = ScrollContainer.new()
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
scroll.size_flags_vertical = SIZE_EXPAND_FILL
add_child(scroll)
_rows = VBoxContainer.new()
_rows.add_theme_constant_override("separation", 6)
_rows.size_flags_horizontal = SIZE_EXPAND_FILL
scroll.add_child(_rows)
_empty = Style.make_label("Older rolls show here.", Style.body(), 15, Style.ON_BG_MUTED)
add_child(_empty)
func render() -> void:
for c in _rows.get_children():
_rows.remove_child(c)
c.queue_free()
_empty.visible = main.history.is_empty()
scroll.visible = not _empty.visible
scroll.scroll_vertical = 0
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_BG_MUTED)
time.custom_minimum_size = Vector2(44, 0)
time.size_flags_vertical = SIZE_SHRINK_BEGIN
row.add_child(time)
var line := RichText.label(earlier_line(rec), 14, Style.ON_BG, false)
line.size_flags_horizontal = SIZE_EXPAND_FILL
RichText.hook_hover(line, main)
row.add_child(line)
_rows.add_child(row)
## One Earlier row: "Root: a → b → c", with only the last few steps of a long
## chain.
static func earlier_line(rec: Dictionary) -> String:
var texts := PackedStringArray()
var all: Array = rec.get("steps", [])
var shown := 0
var skipped := 0
for k in range(all.size() - 1, -1, -1):
var s: Dictionary = all[k]
if s.get("inline", false):
continue
if shown >= 6:
skipped += 1
continue
texts.insert(0, RichText.decorate(TrayText.one_line(str(s["text"])), true))
shown += 1
var lead := "[color=#%s]%s:[/color] " % [Style.ON_BG_MUTED.to_html(false), RichText.plain(Formatter.strip_tags(str(rec.get("root_name", ""))))]
if skipped > 0:
lead += "[color=#%s]… %d earlier →[/color] " % [Style.ON_BG_MUTED.to_html(false), skipped]
return lead + " → ".join(texts)
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"]]