Inspector: one list with the card and every result, each collapsible
Selecting a card or result on the spread opens its section and closes the rest; sections opened by hand stay open, and a click or focus inside one makes it the section edits go to. Only open sections build their fields. Result sections edit the weight or range and the position; the card section picks Weights or Ranges and Auto-sort. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f335faa5c5
commit
1e944fa27d
12 changed files with 461 additions and 12 deletions
85
tests/test_inspector_list.gd
Normal file
85
tests/test_inspector_list.gd
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
extends TestBase
|
||||
## The inspector's card page as one list (InspectorList): a section for the
|
||||
## card and one per result; selecting on the spread opens only that section;
|
||||
## sections opened by hand stay open and edits go to the section clicked in;
|
||||
## a result's weight, range and position (InspectorRange).
|
||||
## Run: godot --headless --path . -s res://tests/test_inspector_list.gd -- --sample
|
||||
|
||||
var insp: Inspector
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
if not await start_main():
|
||||
return
|
||||
main.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
|
||||
main.size = Vector2(1440, 900)
|
||||
main.set_mode(Main.Mode.BUILD)
|
||||
insp = main.inspector
|
||||
main.data.load_dict({"format_version": 2, "id": "list-test", "name": "List test", "tables": [
|
||||
{"id": "work", "name": "Workday Job", "x": 40, "y": 40, "dice": "1d100", "ranged": true,
|
||||
"range_edit": "weights", "entries": [
|
||||
{"id": "a", "text": "Result 1", "range": [1, 5], "weight": 5},
|
||||
{"id": "b", "text": "Bob", "range": [6, 80], "weight": 75},
|
||||
{"id": "c", "text": "Joe", "range": [81, 87], "weight": 7},
|
||||
{"id": "d", "text": "Kevin", "range": [88, 100], "weight": 13}]}]})
|
||||
main._rebuild_cards()
|
||||
main.clear_inspector()
|
||||
await _frames(4)
|
||||
await _test_sections()
|
||||
await _test_open_by_hand()
|
||||
await _test_position_and_weight()
|
||||
finish()
|
||||
|
||||
|
||||
func _t() -> RollTable:
|
||||
return main.data.get_table("work")
|
||||
|
||||
|
||||
func _open_keys() -> Array:
|
||||
var out: Array = []
|
||||
for k: String in insp.section_parts:
|
||||
if insp.section_parts[k].get("built", false):
|
||||
out.append(k)
|
||||
return out
|
||||
|
||||
|
||||
func _test_sections() -> void:
|
||||
main.select_result("work", "b")
|
||||
await _frames()
|
||||
_eq(insp.section_parts.keys(), ["card", "a", "b", "c", "d"], "a section for the card and each result")
|
||||
_eq(_open_keys(), ["b"], "selecting a result opens only its section")
|
||||
_eq((insp.fields["text"] as LineEdit).text, "Bob", "the open section edits that result")
|
||||
main.select_card("work")
|
||||
await _frames()
|
||||
_eq(_open_keys(), ["card"], "selecting the card opens only the card section")
|
||||
_check(insp.fields.has("name"), "the card's fields are active")
|
||||
|
||||
|
||||
func _test_open_by_hand() -> void:
|
||||
main.select_result("work", "a")
|
||||
await _frames()
|
||||
InspectorList.toggle(insp, "c")
|
||||
await _frames()
|
||||
_eq(_open_keys(), ["a", "c"], "a section opened by hand joins the open one")
|
||||
_eq(str(insp.selection.get("eid")), "c", "the section just opened is active")
|
||||
InspectorList.activate(insp, "a")
|
||||
insp.set_entry_text("First")
|
||||
_eq(_t().find_entry("a").text, "First", "edits go to the section made active")
|
||||
_eq(_t().find_entry("c").text, "Joe", "the other open section is untouched")
|
||||
await _frames()
|
||||
_eq(_open_keys(), ["a", "c"], "an edit keeps both sections open")
|
||||
main.select_result("work", "d")
|
||||
await _frames()
|
||||
_eq(_open_keys(), ["d"], "a click on the spread closes the rest again")
|
||||
|
||||
|
||||
func _test_position_and_weight() -> void:
|
||||
var t := _t()
|
||||
InspectorRange.set_weight(insp, t, t.find_entry("a"), 10)
|
||||
_eq(Vector2i(t.find_entry("b").range_lo, t.find_entry("b").range_hi), Vector2i(11, 85), "a weight edit moves the ranges after it")
|
||||
InspectorRange.move_to(insp, t, t.find_entry("d"), 0)
|
||||
_eq(t.entries[0].id, "d", "Position moves the result")
|
||||
_eq(t.entries[0].range_lo, 1, "Weights lay the ranges out again after a move")
|
||||
RangeWeights.set_mode(t, RangeWeights.RANGES)
|
||||
InspectorRange.set_range(insp, t, t.find_entry("d"), 120, 125)
|
||||
_eq(t.entries.back().id, "d", "auto-sort puts an edited range in roll order")
|
||||
1
tests/test_inspector_list.gd.uid
Normal file
1
tests/test_inspector_list.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://7enpfdhcgrqj
|
||||
|
|
@ -40,8 +40,13 @@ 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", ...).
|
||||
## Named fields of the active section ("name", "dice", "text", ...).
|
||||
var fields: Dictionary = {}
|
||||
## The card page's sections (InspectorList): which are open ("card" or a
|
||||
## result id -> true), each one's parts, and each one's box.
|
||||
var open_sections: Dictionary = {}
|
||||
var section_parts: Dictionary = {}
|
||||
var section_boxes: Dictionary = {}
|
||||
|
||||
|
||||
func setup(p_main: Main) -> void:
|
||||
|
|
@ -56,12 +61,37 @@ func setup(p_main: Main) -> void:
|
|||
|
||||
# ---------- Selection ----------
|
||||
|
||||
## Selecting a card or result on the spread opens its section and closes the rest.
|
||||
func select(sel: Dictionary) -> void:
|
||||
if collapsed:
|
||||
set_collapsed(false)
|
||||
selection = sel
|
||||
var kind := str(sel.get("kind", ""))
|
||||
if kind == "card" or kind == "result":
|
||||
open_sections = {InspectorList.key_of(sel): true}
|
||||
rebuild()
|
||||
_mark_cards()
|
||||
if kind == "card" or kind == "result":
|
||||
InspectorList.scroll_to(self, InspectorList.key_of(sel))
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
get_viewport().gui_focus_changed.connect(_on_focus_changed)
|
||||
|
||||
|
||||
## A click or focus inside a section makes it the one edits go to.
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and (event as InputEventMouseButton).pressed and is_visible_in_tree() and not section_boxes.is_empty():
|
||||
var key := InspectorList.key_at(self, (event as InputEventMouseButton).global_position)
|
||||
if key != "":
|
||||
InspectorList.activate(self, key)
|
||||
|
||||
|
||||
func _on_focus_changed(c: Control) -> void:
|
||||
if c and is_ancestor_of(c) and not section_boxes.is_empty():
|
||||
var key := InspectorList.key_holding(self, c)
|
||||
if key != "":
|
||||
InspectorList.activate(self, key)
|
||||
|
||||
|
||||
func clear() -> void:
|
||||
|
|
@ -278,8 +308,10 @@ func rebuild() -> void:
|
|||
effects = null
|
||||
show_if_builder = null
|
||||
case_builder = null
|
||||
pipe_parts.clear()
|
||||
fields.clear()
|
||||
pipe_parts = {}
|
||||
fields = {}
|
||||
section_parts.clear()
|
||||
section_boxes.clear()
|
||||
var t := selected_table()
|
||||
var e := selected_entry()
|
||||
if selection.has("eid") and e == null:
|
||||
|
|
@ -289,12 +321,10 @@ func rebuild() -> void:
|
|||
InspectorFrame.show_empty(self)
|
||||
else:
|
||||
match str(selection.get("kind", "card")):
|
||||
"result":
|
||||
InspectorResult.section(self, t, e)
|
||||
"pipe":
|
||||
InspectorThread.section(self, t, e, str(selection.get("to", "")))
|
||||
_:
|
||||
InspectorCard.build(self, _content, t)
|
||||
InspectorList.build(self, 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 ""
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@ extends RefCounted
|
|||
## InspectorCollection.
|
||||
|
||||
|
||||
static func build(insp: Inspector, box: VBoxContainer, t: RollTable) -> void:
|
||||
box.add_child(insp._head("Selected card · " + Describe.kind_label(t), Inspector._title_of(t.name, "(no name)")))
|
||||
## `with_head`: false inside the inspector's list, which has its own headers.
|
||||
static func build(insp: Inspector, box: VBoxContainer, t: RollTable, with_head: bool = true) -> void:
|
||||
if with_head:
|
||||
box.add_child(insp._head("Selected card · " + Describe.kind_label(t), Inspector._title_of(t.name, "(no name)")))
|
||||
var plain := insp.main.rules_plain()
|
||||
|
||||
var name := InspectorKit.line(t.name, "Name")
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ static func refresh_title(insp: Inspector) -> void:
|
|||
"result":
|
||||
var entry := insp.selected_entry()
|
||||
if entry:
|
||||
insp._title_label.text = Inspector._title_of(entry.text, "(no text)")
|
||||
InspectorList.refresh_title(insp, entry)
|
||||
|
||||
|
||||
## The page shown when nothing is selected.
|
||||
|
|
|
|||
183
ui/inspector_list.gd
Normal file
183
ui/inspector_list.gd
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
class_name InspectorList
|
||||
extends RefCounted
|
||||
## The inspector's page for a card, as one list: the card's own section, then
|
||||
## one section per result, each with a header that opens and closes it.
|
||||
##
|
||||
## Clicking the card or a result on the spread opens that section and closes the
|
||||
## rest (Inspector.select). Sections opened by hand stay open until then.
|
||||
## Only open sections build their fields, so long cards stay quick.
|
||||
##
|
||||
## The older section code edits "the selected result" (Inspector.selection,
|
||||
## fields, effects, ...). So each open section keeps its own parts, and a click
|
||||
## or focus inside a section makes it the active one (activate): selection and
|
||||
## those parts then point at it, and its header is outlined.
|
||||
|
||||
const CARD := "card"
|
||||
|
||||
|
||||
## Builds the whole page for card `t` into the inspector's content box.
|
||||
static func build(insp: Inspector, t: RollTable) -> void:
|
||||
insp.section_parts.clear()
|
||||
insp.section_boxes.clear()
|
||||
var keep_selection := insp.selection.duplicate()
|
||||
insp._content.add_child(insp._head("Card · " + Describe.kind_label(t), Inspector._title_of(t.name, "(no name)")))
|
||||
var list := InspectorKit.vbox(6)
|
||||
insp._content.add_child(list)
|
||||
_section(insp, list, CARD, "Card", "Settings", "", func(body: VBoxContainer) -> void:
|
||||
insp.selection = {"kind": "card", "tid": t.id}
|
||||
InspectorCard.build(insp, body, t, false))
|
||||
if t.kind != RollTable.KIND_VARIABLE:
|
||||
for i in t.entries.size():
|
||||
var e := t.entries[i]
|
||||
var span := t.num_label(e, i) if t.is_ranged() and e.has_range else ""
|
||||
_section(insp, list, e.id, _kind_word(t), Inspector._title_of(e.text, "(nothing)"), span, func(body: VBoxContainer) -> void:
|
||||
insp.selection = {"kind": "result", "tid": t.id, "eid": e.id}
|
||||
InspectorRange.build(insp, body, t, e)
|
||||
var outer := insp._content
|
||||
insp._content = body
|
||||
InspectorResult.section(insp, t, e, false)
|
||||
insp._content = outer)
|
||||
insp.selection = keep_selection
|
||||
activate(insp, key_of(insp.selection))
|
||||
|
||||
|
||||
## "card" for a card selection, the result's id for a result.
|
||||
static func key_of(sel: Dictionary) -> String:
|
||||
return str(sel.get("eid", "")) if str(sel.get("kind", "")) == "result" else CARD
|
||||
|
||||
|
||||
static func _kind_word(t: RollTable) -> String:
|
||||
match t.kind:
|
||||
RollTable.KIND_CHOICE:
|
||||
return "Option"
|
||||
RollTable.KIND_ROUTER:
|
||||
return "Case"
|
||||
return "Result"
|
||||
|
||||
|
||||
## One section: a header (▸/▾, kind, title, range) and, when open, its body.
|
||||
static func _section(insp: Inspector, list: VBoxContainer, key: String, kind: String, title: String, span: String, fill: Callable) -> void:
|
||||
var open: bool = insp.open_sections.get(key, false)
|
||||
var box := InspectorKit.vbox(0)
|
||||
list.add_child(box)
|
||||
insp.section_boxes[key] = box
|
||||
var head := PanelContainer.new()
|
||||
head.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
head.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
head.tooltip_text = "Close this section" if open else "Open this section"
|
||||
var row := InspectorKit.hbox(8)
|
||||
head.add_child(row)
|
||||
row.add_child(InspectorKit.word("▾" if open else "▸", Style.MUTED))
|
||||
var kind_label := InspectorKit.flabel(kind)
|
||||
kind_label.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
row.add_child(kind_label)
|
||||
var title_label := InspectorKit.word(title, Style.INK, true)
|
||||
title_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
title_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
title_label.clip_text = true
|
||||
row.add_child(title_label)
|
||||
if span != "":
|
||||
row.add_child(InspectorKit.word(span, Style.TRIM))
|
||||
head.gui_input.connect(func(ev: InputEvent) -> void:
|
||||
if ev is InputEventMouseButton and (ev as InputEventMouseButton).pressed and (ev as InputEventMouseButton).button_index == MOUSE_BUTTON_LEFT:
|
||||
toggle(insp, key))
|
||||
box.add_child(head)
|
||||
var parts := {"head": head, "title": title_label, "fields": {}, "pipe_parts": {}, "built": open}
|
||||
insp.section_parts[key] = parts
|
||||
if not open:
|
||||
_style_head(head, false, false)
|
||||
return
|
||||
var pad := MarginContainer.new()
|
||||
for side: String in ["margin_left", "margin_right"]:
|
||||
pad.add_theme_constant_override(side, 8)
|
||||
pad.add_theme_constant_override("margin_top", 10)
|
||||
pad.add_theme_constant_override("margin_bottom", 14)
|
||||
box.add_child(pad)
|
||||
var body := InspectorKit.vbox(14)
|
||||
pad.add_child(body)
|
||||
insp.fields = parts["fields"]
|
||||
insp.pipe_parts = parts["pipe_parts"]
|
||||
insp.effects = null
|
||||
insp.show_if_builder = null
|
||||
insp.case_builder = null
|
||||
fill.call(body)
|
||||
parts["effects"] = insp.effects
|
||||
parts["show_if_builder"] = insp.show_if_builder
|
||||
parts["case_builder"] = insp.case_builder
|
||||
_style_head(head, true, false)
|
||||
|
||||
|
||||
static func _style_head(head: PanelContainer, open: bool, active: bool) -> void:
|
||||
var fill := Style.HOVER_ROW if open else Color(0, 0, 0, 0.04)
|
||||
var sb := Style.bordered(Style.box(fill, 7, [10, 7, 10, 7]), 2 if active else 1, Style.TRIM if active else Style.RULE)
|
||||
head.add_theme_stylebox_override("panel", sb)
|
||||
|
||||
|
||||
## Opens or closes a section by its header. Opening one makes it active.
|
||||
static func toggle(insp: Inspector, key: String) -> void:
|
||||
var t := insp.selected_table()
|
||||
if t == null:
|
||||
return
|
||||
var open: bool = not insp.open_sections.get(key, false)
|
||||
insp.open_sections[key] = open
|
||||
if open:
|
||||
insp.selection = {"kind": "card", "tid": t.id} if key == CARD else {"kind": "result", "tid": t.id, "eid": key}
|
||||
insp.rebuild()
|
||||
insp._mark_cards()
|
||||
|
||||
|
||||
## Makes section `key` the one edits go to: the selection and the shared parts
|
||||
## (fields, effects, ...) point at it, and its header is outlined.
|
||||
static func activate(insp: Inspector, key: String) -> void:
|
||||
var t := insp.selected_table()
|
||||
if t == null or not insp.section_parts.has(key):
|
||||
return
|
||||
var parts: Dictionary = insp.section_parts[key]
|
||||
if parts.get("built", false):
|
||||
insp.fields = parts["fields"]
|
||||
insp.pipe_parts = parts["pipe_parts"]
|
||||
insp.effects = parts.get("effects")
|
||||
insp.show_if_builder = parts.get("show_if_builder")
|
||||
insp.case_builder = parts.get("case_builder")
|
||||
var was := key_of(insp.selection)
|
||||
insp.selection = {"kind": "card", "tid": t.id} if key == CARD else {"kind": "result", "tid": t.id, "eid": key}
|
||||
for k: String in insp.section_parts:
|
||||
var p: Dictionary = insp.section_parts[k]
|
||||
_style_head(p["head"], p.get("built", false), k == key)
|
||||
if was != key:
|
||||
insp._mark_cards()
|
||||
|
||||
|
||||
## The open section under a point or holding a control, or "".
|
||||
static func key_at(insp: Inspector, global_point: Vector2) -> String:
|
||||
for key: String in insp.section_boxes:
|
||||
var box: Control = insp.section_boxes[key]
|
||||
if is_instance_valid(box) and box.get_global_rect().has_point(global_point):
|
||||
return key
|
||||
return ""
|
||||
|
||||
|
||||
static func key_holding(insp: Inspector, c: Control) -> String:
|
||||
for key: String in insp.section_boxes:
|
||||
var box: Control = insp.section_boxes[key]
|
||||
if is_instance_valid(box) and box.is_ancestor_of(c):
|
||||
return key
|
||||
return ""
|
||||
|
||||
|
||||
## Scrolls so the section's header shows (after the page is laid out).
|
||||
static func scroll_to(insp: Inspector, key: String) -> void:
|
||||
await insp.get_tree().process_frame
|
||||
var head: Control = (insp.section_parts.get(key, {}) as Dictionary).get("head")
|
||||
if is_instance_valid(head) and is_instance_valid(insp._scroll):
|
||||
# The header near the top, so the open section's fields show below it.
|
||||
var offset := head.get_global_rect().position.y - insp._scroll.get_global_rect().position.y
|
||||
insp._scroll.scroll_vertical = maxi(0, insp._scroll.scroll_vertical + int(offset) - 8)
|
||||
|
||||
|
||||
## Keeps a result's header title in step with its text as it is typed.
|
||||
static func refresh_title(insp: Inspector, e: TableEntry) -> void:
|
||||
var parts: Dictionary = insp.section_parts.get(e.id, {})
|
||||
var label: Label = parts.get("title")
|
||||
if is_instance_valid(label):
|
||||
label.text = Inspector._title_of(e.text, "(nothing)")
|
||||
1
ui/inspector_list.gd.uid
Normal file
1
ui/inspector_list.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bhb60l4tafo4c
|
||||
121
ui/inspector_range.gd
Normal file
121
ui/inspector_range.gd
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
class_name InspectorRange
|
||||
extends RefCounted
|
||||
## A result's place on its card, in the inspector's result section: its weight
|
||||
## (die faces on a Weights card, chance on a plain card) or its range (From–To
|
||||
## on a Ranges card), and its position (▲ ▼ or a typed number). Edits go
|
||||
## through RangeWeights.after_edit, so Weights reflow and auto-sort apply, as
|
||||
## they do on the card.
|
||||
|
||||
|
||||
static func build(insp: Inspector, box: VBoxContainer, t: RollTable, e: TableEntry) -> void:
|
||||
var fixed := t.kind == RollTable.KIND_LOOP or (t.kind == RollTable.KIND_CHOICE and t.choice != "pick")
|
||||
if fixed or t.kind == RollTable.KIND_SHEET:
|
||||
return
|
||||
if t.kind == RollTable.KIND_ROLL or t.kind == RollTable.KIND_CHOICE:
|
||||
if RangeWeights.uses_weights(t) or not t.is_ranged():
|
||||
box.add_child(InspectorKit.field("Weight (die faces)" if t.is_ranged() else "Weight", _weight_row(insp, t, e)))
|
||||
else:
|
||||
box.add_child(InspectorKit.field("Range", _range_row(insp, t, e)))
|
||||
if t.entries.size() > 1:
|
||||
box.add_child(InspectorKit.field("Position", _position_row(insp, t, e)))
|
||||
|
||||
|
||||
static func _weight_row(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
|
||||
var row := InspectorKit.hbox(8)
|
||||
var amount := InspectorKit.line(str(e.weight), "1", 64.0)
|
||||
InspectorKit.tag(amount, "res.weight")
|
||||
insp.fields["weight"] = amount
|
||||
amount.text_submitted.connect(func(_s: String) -> void: amount.release_focus())
|
||||
amount.focus_exited.connect(func() -> void:
|
||||
var typed := amount.text.strip_edges()
|
||||
if typed.is_valid_int():
|
||||
set_weight(insp, t, e, typed.to_int()))
|
||||
row.add_child(amount)
|
||||
if t.is_ranged():
|
||||
row.add_child(InspectorKit.note("rolls %s" % (t.num_label(e, t.entries.find(e)) if e.has_range else "never"), Style.MUTED, 13))
|
||||
else:
|
||||
row.add_child(InspectorKit.note("0 = never comes up", Style.MUTED, 13))
|
||||
return row
|
||||
|
||||
|
||||
static func _range_row(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
|
||||
var row := InspectorKit.hbox(6)
|
||||
var from := InspectorKit.line(str(e.range_lo), "1", 64.0)
|
||||
var to := InspectorKit.line(str(e.range_hi), "1", 64.0)
|
||||
InspectorKit.tag(from, "res.range_lo")
|
||||
InspectorKit.tag(to, "res.range_hi")
|
||||
insp.fields["range_lo"] = from
|
||||
insp.fields["range_hi"] = to
|
||||
var commit := func() -> void:
|
||||
var lo := from.text.strip_edges()
|
||||
var hi := to.text.strip_edges()
|
||||
if lo.is_valid_int() and hi.is_valid_int():
|
||||
set_range(insp, t, e, lo.to_int(), hi.to_int())
|
||||
for edit: LineEdit in [from, to]:
|
||||
edit.text_submitted.connect(func(_s: String) -> void: edit.release_focus())
|
||||
edit.focus_exited.connect(commit)
|
||||
row.add_child(from)
|
||||
row.add_child(InspectorKit.word("–"))
|
||||
row.add_child(to)
|
||||
return row
|
||||
|
||||
|
||||
static func _position_row(insp: Inspector, t: RollTable, e: TableEntry) -> Control:
|
||||
var row := InspectorKit.hbox(6)
|
||||
var at := t.entries.find(e)
|
||||
var up := ModalCard.make_button("▲")
|
||||
up.tooltip_text = "Move up one row"
|
||||
up.disabled = at <= 0
|
||||
up.pressed.connect(func() -> void: move_to(insp, t, e, at - 1))
|
||||
var down := ModalCard.make_button("▼")
|
||||
down.tooltip_text = "Move down one row"
|
||||
down.disabled = at >= t.entries.size() - 1
|
||||
down.pressed.connect(func() -> void: move_to(insp, t, e, at + 1))
|
||||
var number := InspectorKit.line(str(at + 1), "", 52.0)
|
||||
InspectorKit.tag(number, "res.position")
|
||||
insp.fields["position"] = number
|
||||
number.text_submitted.connect(func(_s: String) -> void: number.release_focus())
|
||||
number.focus_exited.connect(func() -> void:
|
||||
var typed := number.text.strip_edges()
|
||||
if typed.is_valid_int() and typed.to_int() - 1 != t.entries.find(e):
|
||||
move_to(insp, t, e, typed.to_int() - 1))
|
||||
for c: Control in [up, down, number]:
|
||||
row.add_child(c)
|
||||
row.add_child(InspectorKit.note("of %d" % t.entries.size(), Style.MUTED, 13))
|
||||
return row
|
||||
|
||||
|
||||
static func set_weight(insp: Inspector, t: RollTable, e: TableEntry, w: int) -> void:
|
||||
w = clampi(w, 0, 9999)
|
||||
if w == e.weight:
|
||||
return
|
||||
e.weight = w
|
||||
RangeWeights.after_edit(t)
|
||||
insp.wrote(t, false, true)
|
||||
|
||||
|
||||
static func set_range(insp: Inspector, t: RollTable, e: TableEntry, lo: int, hi: int) -> void:
|
||||
var limit := TableCardEditing.RANGE_LIMIT
|
||||
lo = clampi(lo, -limit, limit)
|
||||
hi = clampi(hi, -limit, limit)
|
||||
if lo == e.range_lo and hi == e.range_hi:
|
||||
return
|
||||
e.range_lo = lo
|
||||
e.range_hi = hi
|
||||
e.has_range = true
|
||||
RangeWeights.after_edit(t)
|
||||
insp.wrote(t, false, true)
|
||||
|
||||
|
||||
## Moves the result to row `to` (0-based, clamped). On a Ranges card with
|
||||
## auto-sort the row may go back to its place in roll order; a toast says so.
|
||||
static func move_to(insp: Inspector, t: RollTable, e: TableEntry, to: int) -> void:
|
||||
var from := t.entries.find(e)
|
||||
to = clampi(to, 0, t.entries.size() - 1)
|
||||
if from < 0 or from == to:
|
||||
return
|
||||
t.entries.remove_at(from)
|
||||
t.entries.insert(to, e)
|
||||
if RangeWeights.after_edit(t):
|
||||
insp.main.toast("Auto-sort put the rows back in roll order (turn it off in the card's section)")
|
||||
insp.wrote(t, false, true)
|
||||
1
ui/inspector_range.gd.uid
Normal file
1
ui/inspector_range.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://exp3vts6sv6n
|
||||
|
|
@ -61,9 +61,11 @@ static func card_link(insp: Inspector, t: RollTable) -> Button:
|
|||
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))
|
||||
## `with_head`: false inside the inspector's list, which has its own headers.
|
||||
static func section(insp: Inspector, t: RollTable, e: TableEntry, with_head: bool = true) -> void:
|
||||
if with_head:
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ static func build(insp: Inspector, box: VBoxContainer, t: RollTable, plain: bool
|
|||
)
|
||||
v.add_child(err)
|
||||
box.add_child(InspectorKit.field("Rolls", v))
|
||||
box.add_child(InspectorKit.field("Edit ranges as", edit_mode(insp, t)))
|
||||
|
||||
_modifier_field(insp, box, t, plain)
|
||||
box.add_child(InspectorKit.field("Limits", limits(insp, t)))
|
||||
|
|
@ -76,6 +77,27 @@ static func build(insp: Inspector, box: VBoxContainer, t: RollTable, plain: bool
|
|||
refresh.call()
|
||||
|
||||
|
||||
## Weights or Ranges (RangeWeights), with Auto-sort for Ranges.
|
||||
static func edit_mode(insp: Inspector, t: RollTable) -> Control:
|
||||
var v := InspectorKit.vbox(6)
|
||||
var weights := t.range_edit == RangeWeights.WEIGHTS
|
||||
var seg := ModalCard.segmented(["Weights", "Ranges"], 0 if weights else 1, func(i: int) -> void:
|
||||
insp.apply_settings({"range_edit": RangeWeights.WEIGHTS if i == 0 else RangeWeights.RANGES}, true)
|
||||
)
|
||||
InspectorKit.tag(seg, "card.range_edit")
|
||||
v.add_child(seg)
|
||||
if weights:
|
||||
v.add_child(InspectorKit.note("Type how many die faces each result covers; the ranges follow the row order.", Style.MUTED, 13))
|
||||
else:
|
||||
v.add_child(InspectorKit.note("Type each range by hand, as a printed table does.", Style.MUTED, 13))
|
||||
var sort := InspectorKit.check_box("Auto-sort rows by range", t.auto_sort)
|
||||
sort.tooltip_text = "After an edit or a drag, rows put themselves back in roll order"
|
||||
InspectorKit.tag(sort, "card.auto_sort")
|
||||
sort.toggled.connect(func(on: bool) -> void: insp.apply_settings({"auto_sort": on}, true))
|
||||
v.add_child(sort)
|
||||
return v
|
||||
|
||||
|
||||
## "Never below [ ]" and "Never above [ ]": a number, or a value an earlier
|
||||
## result sets (so one table can adjust a later one), via RollTable.roll_floor
|
||||
## and roll_ceiling.
|
||||
|
|
|
|||
|
|
@ -302,6 +302,7 @@ static func apply_settings(t: RollTable, s: Dictionary) -> Dictionary:
|
|||
if ranged:
|
||||
if s.has("auto_sort"):
|
||||
t.auto_sort = bool(s["auto_sort"])
|
||||
RangeWeights.after_edit(t)
|
||||
if s.has("range_edit"):
|
||||
RangeWeights.set_mode(t, str(s["range_edit"]))
|
||||
if was_ranged and old_dice != t.dice:
|
||||
|
|
|
|||
Loading…
Reference in a new issue