Batches saved to the history file but never reached the tray's Earlier list, and played no sound. Now each roll shows there as "Name (2 of 5)" and the batch plays one roll sound. Earlier keeps 30 rolls (was 6) and the saved history 200 (was 50). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
3.2 KiB
GDScript
98 lines
3.2 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
|
|
## The rows built so far: [record, row], so a render only builds rows for new
|
|
## rolls (long results make each row slow to build).
|
|
var _built: Array = []
|
|
|
|
|
|
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:
|
|
var kept: Array = []
|
|
for rec in main.history:
|
|
var row: Control = null
|
|
for pair: Array in _built:
|
|
if is_same(pair[0], rec):
|
|
row = pair[1]
|
|
break
|
|
if row == null:
|
|
row = _make_row(rec)
|
|
_rows.add_child(row)
|
|
kept.append([rec, row])
|
|
for pair: Array in _built:
|
|
if not kept.any(func(other: Array) -> bool: return is_same(other[1], pair[1])):
|
|
_rows.remove_child(pair[1])
|
|
(pair[1] as Node).queue_free()
|
|
for i in kept.size():
|
|
if (kept[i][1] as Node).get_index() != i:
|
|
_rows.move_child(kept[i][1], i)
|
|
_built = kept
|
|
_empty.visible = main.history.is_empty()
|
|
scroll.visible = not _empty.visible
|
|
scroll.scroll_vertical = 0
|
|
|
|
|
|
func _make_row(rec: Dictionary) -> HBoxContainer:
|
|
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)
|
|
return 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 root := RichText.plain(Formatter.strip_tags(str(rec.get("root_name", ""))))
|
|
if str(rec.get("batch", "")) != "":
|
|
root += " (%s)" % rec["batch"]
|
|
var lead := "[color=#%s]%s:[/color] " % [Style.ON_BG_MUTED.to_html(false), root]
|
|
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"]]
|