TableTower/ui/table_card_kind_rows.gd
RobinFiredrake 82d67eb64f Size audit: split ChoiceDialog and TableCard into helpers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 19:56:20 -06:00

134 lines
5.8 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class_name TableCardKindRows
extends RefCounted
## The check-outlet and sheet rows of a TableCard (TableCardRows delegates here).
var rows: TableCardRows
var card: TableCard
func _init(p_rows: TableCardRows) -> void:
rows = p_rows
card = p_rows.card
## One outlet of a check card: "8+ Success · the bars give" / "≤7 Failure",
## with the outlet named in green or red. Build edits the text after the name.
func make_check_row(e: TableEntry, index: int, build: bool, numw: float) -> Control:
var table := card.table
var main := card.main
var row := PanelContainer.new()
row.mouse_filter = Control.MOUSE_FILTER_PASS
row.custom_minimum_size = Vector2(0, 36)
var h := TableCard.hbox(8)
row.add_child(h)
var outs := RulesView.check_outlets(table)
var num := Style.make_label(outs[index] if index < 2 else str(index + 1), Style.display(true), 16, Style.MUTED)
num.custom_minimum_size = Vector2(maxf(numw, 34.0), 0)
num.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
num.size_flags_vertical = Control.SIZE_SHRINK_CENTER
h.add_child(num)
var col := TableCard.vbox(2)
col.size_flags_horizontal = Control.SIZE_EXPAND_FILL
col.size_flags_vertical = Control.SIZE_SHRINK_CENTER
h.add_child(col)
var text: RichTextLabel = null
if build:
var line := TableCard.hbox(6)
col.add_child(line)
var nm := Style.make_label(TableCardText.check_outlet_name(index), Style.body_bold(true), 15, TableCardText.check_outlet_color(index))
nm.size_flags_vertical = Control.SIZE_SHRINK_CENTER
line.add_child(nm)
var edit := card.edit_ui.text_edit(e, index, false)
# The outlet name is already shown, so a result text that just repeats
# it ("Success") shows as an empty field with a hint instead.
if e.text.strip_edges() == TableCardText.check_outlet_name(index):
edit.text = ""
edit.placeholder_text = "What happens on a %s (optional)" % TableCardText.check_outlet_name(index).to_lower()
line.add_child(edit)
rows.add_rule_chips(col, e)
card.edit_ui.hook_select(row, e.id)
else:
text = RichText.label(rows.row_text(e), 16, Style.INK, true)
text.size_flags_horizontal = Control.SIZE_EXPAND_FILL
RichText.hook_hover(text, main)
col.add_child(text)
rows.add_rule_chips(col, e)
row.mouse_entered.connect(func() -> void: main.details().show_entry(row, table.id, e.id))
rows.register(e, row, num, text, index)
return row
## A sheet card's one row: the rendered template in Play, its editor in Build.
func make_sheet_row(e: TableEntry, build: bool) -> Control:
var main := card.main
var row := PanelContainer.new()
row.mouse_filter = Control.MOUSE_FILTER_PASS
row.custom_minimum_size = Vector2(0, 36)
var v := TableCard.vbox(6)
row.add_child(v)
if build:
var te := TextEdit.new()
te.text = e.text
te.placeholder_text = "[b]Name[/b] {@name}\nHP {@hp} · Skills {@skill_*}"
te.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY
te.custom_minimum_size = Vector2(0, 90)
te.scroll_fit_content_height = true
te.add_theme_font_override("font", Style.body(true))
te.add_theme_font_size_override("font_size", 14)
te.add_theme_color_override("font_color", Style.INK)
te.add_theme_color_override("font_placeholder_color", Style.MUTED)
te.add_theme_color_override("caret_color", Style.INK)
te.add_theme_color_override("selection_color", Color(Style.ACCENT, 0.55))
te.add_theme_stylebox_override("normal", Style.bordered(Style.box(Color.WHITE, 5, [7, 4, 7, 4]), 1, Style.RULE))
te.add_theme_stylebox_override("focus", Style.bordered(Style.box(Color.WHITE, 5, [7, 4, 7, 4]), 1, Style.TRIM))
te.tooltip_text = "The sheet's template: BBCode with {@var}, {@prefix_*} and {= expr}"
te.text_changed.connect(func() -> void:
e.text = te.text
e.page = ""
main.mark_dirty()
)
te.focus_entered.connect(func() -> void: card.select_entry(e.id))
v.add_child(te)
var tools := TableCard.vbox(2)
if e.effects.strip_edges() != "":
tools.add_child(effects_chip(e))
var pv := Style.make_label("Preview on the spread in Play", Style.body_italic(true), 12, Style.MUTED)
pv.size_flags_vertical = Control.SIZE_SHRINK_CENTER
tools.add_child(pv)
v.add_child(tools)
card.edit_ui.hook_select(row, e.id)
rows.sheet_label = null
else:
rows.sheet_label = RichText.label("", 15, Style.INK, true)
rows.sheet_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
RichText.hook_hover(rows.sheet_label, main)
v.add_child(rows.sheet_label)
row.mouse_entered.connect(func() -> void: main.details().show_entry(row, card.table.id, e.id))
rows.register(e, row, null, null, 0)
return row
## A subtle brass chip summarising an entry's effects: "Luck −1 · Gold + 2D"
## in plain words, "@luck -= 1 · @gold += 2d6" as text. Its tooltip has the
## other form, every statement on its own line.
func effects_chip(e: TableEntry) -> Control:
var plain := card.plain
var bad := not Effects.validate(TemplateKit.probe(e.effects)).is_empty()
var chip := PanelContainer.new()
chip.mouse_filter = Control.MOUSE_FILTER_PASS
chip.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
var bg := Color(Style.DANGER_INK, 0.1) if bad else Color(Style.ACCENT, 0.2)
var line := Color(Style.DANGER_INK, 0.4) if bad else Color(Style.ACCENT_DARK, 0.3)
chip.add_theme_stylebox_override("panel", Style.bordered(Style.box(bg, 5, [6, 0, 6, 1]), 1, line))
var summary := RulesView.effects_line(e.effects, card.main.data, card.table, plain)
# Cut long summaries by hand: a clipped Label would collapse to nothing.
summary = RulesView.cut(summary, TableCardRows.PLAIN_CHIP_CHARS if plain else TableCardRows.CHIP_CHARS)
var l := Style.make_label(summary, Style.body_bold(true) if plain else Style.body(true), 12, Style.DANGER_INK if bad else Style.TRIM_DARK)
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
chip.add_child(l)
chip.set_meta("effects_chip", summary)
if plain:
chip.tooltip_text = "\n".join(Effects.split(e.effects))
else:
chip.tooltip_text = "\n".join(Describe.effects(e.effects, card.main.data, card.table))
return chip