class_name Inspector extends PanelContainer ## The Build-mode inspector (docs/PLAIN.md §6): a panel docked right of the ## board that edits the selected card, result or pipe with fill-in builders. ## Plain words mode shows builders; Text mode shows the rule text. ## ## Every change goes through Main (mark_dirty), so it is saved and is an undo ## step; typing is one step once it pauses. The panel rebuilds when the ## selected card changes from outside (an undo, an edit on the card), and ## keeps focus in the field being typed in. ## The default and smallest widths (the player can drag it wider) and the ## collapsed strip's width. const WIDTH := 340.0 const MIN_WIDTH := 280.0 const STRIP := 30.0 var width := WIDTH ## The drag handle on the inspector's left edge, shown with it when open. var splitter: PanelSplitter var main: Main ## {kind: "card" | "result" | "pipe", tid, eid?, to?}, or {} for nothing. var selection: Dictionary = {} var collapsed := false var _body: VBoxContainer var _scroll: ScrollContainer var _content: VBoxContainer var _strip: PanelContainer var _sig := "" var _sync_queued := false var _writing := false ## Run after every write, to refresh live sentences and problem lines. var _live: Array[Callable] = [] var _title_label: Label # Parts the tests drive (rebuilt with the panel). var effects: EffectsBuilder var show_if_builder: ConditionBuilder var case_builder: ConditionBuilder ## target id -> {box, when (ConditionBuilder), otherwise (CheckBox), count, save, inputs: {name: LineEdit}, taken} var pipe_parts: Dictionary = {} ## Named fields of the card section ("name", "dice", "check_mod", ...). var fields: Dictionary = {} func setup(p_main: Main) -> void: main = p_main theme = Style.card_theme() custom_minimum_size = Vector2(WIDTH, 0) size_flags_vertical = Control.SIZE_EXPAND_FILL visibility_changed.connect(_sync_splitter) var sb := Style.box(Style.CARD, 0, [0, 0, 0, 0]) sb.border_width_left = 1 sb.border_color = Color(0, 0, 0, 0.25) add_theme_stylebox_override("panel", sb) var stack := Control.new() stack.size_flags_vertical = Control.SIZE_EXPAND_FILL add_child(stack) _body = VBoxContainer.new() _body.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) _body.add_theme_constant_override("separation", 0) stack.add_child(_body) _scroll = ScrollContainer.new() _scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED _scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL _body.add_child(_scroll) var pad := MarginContainer.new() pad.size_flags_horizontal = Control.SIZE_EXPAND_FILL for k in ["margin_left", "margin_right"]: pad.add_theme_constant_override(k, 16) pad.add_theme_constant_override("margin_top", 14) pad.add_theme_constant_override("margin_bottom", 18) _scroll.add_child(pad) _content = InspectorKit.vbox(14) pad.add_child(_content) _strip = PanelContainer.new() _strip.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) _strip.add_theme_stylebox_override("panel", Style.box(Style.CARD, 0, [2, 8, 2, 8])) var open := Button.new() open.text = "«" open.tooltip_text = "Show the inspector" open.size_flags_vertical = Control.SIZE_SHRINK_BEGIN Style.skin_button(open, Style.box(Color(0, 0, 0, 0), 5, [4, 2, 4, 2]), Style.box(Style.HOVER_ROW, 5, [4, 2, 4, 2]), Style.box(Style.HOVER_ROW, 5, [4, 2, 4, 2]), Style.TRIM_DARK) open.add_theme_font_size_override("font_size", 18) open.pressed.connect(func() -> void: set_collapsed(false)) _strip.add_child(open) _strip.hide() stack.add_child(_strip) rebuild() # ---------- Selection ---------- func select(sel: Dictionary) -> void: if collapsed: set_collapsed(false) selection = sel rebuild() _mark_cards() func clear() -> void: selection = {} rebuild() _mark_cards() ## Puts the copper selection bar on the selected result's row, and clears it ## everywhere else. func _mark_cards() -> void: if main == null: return var tid := str(selection.get("tid", "")) var eid := str(selection.get("eid", "")) if str(selection.get("kind", "")) == "result" else "" for c in main.cards.values(): var card := c as TableCard if card and card.has_method("set_selected_entry"): card.set_selected_entry(eid if card.table.id == tid else "") func set_collapsed(on: bool) -> void: collapsed = on custom_minimum_size.x = STRIP if on else width _body.visible = not on _strip.visible = on _sync_splitter() if main and main.state: main.state.set_setting("inspector_collapsed", on) ## Sets the open width (from the PanelSplitter). func set_width(px: float) -> void: width = px if not collapsed: custom_minimum_size.x = px func _sync_splitter() -> void: if splitter: splitter.visible = visible and not collapsed func selected_table() -> RollTable: if selection.is_empty() or main == null: return null return main.data.get_table(str(selection.get("tid", ""))) func selected_entry() -> TableEntry: var t := selected_table() if t == null or not selection.has("eid"): return null return t.find_entry(str(selection["eid"])) ## Rebuilds once, at the end of the frame, if the selection changed from outside. func sync() -> void: if _writing or _sync_queued: return _sync_queued = true _do_sync.call_deferred() func _do_sync() -> void: _sync_queued = false if _signature() != _sig: rebuild() func _signature() -> String: var t := selected_table() if selection.is_empty(): return "" if t == null or (selection.has("eid") and selected_entry() == null): return "gone" var d := t.to_dict() for k in ["x", "y", "collapsed"]: d.erase(k) var parts := PackedStringArray([JSON.stringify(d), main.rules_view(), str(main.mode)]) for x in main.data.tables: if x.kind == RollTable.KIND_VARIABLE: parts.append("%s|%s|%s" % [x.name, x.var_name, x.var_type]) for e in t.entries: for p in e.pipes: var target := main.data.get_table(p) parts.append(("%s|%s" % [target.name, JSON.stringify(target.inputs)]) if target else "-") parts.append(str(main.lit_pipes.has(Roller.pipe_key(t.id, e.id, p)))) parts.append(str(main.is_entry_lit(t.id, e.id))) if t.is_collection(): parts.append(JSON.stringify(members(t))) return str(hash("\n".join(parts))) # ---------- Writing ---------- ## After the inspector changed table `t`: Main refreshes the card(s) and ## records the undo step. `rebuild_panel` redraws the inspector too (for ## changes that add or remove rows). func wrote(t: RollTable, all_cards: bool = false, rebuild_panel: bool = false) -> void: _writing = true main.inspector_edited(t.id, all_cards) main.mark_dirty() _writing = false _sig = _signature() for f in _live: if f.is_valid(): f.call() _refresh_title() if rebuild_panel: rebuild() ## Applies table settings through TableSettingsDialog.apply_settings (the ## same rules as the settings dialog). Returns "" or the problem. func apply_settings(over: Dictionary, rebuild_panel: bool = false) -> String: var t := selected_table() if t == null: return "Nothing selected" var s := {"name": t.name, "details": t.details, "tags": ", ".join(t.tags), "ranged": t.is_ranged(), "dice": t.dice, "dice_mod": t.dice_mod, "card_mode": t.card_mode, "deck_empty": t.deck_empty} s.merge(over, true) var r := TableSettingsDialog.apply_settings(t, s) if not r["ok"]: return str(r["error"]) if r.get("deck_reset", false) and main.state and main.data.id != "": main.state.clear_deck(main.data.id, t.id) wrote(t, t.kind == RollTable.KIND_VARIABLE, rebuild_panel) return "" func set_entry_text(s: String) -> void: var e := selected_entry() if e and e.text != s: e.text = s e.page = "" wrote(selected_table()) func set_entry_details(s: String) -> void: var e := selected_entry() if e and e.details != s: e.details = s e.page = "" wrote(selected_table()) func set_entry_effects(s: String) -> void: var e := selected_entry() if e and e.effects != s: e.effects = s wrote(selected_table()) func set_entry_show_if(s: String) -> void: var e := selected_entry() if e and e.show_if != s.strip_edges() and TableSettingsDialog.when_error(s) == "": e.show_if = s.strip_edges() wrote(selected_table()) ## A router case's condition ("" makes it the Otherwise case). func set_case_when(eid: String, s: String) -> void: var t := 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() wrote(t) func _pipe_entry() -> TableEntry: return selected_entry() func set_pipe_when(to: String, s: String) -> void: var e := _pipe_entry() if e == null or PipePopover.when_error(s) != "" or s.strip_edges() == e.when_for(to): return e.set_pipe_when(to, s) wrote(selected_table()) _refresh_otherwise(to) func set_pipe_otherwise(to: String, on: bool) -> void: var e := _pipe_entry() if e == null or on == e.is_otherwise(to): return e.set_pipe_otherwise(to, on) wrote(selected_table()) _refresh_otherwise(to) ## Sets one input value passed down the pipe ("" uses the card's default). func set_pipe_input(to: String, input_name: String, expr: String) -> void: var e := _pipe_entry() if e == null: return var w := e.with_for(to) var s := expr.strip_edges() if s != "" and InspectorKit.expr_error(s) != "": return if s == "": w.erase(input_name) else: w[input_name] = s if w == e.with_for(to): return e.set_pipe_with(to, w) wrote(selected_table()) func set_pipe_count(to: String, s: String) -> void: var e := _pipe_entry() if e == null or PipePopover._count_error(s) != "": return var before := e.count_text(to) e.set_pipe_count(to, s.strip_edges() if s.strip_edges() != "" else "1") if e.count_text(to) != before: wrote(selected_table()) func set_pipe_combine(to: String, mode: String) -> void: var e := _pipe_entry() if e == null or e.combine_for(to) == mode: return if mode == "all": e.pipe_combine.erase(to) else: e.pipe_combine[to] = mode wrote(selected_table()) func set_pipe_save(to: String, s: String) -> void: var e := _pipe_entry() if e == null or _save_error(s) != "" or s.strip_edges() == e.save_for(to): return e.set_pipe_save(to, s) wrote(selected_table()) func set_pipe_color(hex: String, to: String) -> void: var e := _pipe_entry() if e == null: return if hex == "": e.pipe_color.erase(to) else: e.pipe_color[to] = hex wrote(selected_table()) main.board.geometry_rev += 1 func remove_pipe(to: String) -> void: var t := selected_table() var e := selected_entry() if t == null or e == null: return var was_pipe := str(selection.get("kind", "")) == "pipe" main.remove_pipe(Roller.pipe_key(t.id, e.id, to)) if was_pipe: select({"kind": "result", "tid": t.id, "eid": e.id}) else: rebuild() static func _save_error(s: String) -> String: var t := TemplateKit.probe(s.strip_edges()) if t == "" or RegEx.create_from_string(PipePopover.SAVE_PATTERN).search(t) != null: return "" return "Use a name like weapon, or @weapon to keep it between rolls." # ---------- Collections ---------- ## A collection card's members: Array of [item, value] (item without the stem). func members(t: RollTable) -> Array: var out: Array = [] var pre := t.var_name + "_" var names: Array = main.persistent_vars.keys() names.sort_custom(func(a: String, b: String) -> bool: return a.naturalnocasecmp_to(b) < 0) for n: String in names: if n.begins_with(pre) and n.length() > pre.length(): var v: Variant = main.persistent_vars[n] out.append([n.substr(pre.length()), Expr.format_value(v.get("value") if v is Dictionary else v)]) return out # ---------- Building ---------- func rebuild() -> void: var focus_key := "" var caret := -1 var f := get_viewport().gui_get_focus_owner() if is_inside_tree() else null if f and is_ancestor_of(f) and f.has_meta(InspectorKit.KEY): focus_key = str(f.get_meta(InspectorKit.KEY)) if f is LineEdit: caret = (f as LineEdit).caret_column for c in _content.get_children(): _content.remove_child(c) c.queue_free() _live.clear() effects = null show_if_builder = null case_builder = null pipe_parts.clear() fields.clear() var t := selected_table() var e := selected_entry() if selection.has("eid") and e == null: t = null if t == null: selection = {} _empty() else: match str(selection.get("kind", "card")): "result": _result_section(t, e) "pipe": _pipe_section(t, e, str(selection.get("to", ""))) _: InspectorCard.build(self, _content, t) _sig = _signature() if main and main.board and main.board.pipes: main.board.pipes.select_key = Roller.pipe_key(t.id, e.id, str(selection["to"])) if t and str(selection.get("kind", "")) == "pipe" else "" if focus_key != "": var c := InspectorKit.find_tagged(_content, focus_key) if c: c.grab_focus() if c is LineEdit and caret >= 0: (c as LineEdit).caret_column = caret func _head(kind: String, title: String) -> Control: var h := InspectorKit.hbox(6) var v := InspectorKit.vbox(2) v.size_flags_horizontal = Control.SIZE_EXPAND_FILL v.add_child(InspectorKit.flabel(kind)) var tl := Style.make_label(title, Style.display(), 22, Style.INK) _title_label = tl tl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART tl.custom_minimum_size = Vector2(120, 0) v.add_child(tl) h.add_child(v) var hide_b := Button.new() hide_b.text = "»" hide_b.tooltip_text = "Hide the inspector" hide_b.size_flags_vertical = Control.SIZE_SHRINK_BEGIN Style.skin_button(hide_b, Style.box(Color(0, 0, 0, 0), 5, [6, 0, 6, 2]), Style.box(Style.HOVER_ROW, 5, [6, 0, 6, 2]), Style.box(Style.HOVER_ROW, 5, [6, 0, 6, 2]), Style.MUTED, Style.INK) hide_b.add_theme_font_size_override("font_size", 18) hide_b.focus_mode = Control.FOCUS_NONE hide_b.pressed.connect(func() -> void: set_collapsed(true)) h.add_child(hide_b) return h ## Keeps the heading in step with the name or text being typed. func _refresh_title() -> void: if not is_instance_valid(_title_label): return var t := selected_table() match str(selection.get("kind", "")): "card": if t: _title_label.text = _title_of(t.name, "(no name)") "result": var e := selected_entry() if e: _title_label.text = _title_of(e.text, "(no text)") func _empty() -> void: _content.add_child(_head("Inspector", "Nothing selected")) _content.add_child(InspectorKit.note("Select a card, a result or a thread to edit it.", Style.MUTED, 15)) _content.add_child(InspectorKit.note("Click a card's title for the card, a result's text for the result, or a thread on the felt for its options.", Style.MUTED, 13)) static func _title_of(s: String, fallback: String) -> String: var t := Formatter.strip_tags(s).strip_edges() return t if t != "" else fallback ## 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". func _book_line(t: RollTable, e: TableEntry) -> Control: var p := 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: 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: main.book.set_shown(true) main.book.refresh() 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 = "" wrote(t, false, true)) row.add_child(unlink) return row func _card_link(t: RollTable) -> Button: var b := InspectorKit.link("On %s · edit the card" % _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: select({"kind": "card", "tid": t.id})) return b func _result_section(t: RollTable, e: TableEntry) -> void: _content.add_child(_head("Selected result", _title_of(e.text, "(no text)"))) _content.add_child(_card_link(t)) var plain := 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(set_entry_text) fields["text"] = le _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: set_entry_details(det.text)) fields["details"] = det _content.add_child(InspectorKit.field("Details", det)) _content.add_child(_book_line(t, e)) if t.kind == RollTable.KIND_CHOICE and t.choice == "pick" and not (t.is_dynamic() and t.entries.find(e) == 0): show_if_builder = ConditionBuilder.new() show_if_builder.setup(main, e.show_if, not plain, "res.show_if", {"empty_note": "Always offered."}) show_if_builder.changed.connect(set_entry_show_if) _content.add_child(InspectorKit.field("Offer only if", show_if_builder)) if t.kind == RollTable.KIND_ROUTER: _content.add_child(InspectorCard.case_block(self, t, e)) effects = EffectsBuilder.new() effects.setup(main, e.effects, t, not plain, "res.fx") effects.changed.connect(set_entry_effects) _content.add_child(InspectorKit.field("When this comes up", 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(_pipe_box(t, e, p)) _content.add_child(InspectorKit.field("Then go to", go)) _lint_lines(t, e) func _pipe_section(t: RollTable, e: TableEntry, to: String) -> void: if not e.pipes.has(to): _result_section(t, e) return var target := main.data.get_table(to) _content.add_child(_head("Selected thread", "%s → %s" % [_title_of(e.text, "(no text)"), _title_of(target.name, to) if target else to])) var back := InspectorKit.link("Edit the whole result", "Show the result this thread leaves from") back.add_theme_color_override("font_color", Style.MUTED) back.pressed.connect(func() -> void: select({"kind": "result", "tid": t.id, "eid": e.id})) _content.add_child(back) _content.add_child(_pipe_box(t, e, to)) _content.add_child(InspectorKit.field("Thread colour", ColorChoice.new(str(e.pipe_color.get(to, "")), set_pipe_color.bind(to)))) _lint_lines(t, e) ## Problems and hints the board check finds on this result's pipes. func _lint_lines(t: RollTable, e: TableEntry) -> void: var box := InspectorKit.vbox(3) var fill := func() -> void: for c in box.get_children(): box.remove_child(c) c.queue_free() for it: Dictionary in Roller.lint_pipes(main.data): if str(it["table_id"]) == t.id and str(it["entry_id"]) == e.id: var hint := str(it.get("level", "error")) == "hint" or str(it["message"]).contains("otherwise") box.add_child(InspectorKit.note(("Note: " if hint else "Problem: ") + str(it["message"]) + ".", Style.MUTED if hint else Style.DANGER_INK, 13)) box.visible = box.get_child_count() > 0 fill.call() _live.append(fill) _content.add_child(box) func _pipe_box(t: RollTable, e: TableEntry, to: String) -> Control: var target := main.data.get_table(to) var parts := {"inputs": {}} var taken := main.lit_pipes.has(Roller.pipe_key(t.id, e.id, to)) var panel := PanelContainer.new() var sb := Style.bordered(Style.box(Style.VALUE_BG if taken else Style.CARD_SOFT, 8, [10, 9, 10, 10]), 1, Style.ACCENT if taken else Style.RULE) panel.add_theme_stylebox_override("panel", sb) var v := InspectorKit.vbox(8) panel.add_child(v) parts["box"] = panel parts["taken"] = taken var head := InspectorKit.hbox(8) head.add_child(InspectorKit.word("→", Style.TRIM, true)) var tn := Style.make_label(_title_of(target.name, to) if target else to + " (missing)", Style.display(), 19, Style.INK) tn.size_flags_horizontal = Control.SIZE_EXPAND_FILL tn.clip_text = true head.add_child(tn) if taken: head.add_child(_chip("taken last roll", Style.ACCENT_DARK, Style.LIT)) elif main.is_entry_lit(t.id, e.id): head.add_child(Style.make_label("not taken", Style.body_bold(), 12, Style.MUTED)) v.add_child(head) # Inputs the target declares (and any extra names the pipe passes). var w := e.with_for(to) var names: Array = target.input_names() if target else [] for nm: String in w: if not names.has(nm): names.append(nm) for nm: String in names: var decl: Dictionary = target.find_input(nm) if target else {} var row := InspectorKit.hbox(6) var lab := str(decl.get("label", "")) if not decl.is_empty() else "" var cap := InspectorKit.word(lab if lab != "" else RollContext.pretty_name(nm)) cap.custom_minimum_size = Vector2(64, 0) cap.tooltip_text = "Input %s of %s" % [nm, target.name if target else to] row.add_child(cap) var def := str(decl.get("default", "")) var le := InspectorKit.amount(str(w.get(nm, "")), def if def != "" else "0") le.tooltip_text = "An expression passed as %s. Empty uses the card's default%s." % [nm, (" (" + def + ")") if def != "" else ""] InspectorKit.tag(le, "pipe.%s.in.%s" % [to, nm]) var err := InspectorKit.error_label() var nm_c := nm le.text_changed.connect(func(s: String) -> void: var msg := InspectorKit.expr_error(s, "This value") InspectorKit.show_error(err, msg) InspectorKit.mark(le, msg == "") set_pipe_input(to, nm_c, s) ) row.add_child(le) if decl.is_empty(): row.add_child(InspectorKit.word("(not an input of this card)", Style.MUTED)) (parts["inputs"] as Dictionary)[nm] = le v.add_child(row) v.add_child(err) # Only if / Otherwise. var cond := ConditionBuilder.new() cond.setup(main, e.when_for(to), not main.rules_plain(), "pipe.%s.when" % to, {"add_label": "+ Only if…" if e.when_for(to) == "" else "+ Add condition"}) cond.changed.connect(func(s: String) -> void: set_pipe_when(to, s)) parts["when"] = cond var when_box := InspectorKit.vbox(4) when_box.add_child(InspectorKit.flabel("Only if")) when_box.add_child(cond) v.add_child(when_box) var other := InspectorKit.check_box("Otherwise", e.is_otherwise(to)) other.tooltip_text = "Runs only when none of this result's \"Only if\" threads is true" other.toggled.connect(func(on: bool) -> void: set_pipe_otherwise(to, on)) parts["otherwise"] = other v.add_child(other) # Count and saves as. var cr := InspectorKit.flow() cr.add_child(InspectorKit.word("Rolls")) var count := InspectorKit.amount(e.count_text(to), "1") count.tooltip_text = "A number, or an expression such as @terms, answer or 1d3 (worked out when the thread runs)" InspectorKit.tag(count, "pipe.%s.count" % to) var cerr := InspectorKit.error_label() count.text_changed.connect(func(s: String) -> void: var msg := PipePopover._count_error(s) InspectorKit.show_error(cerr, msg) InspectorKit.mark(count, msg == "") set_pipe_count(to, s) ) cr.add_child(count) cr.add_child(InspectorKit.word("times, then")) var then := OptionButton.new() ModalCard.style_popup(then.get_popup()) for i in RollCombine.LABELS.size(): then.add_item(RollCombine.LABELS[i], i) then.select(maxi(0, RollCombine.MODES.find(e.combine_for(to)))) then.tooltip_text = "What to do with the rolls when there's more than one (rerolls, best of two, totals…)" then.item_selected.connect(func(i: int) -> void: set_pipe_combine(to, RollCombine.MODES[i])) cr.add_child(then) parts["combine"] = then var sr := InspectorKit.hbox(6) sr.add_child(InspectorKit.word("Saves as")) var save := InspectorKit.line(e.save_for(to), "nothing (or a name)") save.tooltip_text = "Keep the result as a value: a name lasts one roll, @name is kept between rolls" InspectorKit.tag(save, "pipe.%s.save" % to) save.text_changed.connect(func(s: String) -> void: var msg := _save_error(s) InspectorKit.show_error(cerr, msg) InspectorKit.mark(save, msg == "") set_pipe_save(to, s) ) sr.add_child(save) parts["count"] = count parts["save"] = save v.add_child(cr) v.add_child(sr) v.add_child(cerr) var rm := InspectorKit.link("Delete thread", "Delete this thread") rm.add_theme_color_override("font_color", Style.DANGER_INK) rm.add_theme_color_override("font_hover_color", Style.DANGER_INK) rm.pressed.connect(func() -> void: remove_pipe(to)) v.add_child(rm) pipe_parts[to] = parts _refresh_otherwise(to) return panel ## Otherwise is off and disabled while the pipe has an Only if. func _refresh_otherwise(to: String) -> void: var parts: Dictionary = pipe_parts.get(to, {}) var e := _pipe_entry() if parts.is_empty() or e == null: return var cb := parts["otherwise"] as CheckBox var has_when := e.when_for(to) != "" cb.disabled = has_when cb.set_pressed_no_signal(e.is_otherwise(to)) cb.tooltip_text = "Turn off \"Only if\" first: a thread with a condition isn't an otherwise thread" if has_when \ else "Runs only when none of this result's \"Only if\" threads is true" static func _chip(text: String, fg: Color, bg: Color) -> Control: var p := PanelContainer.new() p.add_theme_stylebox_override("panel", Style.bordered(Style.box(bg, 9, [7, 1, 7, 2]), 1, Style.ACCENT)) p.add_child(Style.make_label(text, Style.body_bold(), 12, fg)) p.size_flags_vertical = Control.SIZE_SHRINK_CENTER return p ## Closes any open value-picker menu (before an undo rebuilds the board). func close_menus() -> void: _close_pickers(self) func _close_pickers(n: Node) -> void: for c in n.get_children(): if c is ValuePicker: (c as ValuePicker).close_menu() _close_pickers(c)