From 14a0b6e6a4a37edcdbc535c7130aacb5666494a0 Mon Sep 17 00:00:00 2001 From: RobinFiredrake Date: Sun, 8 Nov 2026 17:11:19 -0600 Subject: [PATCH] Keep long sheets from widening the tray; show sheets filled in in previews The tray's sheet headline now wraps at a fixed width and scrolls past 220 px, so a long character sheet can't stretch the window (which also threw off Fit on big boards). Option previews in the choice pop-up show a sheet card rendered with current values instead of its raw template and a meaningless 100%. Co-Authored-By: Claude Opus 5.5 --- ui/choice_dialog.gd | 7 +++++-- ui/result_tray.gd | 22 ++++++++++++++++++++-- ui/table_preview.gd | 7 +++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/ui/choice_dialog.gd b/ui/choice_dialog.gd index 873ecf6..00fb235 100644 --- a/ui/choice_dialog.gd +++ b/ui/choice_dialog.gd @@ -44,6 +44,8 @@ const PREVIEW_WIDTH := 350.0 ## The board the question belongs to, for previews. Found from the parent Main ## when not set; without one the dialog simply shows no preview. var board: TowerBoard +## Board variables, so previews can show sheets filled in. +var vars: Dictionary = {} var minimized := false var preview_panel: PanelContainer var pill: PanelContainer @@ -222,6 +224,7 @@ func _ready() -> void: var m := get_parent() as Main if m: board = m.data + vars = m.persistent_vars _refresh_preview() if _spin: _spin.get_line_edit().grab_focus() @@ -574,7 +577,7 @@ func preview_for_option(k: int) -> Control: shown.append(tid) any = true box.add_child(_rule()) - box.add_child(TablePreview.build(board, tid, {"count": e.count_text(tid)})) + box.add_child(TablePreview.build(board, tid, {"count": e.count_text(tid), "vars": vars})) var mentioned: Array[String] = [] for name in TextExpander.references(e.text, func(n: String) -> String: return Roller.resolve(board, n)): var rid := Roller.resolve(board, name) @@ -585,7 +588,7 @@ func preview_for_option(k: int) -> Control: box.add_child(_rule()) box.add_child(section("Mentioned in the text")) for rid in mentioned: - box.add_child(TablePreview.build(board, rid)) + box.add_child(TablePreview.build(board, rid, {"vars": vars})) if not any: box.free() return null diff --git a/ui/result_tray.gd b/ui/result_tray.gd index b39332a..b9f6422 100644 --- a/ui/result_tray.gd +++ b/ui/result_tray.gd @@ -31,6 +31,9 @@ var _halt_label: Label var _headline: PanelContainer var _headline_cap: Label var _headline_text: RichTextLabel +var _headline_scroll: ScrollContainer +const HEADLINE_W := 420.0 +const HEADLINE_MAX_H := 220.0 ## True when "+N earlier steps" has been opened for the current roll. var expanded := false var _scroll_to_end := false @@ -94,9 +97,16 @@ func setup(p_main: Main) -> void: _headline.add_child(hv) _headline_cap = Style.make_label("", Style.body(), 12, Style.MUTED) hv.add_child(_headline_cap) - _headline_text = RichText.label("", 17, Style.INK, false, false) + # A sheet wraps at a fixed width and scrolls past HEADLINE_MAX_H, so a long + # sheet can't widen the window or take over the tray. + _headline_text = RichText.label("", 17, Style.INK, false, true) + _headline_text.custom_minimum_size = Vector2(HEADLINE_W, 0) RichText.hook_hover(_headline_text, main) - hv.add_child(_headline_text) + _headline_scroll = ScrollContainer.new() + _headline_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED + _headline_scroll.custom_minimum_size = Vector2(HEADLINE_W + 12, 0) + _headline_scroll.add_child(_headline_text) + hv.add_child(_headline_scroll) _headline.hide() _headline.size_flags_vertical = SIZE_SHRINK_BEGIN # The headline sits left of the chips, so a sheet doesn't make the tray taller. @@ -328,6 +338,7 @@ func _render_status(current: Dictionary, steps: Array) -> void: if not sheet.is_empty(): _headline_cap.text = Formatter.strip_tags(str(sheet.get("table", ""))).to_upper() _headline_text.text = RichText.decorate(str(sheet.get("text", ""))) + _fit_headline() ## The last sheet step of a chain (the headline), or {}. @@ -530,3 +541,10 @@ 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"]] + + +## Sizes the sheet headline's scroll area to its text, up to HEADLINE_MAX_H. +func _fit_headline() -> void: + await get_tree().process_frame + if is_instance_valid(_headline_text): + _headline_scroll.custom_minimum_size.y = minf(_headline_text.get_content_height(), HEADLINE_MAX_H) diff --git a/ui/table_preview.gd b/ui/table_preview.gd index e1183cd..ca7ab42 100644 --- a/ui/table_preview.gd +++ b/ui/table_preview.gd @@ -58,6 +58,13 @@ static func build(board: TowerBoard, table_id: String, opts: Dictionary = {}) -> var list := VBoxContainer.new() list.add_theme_constant_override("separation", 2) list.mouse_filter = Control.MOUSE_FILTER_IGNORE + if t.kind == RollTable.KIND_SHEET: + # A sheet's "entry" is its template: show it filled in, not as a result row. + var vars: Dictionary = opts.get("vars", {}) + var sheet := RichText.label(RichText.decorate(Roller.render_sheet(board, vars, t)), 13, Style.INK, false) + sheet.mouse_filter = Control.MOUSE_FILTER_IGNORE + box.add_child(sheet) + return box if t.kind != RollTable.KIND_VARIABLE: for i in t.entries.size(): if shown >= cap: