145 lines
5.7 KiB
GDScript
145 lines
5.7 KiB
GDScript
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).
|
|
static func cost_row(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
|
|
var row := InspectorKit.flow()
|
|
var amount := InspectorKit.amount(e.cost_amount, "0")
|
|
amount.tooltip_text = "How much picking this takes away (0 or empty: free)"
|
|
row.add_child(amount)
|
|
row.add_child(InspectorKit.word("of"))
|
|
var picker := ValuePicker.new(insp.main, e.cost_value.trim_prefix("@"))
|
|
row.add_child(picker)
|
|
var apply := func() -> void:
|
|
var a := amount.text.strip_edges()
|
|
e.cost_amount = "" if a == "" or a == "0" else a
|
|
if e.cost_amount == "":
|
|
e.cost_value = ""
|
|
insp.wrote(t)
|
|
amount.text_changed.connect(func(_s: String) -> void: apply.call())
|
|
picker.value_chosen.connect(func(n: String) -> void:
|
|
e.cost_value = "@" + n.trim_prefix("@")
|
|
if amount.text.strip_edges() == "":
|
|
amount.text = "1"
|
|
apply.call())
|
|
row.add_child(InspectorKit.note("Greyed out in the pop-up when there isn't enough.", Style.MUTED, 12))
|
|
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
|
|
insp._content.add_child(InspectorKit.field("Text", le))
|
|
|
|
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))
|
|
|
|
if t.kind == RollTable.KIND_CHOICE and t.choice == "pick" and not (t.is_dynamic() and t.entries.find(e) == 0):
|
|
insp.show_if_builder = ConditionBuilder.new()
|
|
insp.show_if_builder.setup(insp.main, e.show_if, not plain, "res.show_if", {"empty_note": "Always offered."})
|
|
insp.show_if_builder.changed.connect(insp.set_entry_show_if)
|
|
insp._content.add_child(InspectorKit.field("Offer only if", insp.show_if_builder))
|
|
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()
|
|
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)
|