2026-11-10 19:51:10 -06:00
|
|
|
class_name InspectorResult
|
|
|
|
|
extends RefCounted
|
|
|
|
|
## The Inspector's "Selected result" section: text, details, picture, Book link,
|
|
|
|
|
## costs, effects and the threads leaving it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## A link back to the card the result or pipe belongs to.
|
|
|
|
|
## "From the Book page X · unlink" for a linked result, else "Save to the Book".
|
|
|
|
|
static func book_line(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
|
|
|
|
|
var p := insp.main.data.get_page(e.page)
|
|
|
|
|
if p == null:
|
|
|
|
|
var save := InspectorKit.link("Save to the Book", "Keep this result as a Page to reuse on other tables")
|
|
|
|
|
save.pressed.connect(func() -> void: insp.main.book.save_result(t, e))
|
|
|
|
|
return save
|
|
|
|
|
var row := InspectorKit.hbox(8)
|
|
|
|
|
var open := InspectorKit.link("§ From the Book: %s" % p.label(), "Edit the page; every result using it changes")
|
|
|
|
|
open.pressed.connect(func() -> void:
|
|
|
|
|
insp.main.book.set_shown(true)
|
|
|
|
|
insp.main.book.refresh()
|
|
|
|
|
insp.main.book.select_page(p.id))
|
|
|
|
|
row.add_child(open)
|
|
|
|
|
var unlink := InspectorKit.link("Unlink", "Keep the text here but stop following the page")
|
|
|
|
|
unlink.pressed.connect(func() -> void:
|
|
|
|
|
e.page = ""
|
|
|
|
|
insp.wrote(t, false, true))
|
|
|
|
|
row.add_child(unlink)
|
|
|
|
|
return row
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## "[1] of [Points ▾]": what picking this option costs (RollCosts).
|
2026-11-14 14:23:07 -06:00
|
|
|
## "Costs [1] of [value]": for a choice option (`holder` a TableEntry) or a
|
|
|
|
|
## whole card (`holder` the RollTable). `note` sits under it.
|
|
|
|
|
static func cost_row(insp: Inspector, t: RollTable, holder: Object, note: String = "Greyed out in the pop-up when there isn't enough.") -> Control:
|
2026-11-10 19:51:10 -06:00
|
|
|
var row := InspectorKit.flow()
|
2026-11-14 14:23:07 -06:00
|
|
|
var amount := InspectorKit.amount(str(holder.get("cost_amount")), "0")
|
|
|
|
|
amount.tooltip_text = "How much it takes away (0 or empty: free)"
|
2026-11-10 19:51:10 -06:00
|
|
|
row.add_child(amount)
|
|
|
|
|
row.add_child(InspectorKit.word("of"))
|
2026-11-14 14:23:07 -06:00
|
|
|
var picker := ValuePicker.new(insp.main, str(holder.get("cost_value")).trim_prefix("@"))
|
2026-11-10 19:51:10 -06:00
|
|
|
row.add_child(picker)
|
|
|
|
|
var apply := func() -> void:
|
2026-11-14 14:23:07 -06:00
|
|
|
var typed := amount.text.strip_edges()
|
|
|
|
|
holder.set("cost_amount", "" if typed == "" or typed == "0" else typed)
|
|
|
|
|
if str(holder.get("cost_amount")) == "":
|
|
|
|
|
holder.set("cost_value", "")
|
2026-11-10 19:51:10 -06:00
|
|
|
insp.wrote(t)
|
|
|
|
|
amount.text_changed.connect(func(_s: String) -> void: apply.call())
|
|
|
|
|
picker.value_chosen.connect(func(n: String) -> void:
|
2026-11-14 14:23:07 -06:00
|
|
|
holder.set("cost_value", "@" + n.trim_prefix("@"))
|
2026-11-10 19:51:10 -06:00
|
|
|
if amount.text.strip_edges() == "":
|
|
|
|
|
amount.text = "1"
|
|
|
|
|
apply.call())
|
2026-11-14 14:23:07 -06:00
|
|
|
row.add_child(InspectorKit.note(note, Style.MUTED, 12))
|
2026-11-10 19:51:10 -06:00
|
|
|
return row
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func card_link(insp: Inspector, t: RollTable) -> Button:
|
|
|
|
|
var b := InspectorKit.link("On %s · edit the card" % Inspector._title_of(t.name, "this card"), "Show the card's settings")
|
|
|
|
|
b.add_theme_color_override("font_color", Style.MUTED)
|
|
|
|
|
b.pressed.connect(func() -> void: insp.select({"kind": "card", "tid": t.id}))
|
|
|
|
|
return b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func section(insp: Inspector, t: RollTable, e: TableEntry) -> void:
|
|
|
|
|
insp._content.add_child(insp._head("Selected result", Inspector._title_of(e.text, "(no text)")))
|
|
|
|
|
insp._content.add_child(card_link(insp, t))
|
|
|
|
|
var plain := insp.main.rules_plain()
|
|
|
|
|
|
|
|
|
|
if t.kind != RollTable.KIND_SHEET:
|
|
|
|
|
var le := InspectorKit.line(e.text, "What this result says")
|
|
|
|
|
InspectorKit.tag(le, "res.text")
|
|
|
|
|
le.text_changed.connect(insp.set_entry_text)
|
|
|
|
|
insp.fields["text"] = le
|
UI for cards with columns: header and cells, inspector Columns section, help
- TableCardColumns: the column-name header, each row's cells after its text
(Play: wrapping text; Build: a field per cell, edited inline), cards widen
per column, and in "each" mode the cell each column landed on is lit
(Main.lit_columns, from the rolled node's columns).
- InspectorColumns: Add columns, add/rename/move/remove (cells kept in step),
one roll vs each column, Save as (value picker) and Only if (condition
builder); the result inspector gets a field per extra column.
- Help: a Columns topic after Ranged tables and dice.
- tests/test_ui_columns.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:24:35 -06:00
|
|
|
insp._content.add_child(InspectorKit.field(Inspector._title_of(str(t.columns[0].get("name", "")), "Text") if t.has_columns() else "Text", le))
|
|
|
|
|
InspectorColumns.result_cells(insp, t, e)
|
2026-11-10 19:51:10 -06:00
|
|
|
|
|
|
|
|
var det := InspectorKit.text_box(e.details, "Shown on hover (optional)", 36.0)
|
|
|
|
|
InspectorKit.tag(det, "res.details")
|
|
|
|
|
det.text_changed.connect(func() -> void: insp.set_entry_details(det.text))
|
|
|
|
|
insp.fields["details"] = det
|
|
|
|
|
insp._content.add_child(InspectorKit.field("Details", det))
|
|
|
|
|
insp._content.add_child(InspectorKit.field("Picture", ImageField.new(insp.main, e.image, func(id: String) -> void:
|
|
|
|
|
e.image = id
|
|
|
|
|
e.page = ""
|
|
|
|
|
insp.wrote(t))))
|
|
|
|
|
insp._content.add_child(book_line(insp, t, e))
|
|
|
|
|
|
2026-11-14 14:02:29 -06:00
|
|
|
var pick := t.kind == RollTable.KIND_CHOICE and t.choice == "pick"
|
|
|
|
|
if (pick and not (t.is_dynamic() and t.entries.find(e) == 0)) or t.kind == RollTable.KIND_ROLL:
|
2026-11-10 19:51:10 -06:00
|
|
|
insp.show_if_builder = ConditionBuilder.new()
|
2026-11-14 14:02:29 -06:00
|
|
|
insp.show_if_builder.setup(insp.main, e.show_if, not plain, "res.show_if",
|
|
|
|
|
{"empty_note": "Always offered." if pick else "Can always come up."})
|
2026-11-10 19:51:10 -06:00
|
|
|
insp.show_if_builder.changed.connect(insp.set_entry_show_if)
|
2026-11-14 14:02:29 -06:00
|
|
|
insp._content.add_child(InspectorKit.field("Offer only if" if pick else "Can come up only if", insp.show_if_builder))
|
|
|
|
|
if pick and not (t.is_dynamic() and t.entries.find(e) == 0):
|
2026-11-10 19:51:10 -06:00
|
|
|
insp._content.add_child(InspectorKit.field("Costs", cost_row(insp, t, e)))
|
|
|
|
|
|
|
|
|
|
if t.kind == RollTable.KIND_ROUTER:
|
|
|
|
|
insp._content.add_child(InspectorCard.case_block(insp, t, e))
|
|
|
|
|
|
|
|
|
|
insp.effects = EffectsBuilder.new()
|
2026-11-14 13:40:20 -06:00
|
|
|
insp.effects.item_hint = Formatter.strip_tags(e.text).strip_edges()
|
2026-11-10 19:51:10 -06:00
|
|
|
insp.effects.setup(insp.main, e.effects, t, not plain, "res.fx")
|
|
|
|
|
insp.effects.changed.connect(insp.set_entry_effects)
|
|
|
|
|
insp._content.add_child(InspectorKit.field("When this comes up", insp.effects))
|
|
|
|
|
|
|
|
|
|
var go := InspectorKit.vbox(8)
|
|
|
|
|
if e.pipes.is_empty():
|
|
|
|
|
go.add_child(InspectorKit.note("No threads yet. Drag from the ● at the end of this result to a card.", Style.MUTED, 14))
|
|
|
|
|
for p in e.pipes:
|
|
|
|
|
go.add_child(InspectorThread.box(insp, t, e, p))
|
|
|
|
|
insp._content.add_child(InspectorKit.field("Then go to", go))
|
|
|
|
|
InspectorThread.lint_lines(insp, t, e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func set_entry_text(insp: Inspector, s: String) -> void:
|
|
|
|
|
var e := insp.selected_entry()
|
|
|
|
|
if e and e.text != s:
|
|
|
|
|
e.text = s
|
|
|
|
|
e.page = ""
|
|
|
|
|
insp.wrote(insp.selected_table())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func set_entry_details(insp: Inspector, s: String) -> void:
|
|
|
|
|
var e := insp.selected_entry()
|
|
|
|
|
if e and e.details != s:
|
|
|
|
|
e.details = s
|
|
|
|
|
e.page = ""
|
|
|
|
|
insp.wrote(insp.selected_table())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func set_entry_effects(insp: Inspector, s: String) -> void:
|
|
|
|
|
var e := insp.selected_entry()
|
|
|
|
|
if e and e.effects != s:
|
|
|
|
|
e.effects = s
|
|
|
|
|
insp.wrote(insp.selected_table())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func set_entry_show_if(insp: Inspector, s: String) -> void:
|
|
|
|
|
var e := insp.selected_entry()
|
|
|
|
|
if e and e.show_if != s.strip_edges() and TableSettingsDialog.when_error(s) == "":
|
|
|
|
|
e.show_if = s.strip_edges()
|
|
|
|
|
insp.wrote(insp.selected_table())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## A router case's condition ("" makes it the Otherwise case).
|
|
|
|
|
static func set_case_when(insp: Inspector, eid: String, s: String) -> void:
|
|
|
|
|
var t := insp.selected_table()
|
|
|
|
|
var e := t.find_entry(eid) if t else null
|
|
|
|
|
if e and e.when != s.strip_edges() and TableSettingsDialog.when_error(s) == "":
|
|
|
|
|
e.when = s.strip_edges()
|
|
|
|
|
insp.wrote(t)
|