TableTower/ui/earlier_rolls.gd

66 lines
2.1 KiB
GDScript3
Raw Normal View History

class_name EarlierRolls
extends VBoxContainer
## ResultTray's Earlier tab: one row per past roll, newest first, as
## "12:04 Root: a → b → c".
var main: Main
var _rows: VBoxContainer
var _empty: Label
func setup(p_main: Main) -> void:
main = p_main
add_theme_constant_override("separation", 6)
_rows = VBoxContainer.new()
_rows.add_theme_constant_override("separation", 6)
add_child(_rows)
_empty = Style.make_label("Older rolls show here.", Style.body(), 15, Style.ON_FELT_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()
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 line := RichText.label(earlier_line(rec), 14, Style.ON_FELT, 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_FELT_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_FELT_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"]]