2026-11-08 12:23:21 -06:00
|
|
|
class_name TableSettingsDialog
|
|
|
|
|
extends ModalCard
|
|
|
|
|
## Build-mode editor for one table's name, details, tags, type and card mode.
|
2026-11-09 08:06:56 -06:00
|
|
|
## The editing rules live in TableSettingsRules (static, tested without a
|
|
|
|
|
## window); the kind-specific fields in SettingsKindFields.
|
2026-11-08 12:23:21 -06:00
|
|
|
|
|
|
|
|
signal applied(settings: Dictionary)
|
Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
|
|
|
## The footer's "Save as template…" (the dialog closes first; Main opens the save dialog).
|
|
|
|
|
signal template_requested
|
2026-11-08 12:23:21 -06:00
|
|
|
|
|
|
|
|
const COLORS := [
|
|
|
|
|
["Red", Color("#a33a2c")],
|
|
|
|
|
["Copper", Color("#b8703a")],
|
|
|
|
|
["Green", Color("#2f6b4f")],
|
|
|
|
|
["Blue", Color("#2f5d8a")],
|
|
|
|
|
["Purple", Color("#6b3f8a")],
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
var table: RollTable
|
|
|
|
|
|
|
|
|
|
var _name: LineEdit
|
|
|
|
|
var _details: TextEdit
|
|
|
|
|
var _preview: RichTextLabel
|
|
|
|
|
var _tags: LineEdit
|
|
|
|
|
var _dice: LineEdit
|
|
|
|
|
var _dice_row: Control
|
|
|
|
|
var _type_note: Label
|
|
|
|
|
var _problem: Label
|
|
|
|
|
var _deck_block: Control
|
|
|
|
|
var _ranged := false
|
|
|
|
|
var _card_mode := false
|
|
|
|
|
var _deck_empty := "reshuffle"
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
var _type_box: Control
|
|
|
|
|
var _card_box: Control
|
2026-11-09 08:06:56 -06:00
|
|
|
var _kind: SettingsKindFields
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
|
|
|
|
|
const TITLES := {
|
|
|
|
|
RollTable.KIND_ROLL: "Table settings",
|
|
|
|
|
RollTable.KIND_CHOICE: "Choice settings",
|
|
|
|
|
RollTable.KIND_LOOP: "Loop settings",
|
|
|
|
|
RollTable.KIND_VARIABLE: "Variable settings",
|
|
|
|
|
RollTable.KIND_SHEET: "Sheet settings",
|
Conditional pipes and router cards
Pipes can carry "when" (Only if) and "otherwise". When an entry is
chosen, its effects run, its text expands, then every pipe condition and
count is evaluated once as a snapshot before any pipe runs; when pipes
run if true, otherwise pipes if no when pipe was true, plain pipes
always. Condition errors count as false and show as error lines.
New router card (kind "router"): its entries are cases with an
entry-level "when"; the first true case is chosen (empty = Otherwise),
and "No case matched" stops the node. One action. JSON round trip for
entry/pipe when and pipe otherwise, including JsonIO.canonical and
edge labels. Roller.lint_pipes() and Roller.lint_router() for board
checks. A pick choice's save_as is now stored before the snapshot.
UI: Only if / Otherwise in the pipe popover with live validation, pipe
labels ("if @str >= 8", "otherwise") and a source-end diamond on
conditional pipes, router card with fork icon, per-case condition rows,
case editing / reordering in Build, router settings, "+ Table" entry,
router cases in table previews. Logic demo now routes through a router.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:53:00 -06:00
|
|
|
RollTable.KIND_ROUTER: "Router settings",
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
}
|
|
|
|
|
const CHOICE_LABELS := ["Which option", "How many", "Open ended"]
|
Dynamic pick options, show_if and indirect @[expr] names
Pick choice cards can take their options from variables (options_from:
@prefix_* or a @list, filtered by options_where with option, option_label
and option_value bound). A Chosen entry runs for whichever dynamic option
is picked; fixed entries stay as extras, listed first. Random weighs each
dynamic option as the Chosen entry and fixed ones by weight. Any pick
option can have show_if, which hides it from the pop-up and from Random;
with nothing offered the node stops with "No options available".
@[expr] reads or writes the variable named by expr in expressions,
effects (including reset) and text ({@[expr]}); bad computed names are
effect errors. JSON round trip, lint_options in lint_pipes, choice
pop-up value badges and previews, card and settings UI, docs, demo board
(Spend a find) and tests/test_options.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 18:55:38 -06:00
|
|
|
const OPTION_LABELS := ["Fixed list", "From variables (+ fixed extras)"]
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
const LOOP_LABELS := ["Times", "While", "Until"]
|
|
|
|
|
const LOOP_NOTES := {
|
|
|
|
|
"times": "Runs Each time this many times (worked out once), then Afterwards. e.g. 3, @answer, 1d3",
|
|
|
|
|
"while": "Checks the condition before each pass and stops when it's false. e.g. @hp > 0",
|
|
|
|
|
"until": "Runs a pass, then stops once the condition is true (at least one pass). e.g. @gold >= 100",
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-08 12:23:21 -06:00
|
|
|
|
|
|
|
|
func _init(p_table: RollTable = null) -> void:
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
super._init(TITLES.get(p_table.kind, "Table settings") if p_table else "Table settings", 560.0)
|
2026-11-08 12:23:21 -06:00
|
|
|
table = p_table
|
|
|
|
|
_ranged = table.is_ranged()
|
|
|
|
|
_card_mode = table.card_mode
|
|
|
|
|
_deck_empty = table.deck_empty
|
2026-11-09 08:06:56 -06:00
|
|
|
_kind = SettingsKindFields.new(self)
|
2026-11-08 12:23:21 -06:00
|
|
|
_build()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _build() -> void:
|
|
|
|
|
_name = LineEdit.new()
|
|
|
|
|
_name.text = table.name
|
|
|
|
|
_name.placeholder_text = "Table name"
|
|
|
|
|
style_line_edit(_name)
|
|
|
|
|
_name.text_changed.connect(func(_t: String) -> void: _refresh())
|
|
|
|
|
body.add_child(field("Name", _name))
|
2026-11-09 08:06:56 -06:00
|
|
|
_kind.build()
|
2026-11-08 12:23:21 -06:00
|
|
|
|
|
|
|
|
_details = TextEdit.new()
|
|
|
|
|
_details.text = table.details
|
|
|
|
|
_details.placeholder_text = "What this table is for. BBCode is allowed."
|
|
|
|
|
_details.custom_minimum_size.y = 84
|
|
|
|
|
_details.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY
|
|
|
|
|
style_text_edit(_details)
|
|
|
|
|
_details.text_changed.connect(_refresh)
|
|
|
|
|
var tools := HBoxContainer.new()
|
|
|
|
|
tools.add_theme_constant_override("separation", 6)
|
|
|
|
|
tools.add_child(_tool_button("B", "Bold", func() -> void: _wrap_selection("[b]", "[/b]")))
|
|
|
|
|
tools.add_child(_tool_button("I", "Italic", func() -> void: _wrap_selection("[i]", "[/i]")))
|
|
|
|
|
var color := make_button("Color ▾", "plain")
|
|
|
|
|
color.pressed.connect(func() -> void: _color_menu(color))
|
|
|
|
|
color.add_theme_font_size_override("font_size", 14)
|
|
|
|
|
tools.add_child(color)
|
|
|
|
|
var dbox := VBoxContainer.new()
|
|
|
|
|
dbox.add_theme_constant_override("separation", 6)
|
|
|
|
|
dbox.add_child(section("Details"))
|
|
|
|
|
dbox.add_child(tools)
|
|
|
|
|
dbox.add_child(_details)
|
|
|
|
|
_preview = RichTextLabel.new()
|
|
|
|
|
_preview.bbcode_enabled = true
|
|
|
|
|
_preview.fit_content = true
|
|
|
|
|
_preview.scroll_active = false
|
|
|
|
|
_preview.custom_minimum_size.y = 24
|
|
|
|
|
var pbox := PanelContainer.new()
|
|
|
|
|
pbox.add_theme_stylebox_override("panel", Style.box(Color(0, 0, 0, 0.05), 7, [10, 7, 10, 7]))
|
|
|
|
|
pbox.add_child(_preview)
|
|
|
|
|
dbox.add_child(pbox)
|
|
|
|
|
body.add_child(dbox)
|
|
|
|
|
|
|
|
|
|
_tags = LineEdit.new()
|
|
|
|
|
_tags.text = ", ".join(table.tags)
|
|
|
|
|
_tags.placeholder_text = "loot, treasure, magic"
|
|
|
|
|
style_line_edit(_tags)
|
|
|
|
|
body.add_child(field("Tags (comma-separated)", _tags))
|
|
|
|
|
|
|
|
|
|
var type_box := VBoxContainer.new()
|
|
|
|
|
type_box.add_theme_constant_override("separation", 6)
|
|
|
|
|
type_box.add_child(section("Table type"))
|
|
|
|
|
type_box.add_child(segmented(["Plain", "Ranged (dice)"], 1 if _ranged else 0, func(i: int) -> void:
|
|
|
|
|
_ranged = i == 1
|
|
|
|
|
_refresh()
|
|
|
|
|
))
|
|
|
|
|
_dice = LineEdit.new()
|
|
|
|
|
_dice.text = table.dice
|
|
|
|
|
_dice.placeholder_text = "1d100"
|
|
|
|
|
_dice.custom_minimum_size.x = 140
|
|
|
|
|
style_line_edit(_dice)
|
|
|
|
|
_dice.size_flags_horizontal = SIZE_SHRINK_BEGIN
|
|
|
|
|
_dice.text_changed.connect(func(_t: String) -> void: _refresh())
|
|
|
|
|
var drow := HBoxContainer.new()
|
|
|
|
|
drow.add_theme_constant_override("separation", 10)
|
|
|
|
|
var dl := Style.make_label("Dice", Style.body(), 15, Style.INK)
|
|
|
|
|
dl.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
|
|
|
drow.add_child(dl)
|
|
|
|
|
drow.add_child(_dice)
|
|
|
|
|
var eg := note("e.g. 1d100, 2d6, 1d8+2")
|
|
|
|
|
eg.size_flags_vertical = SIZE_SHRINK_CENTER
|
|
|
|
|
drow.add_child(eg)
|
|
|
|
|
_dice_row = drow
|
|
|
|
|
type_box.add_child(drow)
|
|
|
|
|
_type_note = note("")
|
|
|
|
|
type_box.add_child(_type_note)
|
|
|
|
|
_problem = note("", Style.WARN_INK)
|
|
|
|
|
type_box.add_child(_problem)
|
|
|
|
|
body.add_child(type_box)
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
_type_box = type_box
|
2026-11-08 12:23:21 -06:00
|
|
|
|
|
|
|
|
var card_box := VBoxContainer.new()
|
|
|
|
|
card_box.add_theme_constant_override("separation", 6)
|
|
|
|
|
card_box.add_child(section("Card mode"))
|
|
|
|
|
card_box.add_child(segmented(["Off", "On"], 1 if _card_mode else 0, func(i: int) -> void:
|
|
|
|
|
_card_mode = i == 1
|
|
|
|
|
_refresh()
|
|
|
|
|
))
|
|
|
|
|
card_box.add_child(note("Entries are dealt like cards, without repeats, until the deck runs out."))
|
|
|
|
|
var deck := VBoxContainer.new()
|
|
|
|
|
deck.add_theme_constant_override("separation", 6)
|
|
|
|
|
deck.add_child(section("When the deck runs out"))
|
|
|
|
|
deck.add_child(segmented(["Reshuffle", "Stop"], 1 if _deck_empty == "stop" else 0, func(i: int) -> void:
|
|
|
|
|
_deck_empty = "stop" if i == 1 else "reshuffle"
|
|
|
|
|
_refresh()
|
|
|
|
|
))
|
|
|
|
|
_deck_block = deck
|
|
|
|
|
card_box.add_child(deck)
|
|
|
|
|
body.add_child(card_box)
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
_card_box = card_box
|
2026-11-08 12:23:21 -06:00
|
|
|
|
Group cards and templates
Groups: an optional groups list on a collection (frame rect, collapsed,
members, details), saved by TowerBoard and kept by JsonIO. Expanded groups
draw a frame behind their cards with a title bar; collapsed ones become one
compact card that lists the members' lit results, with pipes re-routed to
its inlet and right edge. Build mode adds multi-select (Ctrl/Shift-click,
Ctrl-drag), Group (Ctrl+G), drop in/out of frames, rename, ungroup, delete
with undo and a details editor.
Templates: TemplateKit saves cards, groups or selections with relative
positions, internal pipes and outside pipes by name, detects {$name}
parameters and inserts with fresh ids. TemplateLibrary keeps user templates
in user://templates and lists the built-in ones in templates/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 17:01:34 -06:00
|
|
|
var tpl := add_button("Save as template…", "plain", func() -> void:
|
|
|
|
|
close()
|
|
|
|
|
template_requested.emit()
|
|
|
|
|
)
|
|
|
|
|
tpl.tooltip_text = "Save this card as a reusable template ({$name} in any text becomes a parameter)"
|
|
|
|
|
var gap := Control.new()
|
|
|
|
|
gap.size_flags_horizontal = SIZE_EXPAND_FILL
|
|
|
|
|
footer.add_child(gap)
|
2026-11-08 12:23:21 -06:00
|
|
|
add_button("Close", "plain", close)
|
|
|
|
|
add_button("Apply", "primary", _on_apply)
|
|
|
|
|
_refresh()
|
|
|
|
|
|
|
|
|
|
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
func _ready() -> void:
|
|
|
|
|
super._ready()
|
|
|
|
|
# Now that the dialog sits in Main, the sheet preview can use its variables.
|
|
|
|
|
_refresh()
|
|
|
|
|
|
|
|
|
|
|
2026-11-08 12:23:21 -06:00
|
|
|
func _tool_button(text: String, tip: String, on_press: Callable) -> Button:
|
|
|
|
|
var b := make_button(text, "plain")
|
|
|
|
|
b.tooltip_text = tip
|
|
|
|
|
b.custom_minimum_size.x = 36
|
|
|
|
|
b.add_theme_font_size_override("font_size", 14)
|
|
|
|
|
b.pressed.connect(on_press)
|
|
|
|
|
return b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _color_menu(anchor: Control) -> void:
|
|
|
|
|
var pm := PopupMenu.new()
|
|
|
|
|
style_popup(pm)
|
|
|
|
|
for i in COLORS.size():
|
|
|
|
|
pm.add_item(COLORS[i][0], i)
|
|
|
|
|
pm.id_pressed.connect(func(id: int) -> void:
|
|
|
|
|
_wrap_selection("[color=%s]" % (COLORS[id][1] as Color).to_html(false), "[/color]")
|
|
|
|
|
)
|
|
|
|
|
pm.popup_hide.connect(pm.queue_free)
|
|
|
|
|
add_child(pm)
|
|
|
|
|
pm.popup(Rect2i(Vector2i(anchor.get_screen_position()) + Vector2i(0, int(anchor.size.y)), Vector2i(0, 0)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Wraps the selected text in the tags, or inserts an empty pair at the caret.
|
|
|
|
|
func _wrap_selection(open: String, close_tag: String) -> void:
|
2026-11-09 08:06:56 -06:00
|
|
|
var r := TableSettingsRules.wrap_text(_details.text, _selection_range(), open, close_tag)
|
2026-11-08 12:23:21 -06:00
|
|
|
_details.text = r["text"]
|
|
|
|
|
_set_caret_at_offset(int(r["caret"]))
|
|
|
|
|
_details.grab_focus()
|
|
|
|
|
_refresh()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _selection_range() -> Vector2i:
|
|
|
|
|
if _details.has_selection():
|
|
|
|
|
return Vector2i(_offset_of(_details.get_selection_from_line(), _details.get_selection_from_column()),
|
|
|
|
|
_offset_of(_details.get_selection_to_line(), _details.get_selection_to_column()))
|
|
|
|
|
var c := _offset_of(_details.get_caret_line(), _details.get_caret_column())
|
|
|
|
|
return Vector2i(c, c)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _offset_of(line: int, col: int) -> int:
|
|
|
|
|
var off := 0
|
|
|
|
|
for i in line:
|
|
|
|
|
off += _details.get_line(i).length() + 1
|
|
|
|
|
return off + col
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _set_caret_at_offset(off: int) -> void:
|
|
|
|
|
var line := 0
|
|
|
|
|
while line < _details.get_line_count() - 1 and off > _details.get_line(line).length():
|
|
|
|
|
off -= _details.get_line(line).length() + 1
|
|
|
|
|
line += 1
|
|
|
|
|
_details.set_caret_line(line)
|
|
|
|
|
_details.set_caret_column(clampi(off, 0, _details.get_line(line).length()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func settings() -> Dictionary:
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
var s := {
|
2026-11-08 12:23:21 -06:00
|
|
|
"name": _name.text, "details": _details.text, "tags": _tags.text,
|
|
|
|
|
"ranged": _ranged, "dice": _dice.text.strip_edges(),
|
|
|
|
|
"card_mode": _card_mode, "deck_empty": _deck_empty,
|
|
|
|
|
}
|
2026-11-09 08:06:56 -06:00
|
|
|
_kind.add_settings(s)
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
2026-11-08 12:23:21 -06:00
|
|
|
func _refresh() -> void:
|
|
|
|
|
if _preview == null:
|
|
|
|
|
return
|
|
|
|
|
var det := _details.text
|
|
|
|
|
_preview.text = Formatter.close_open_tags(det) if det.strip_edges() != "" else "[color=#69726b]Preview appears here.[/color]"
|
|
|
|
|
_dice_row.visible = _ranged
|
|
|
|
|
_deck_block.visible = _card_mode
|
|
|
|
|
var s := settings()
|
2026-11-09 08:06:56 -06:00
|
|
|
var dice_ok := not _ranged or TableSettingsRules.dice_ok_text(s["dice"])
|
2026-11-08 12:23:21 -06:00
|
|
|
_dice.add_theme_color_override("font_color", Style.INK if dice_ok else Style.WARN_INK)
|
|
|
|
|
var msgs := PackedStringArray()
|
|
|
|
|
if _ranged and not table.is_ranged():
|
|
|
|
|
msgs.append("Each entry gets a range sized by its weight; adjust them on the card.")
|
2026-11-09 08:06:56 -06:00
|
|
|
if _ranged and TableSettingsRules.extra_pipe_count(table) > 0:
|
2026-11-08 12:23:21 -06:00
|
|
|
msgs.append("A range takes one pipe, so extra pipes on an entry will be dropped.")
|
|
|
|
|
if not _ranged and table.is_ranged():
|
|
|
|
|
msgs.append("Ranges are removed; entries become plain picks.")
|
|
|
|
|
_type_note.text = " ".join(msgs)
|
|
|
|
|
_type_note.visible = not msgs.is_empty()
|
|
|
|
|
var problem := ""
|
|
|
|
|
if not dice_ok:
|
|
|
|
|
problem = "“%s” is not a valid dice expression." % s["dice"]
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
elif _type_box == null or _type_box.visible:
|
2026-11-08 12:23:21 -06:00
|
|
|
var clone := RollTable.from_dict(table.to_dict())
|
2026-11-09 08:06:56 -06:00
|
|
|
TableSettingsRules.apply_settings(clone, s)
|
2026-11-08 12:23:21 -06:00
|
|
|
problem = clone.range_problems()
|
|
|
|
|
_problem.text = problem
|
|
|
|
|
_problem.visible = problem != ""
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
if _type_box != null:
|
2026-11-09 08:06:56 -06:00
|
|
|
_kind.refresh()
|
2026-11-08 12:23:21 -06:00
|
|
|
if is_inside_tree():
|
|
|
|
|
_fit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_apply() -> void:
|
|
|
|
|
var s := settings()
|
2026-11-09 08:06:56 -06:00
|
|
|
var r := TableSettingsRules.apply_settings(table, s)
|
2026-11-08 12:23:21 -06:00
|
|
|
if not r["ok"]:
|
2026-11-09 08:06:56 -06:00
|
|
|
if _kind.problem and not TableSettingsRules.kind_problems(table, s).is_empty():
|
|
|
|
|
_kind.problem.text = r["error"]
|
|
|
|
|
_kind.problem.visible = true
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
else:
|
|
|
|
|
_problem.text = r["error"]
|
|
|
|
|
_problem.visible = true
|
2026-11-08 12:23:21 -06:00
|
|
|
return
|
|
|
|
|
applied.emit(r)
|
|
|
|
|
close()
|
|
|
|
|
|
|
|
|
|
|
2026-11-09 08:06:56 -06:00
|
|
|
## TableSettingsRules.apply_settings.
|
|
|
|
|
static func apply_settings(t: RollTable, s: Dictionary) -> Dictionary:
|
|
|
|
|
return TableSettingsRules.apply_settings(t, s)
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
|
|
|
|
|
|
2026-11-09 08:06:56 -06:00
|
|
|
## TableSettingsRules.when_error.
|
|
|
|
|
static func when_error(src: String) -> String:
|
|
|
|
|
return TableSettingsRules.when_error(src)
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
|
|
|
|
|
|
2026-11-09 08:06:56 -06:00
|
|
|
## TableSettingsRules.dice_ok_text.
|
Logic cards UI: choice pop-up, card kinds, Build creation and settings, tray
- ChoiceDialog: card-styled pop-up for pick (option rows with details, Random,
1-9 / R keys), number (spin box with min/max/default, Enter) and text.
Cancel, Esc, freeing the dialog, a new roll or a collection switch all
answer null through a separate Reply object, so a roll never hangs.
- Main: real prompt hook; the steps so far light on the board and in the
tray before each question; a roll with questions shows the rest at once;
a new roll cancels an open question cleanly; refresh_live() re-renders
variable, sheet and question text only after rolls and edits.
- TableCard: "?" badge and question for choice cards, loop icon, rule chip
and Each time / Afterwards rows, compact live variable cards (reset in
Build), live sheet cards with one outlet, expression-dice subtitles,
effect chips in Play and a validated effects editor in Build.
- Build: "+ Table" menu for every kind; kind-specific settings (choice type,
question, save as, min/max; loop mode and rule; variable name, type,
starting value; sheet template) checked with Expr.check; expression pipe
counts in the pipe popover and on pipe labels.
- Tray: effect lines under chips, last 12 steps behind "+N earlier steps",
sheet headline, Cancelled / action-limit pill, capped indents and Earlier
rows; Variables tab lists every board variable with Reset all.
- RichText: error markers in red; previews show {@x_*} and {= expr}.
- examples/logic_demo.json and tests/test_logic_ui.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 14:07:57 -06:00
|
|
|
static func dice_ok_text(text: String) -> bool:
|
2026-11-09 08:06:56 -06:00
|
|
|
return TableSettingsRules.dice_ok_text(text)
|