Size audit 2: split table_card, its header and rows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b604553364
commit
ff76e56daf
11 changed files with 317 additions and 233 deletions
|
|
@ -53,6 +53,7 @@ var skin: TableCardSkin
|
||||||
var input: TableCardInput
|
var input: TableCardInput
|
||||||
var geometry: TableCardGeometry
|
var geometry: TableCardGeometry
|
||||||
var list_ui: TableCardList
|
var list_ui: TableCardList
|
||||||
|
var rebuilder: TableCardRebuild
|
||||||
## The ornamental border (null when the theme has none).
|
## The ornamental border (null when the theme has none).
|
||||||
var frame: CardFrame
|
var frame: CardFrame
|
||||||
var group_mark: GroupMark
|
var group_mark: GroupMark
|
||||||
|
|
@ -107,6 +108,7 @@ func setup(p_main: Main, p_table: RollTable) -> void:
|
||||||
rows_ui = TableCardRows.new(self)
|
rows_ui = TableCardRows.new(self)
|
||||||
edit_ui = TableCardEditing.new(self)
|
edit_ui = TableCardEditing.new(self)
|
||||||
value_ui = TableCardValue.new(self)
|
value_ui = TableCardValue.new(self)
|
||||||
|
rebuilder = TableCardRebuild.new(self)
|
||||||
minimum_size_changed.connect(func() -> void: _shrink.call_deferred())
|
minimum_size_changed.connect(func() -> void: _shrink.call_deferred())
|
||||||
RulesView.watch(main, _on_rules_view_changed)
|
RulesView.watch(main, _on_rules_view_changed)
|
||||||
rebuild()
|
rebuild()
|
||||||
|
|
@ -116,69 +118,9 @@ func _on_rules_view_changed(_v: Variant = null) -> void:
|
||||||
rebuild()
|
rebuild()
|
||||||
|
|
||||||
|
|
||||||
|
## Throws away the card's contents and builds them again (TableCardRebuild).
|
||||||
func rebuild() -> void:
|
func rebuild() -> void:
|
||||||
for c in get_children():
|
rebuilder.run()
|
||||||
if c == frame or c == group_mark or c == grip or c == shield:
|
|
||||||
continue
|
|
||||||
remove_child(c)
|
|
||||||
c.queue_free()
|
|
||||||
skin.sync_frame()
|
|
||||||
rows.clear()
|
|
||||||
rows_ui.clear()
|
|
||||||
more_row = null
|
|
||||||
list_scroll = null
|
|
||||||
header_ui.clear()
|
|
||||||
value_ui.clear()
|
|
||||||
plain = RulesView.plain(main)
|
|
||||||
if main.has_method("inspector_selection"):
|
|
||||||
var sel: Variant = main.call("inspector_selection")
|
|
||||||
_selected_eid = ""
|
|
||||||
# The inspector reports {kind, tid, eid}; older callers used {table_id, entry_id}.
|
|
||||||
if sel is Dictionary:
|
|
||||||
var d := sel as Dictionary
|
|
||||||
var tid := str(d.get("tid", d.get("table_id", "")))
|
|
||||||
if tid == table.id and str(d.get("kind", "result")) == "result":
|
|
||||||
_selected_eid = str(d.get("eid", d.get("entry_id", "")))
|
|
||||||
|
|
||||||
var build := main.mode == Main.Mode.BUILD
|
|
||||||
custom_minimum_size = Vector2(card_width(), 0)
|
|
||||||
_shrink.call_deferred()
|
|
||||||
var ranged := table.is_ranged()
|
|
||||||
var collapsed := is_collapsed()
|
|
||||||
var col := vbox(0)
|
|
||||||
add_child(col)
|
|
||||||
col.add_child(header_ui.make(build, ranged))
|
|
||||||
if not table.inputs.is_empty() and table.kind != RollTable.KIND_VARIABLE:
|
|
||||||
col.add_child(header_ui.make_inputs_box())
|
|
||||||
|
|
||||||
if table.kind == RollTable.KIND_VARIABLE:
|
|
||||||
col.add_child(value_ui.make_collection_body(build) if table.is_collection() else value_ui.make_variable_body(build))
|
|
||||||
_warn_panel = skin.make_warning()
|
|
||||||
col.add_child(_warn_panel)
|
|
||||||
update_warning()
|
|
||||||
if build:
|
|
||||||
col.add_child(edit_ui.make_footer(ranged))
|
|
||||||
skin.apply_style()
|
|
||||||
refresh_live()
|
|
||||||
input.raise_covers()
|
|
||||||
return
|
|
||||||
|
|
||||||
list_ui.fill(col, build, ranged, collapsed)
|
|
||||||
|
|
||||||
_warn_panel = skin.make_warning()
|
|
||||||
col.add_child(_warn_panel)
|
|
||||||
update_warning()
|
|
||||||
if build:
|
|
||||||
col.add_child(edit_ui.make_footer(ranged))
|
|
||||||
skin.apply_style()
|
|
||||||
refresh_live()
|
|
||||||
input.raise_covers()
|
|
||||||
skin.dim_drawn()
|
|
||||||
if list_scroll != null:
|
|
||||||
for eid in rows:
|
|
||||||
if main.is_entry_lit(table.id, eid):
|
|
||||||
_reveal_when_laid_out.call_deferred(eid)
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
## Variable and sheet cards always show everything; other cards collapse.
|
## Variable and sheet cards always show everything; other cards collapse.
|
||||||
|
|
|
||||||
100
ui/table_card_go_button.gd
Normal file
100
ui/table_card_go_button.gd
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
class_name TableCardGoButton
|
||||||
|
extends RefCounted
|
||||||
|
## The button at the right of a card's header that starts a roll. Its look
|
||||||
|
## depends on the card kind: a die with "2d6" on roll tables, "?" on choice
|
||||||
|
## cards, a loop arrow, a fork for routers, "Print" on sheets and a badge on
|
||||||
|
## checks. Variable cards get no button. TableCardHeader asks for it.
|
||||||
|
|
||||||
|
|
||||||
|
## Builds the go button (null for variable cards). It also fills in
|
||||||
|
## header.die_icon and header.roll_button.
|
||||||
|
static func make(header: TableCardHeader) -> Button:
|
||||||
|
var card := header.card
|
||||||
|
var table := card.table
|
||||||
|
header.die_icon = null
|
||||||
|
header.roll_button = null
|
||||||
|
if table.kind == RollTable.KIND_VARIABLE:
|
||||||
|
return null
|
||||||
|
var go_button := Button.new()
|
||||||
|
go_button.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||||
|
go_button.add_theme_font_override("font", Style.display(true))
|
||||||
|
go_button.add_theme_font_size_override("font_size", 17)
|
||||||
|
var left := 10
|
||||||
|
match table.kind:
|
||||||
|
RollTable.KIND_CHOICE:
|
||||||
|
go_button.text = "?"
|
||||||
|
go_button.add_theme_font_size_override("font_size", 20)
|
||||||
|
go_button.custom_minimum_size = Vector2(36, 0)
|
||||||
|
go_button.tooltip_text = "Ask: %s" % Formatter.strip_tags(table.prompt if table.prompt != "" else table.name)
|
||||||
|
RollTable.KIND_LOOP:
|
||||||
|
go_button.custom_minimum_size = Vector2(38, 32)
|
||||||
|
go_button.tooltip_text = "Run %s" % Formatter.strip_tags(table.name)
|
||||||
|
var icon := Control.new()
|
||||||
|
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||||
|
icon.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||||
|
icon.draw.connect(func() -> void: Icons.draw_loop(icon, icon.size / 2.0 + Vector2(0, -1), 7.0, Style.ACCENT, 2.2))
|
||||||
|
go_button.add_child(icon)
|
||||||
|
RollTable.KIND_ROUTER:
|
||||||
|
go_button.custom_minimum_size = Vector2(38, 32)
|
||||||
|
go_button.tooltip_text = "Route %s: the first case that's true is chosen" % Formatter.strip_tags(table.name)
|
||||||
|
var fork := Control.new()
|
||||||
|
fork.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||||
|
fork.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||||
|
fork.draw.connect(func() -> void: draw_fork(fork, fork.size / 2.0 + Vector2(0, 0), 8.0, Style.ACCENT, 2.2))
|
||||||
|
go_button.add_child(fork)
|
||||||
|
RollTable.KIND_SHEET:
|
||||||
|
go_button.text = "Print"
|
||||||
|
go_button.add_theme_font_override("font", Style.body_bold(true))
|
||||||
|
go_button.add_theme_font_size_override("font_size", 14)
|
||||||
|
go_button.tooltip_text = "Print this sheet in the tray"
|
||||||
|
RollTable.KIND_CHECK:
|
||||||
|
go_button.text = TableCardText.check_badge(table)
|
||||||
|
go_button.custom_minimum_size = Vector2(38, 0)
|
||||||
|
go_button.tooltip_text = "Roll the check: %s\nShift-click to skip the animation" % RulesView.check_line(table, card.main.data, card.plain)
|
||||||
|
_:
|
||||||
|
left = 34
|
||||||
|
var label := "d%d" % table.die_size()
|
||||||
|
if table.has_mod() and not table.is_expr_dice():
|
||||||
|
# The dice, not the ranges' end (which a modifier stretches).
|
||||||
|
label = table.dice_label()
|
||||||
|
elif table.is_expr_dice():
|
||||||
|
label = table.dice_label() if table.dice_label().length() <= 5 else "Roll"
|
||||||
|
go_button.text = label
|
||||||
|
go_button.tooltip_text = "Roll %s on %s\nShift-click to skip the animation" % [table.roll_text() if table.is_ranged() else table.dice_label(), table.name]
|
||||||
|
var normal_style := Style.box(Style.BG, 8, [left, 6, 10, 6])
|
||||||
|
normal_style.border_width_bottom = 2
|
||||||
|
normal_style.border_color = Style.BG_DEEP
|
||||||
|
var hover_style := normal_style.duplicate() as StyleBoxFlat
|
||||||
|
hover_style.bg_color = Style.BG_HOVER
|
||||||
|
var pressed_style := normal_style.duplicate() as StyleBoxFlat
|
||||||
|
pressed_style.border_width_bottom = 1
|
||||||
|
pressed_style.content_margin_top = 7
|
||||||
|
pressed_style.content_margin_bottom = 5
|
||||||
|
Style.skin_button(go_button, normal_style, hover_style, pressed_style, Style.ACCENT)
|
||||||
|
if table.kind == RollTable.KIND_ROLL:
|
||||||
|
var die := DieIcon.new()
|
||||||
|
die.spinning = card._rolling
|
||||||
|
header.die_icon = die
|
||||||
|
go_button.add_child(die)
|
||||||
|
go_button.resized.connect(func() -> void: die.position = Vector2(8, (go_button.size.y - 20.0) / 2.0 - 1.0))
|
||||||
|
go_button.pressed.connect(func() -> void: card.main.start_roll(table.id))
|
||||||
|
header.roll_button = go_button
|
||||||
|
return go_button
|
||||||
|
|
||||||
|
|
||||||
|
## A fork: one stem splitting into two branches, each ending in a dot (the
|
||||||
|
## router card's go button). `radius` is about half the icon's height.
|
||||||
|
static func draw_fork(canvas: CanvasItem, center: Vector2, radius: float, color: Color, width: float = 2.0) -> void:
|
||||||
|
var base := center + Vector2(-radius, 0)
|
||||||
|
var split := center + Vector2(-radius * 0.15, 0)
|
||||||
|
canvas.draw_line(base, split, color, width, true)
|
||||||
|
var up := center + Vector2(radius * 0.85, -radius * 0.75)
|
||||||
|
var down := center + Vector2(radius * 0.85, radius * 0.75)
|
||||||
|
for tip: Vector2 in [up, down]:
|
||||||
|
var points := PackedVector2Array()
|
||||||
|
for step in 9:
|
||||||
|
var weight := float(step) / 8.0
|
||||||
|
points.append(split.bezier_interpolate(split + Vector2(radius * 0.5, 0), tip - Vector2(radius * 0.45, 0), tip, weight))
|
||||||
|
canvas.draw_polyline(points, color, width, true)
|
||||||
|
canvas.draw_circle(tip, width * 1.25, color)
|
||||||
|
canvas.draw_circle(base, width * 0.9, color)
|
||||||
1
ui/table_card_go_button.gd.uid
Normal file
1
ui/table_card_go_button.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bydle33x0k13o
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
class_name TableCardHeader
|
class_name TableCardHeader
|
||||||
extends RefCounted
|
extends RefCounted
|
||||||
## The top of a TableCard: collapse chevron, name (or its inline editor and
|
## The top of a TableCard: collapse chevron, name (or its inline editor and
|
||||||
## ⋯ menu in Build), the go button, the card-mode deck row and the
|
## ⋯ menu in Build), the go button (TableCardGoButton), the card-mode deck row and the
|
||||||
## kind-specific lines under the title, plus the dashed inputs box. Owns the
|
## kind-specific lines under the title, plus the dashed inputs box. Owns the
|
||||||
## live labels refresh_live() updates (a choice's question, "3 available now").
|
## live labels refresh_live() updates (a choice's question, "3 available now").
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ func make(build: bool, ranged: bool) -> Control:
|
||||||
if table.card_mode:
|
if table.card_mode:
|
||||||
deck_row = _make_deck_row()
|
deck_row = _make_deck_row()
|
||||||
|
|
||||||
var go := _make_go_button()
|
var go := TableCardGoButton.make(self)
|
||||||
if go != null:
|
if go != null:
|
||||||
row.add_child(go)
|
row.add_child(go)
|
||||||
if deck_row != null:
|
if deck_row != null:
|
||||||
|
|
@ -134,81 +134,6 @@ func _subtitle() -> String:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
## The header button that starts a roll: the die on roll tables, a "?" badge on
|
|
||||||
## choice cards, a loop arrow on loop cards and "Print" on sheets. Variable
|
|
||||||
## cards have none.
|
|
||||||
func _make_go_button() -> Button:
|
|
||||||
var table := card.table
|
|
||||||
die_icon = null
|
|
||||||
roll_button = null
|
|
||||||
if table.kind == RollTable.KIND_VARIABLE:
|
|
||||||
return null
|
|
||||||
var go_button := Button.new()
|
|
||||||
go_button.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
|
||||||
go_button.add_theme_font_override("font", Style.display(true))
|
|
||||||
go_button.add_theme_font_size_override("font_size", 17)
|
|
||||||
var left := 10
|
|
||||||
match table.kind:
|
|
||||||
RollTable.KIND_CHOICE:
|
|
||||||
go_button.text = "?"
|
|
||||||
go_button.add_theme_font_size_override("font_size", 20)
|
|
||||||
go_button.custom_minimum_size = Vector2(36, 0)
|
|
||||||
go_button.tooltip_text = "Ask: %s" % Formatter.strip_tags(table.prompt if table.prompt != "" else table.name)
|
|
||||||
RollTable.KIND_LOOP:
|
|
||||||
go_button.custom_minimum_size = Vector2(38, 32)
|
|
||||||
go_button.tooltip_text = "Run %s" % Formatter.strip_tags(table.name)
|
|
||||||
var icon := Control.new()
|
|
||||||
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
||||||
icon.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
||||||
icon.draw.connect(func() -> void: Icons.draw_loop(icon, icon.size / 2.0 + Vector2(0, -1), 7.0, Style.ACCENT, 2.2))
|
|
||||||
go_button.add_child(icon)
|
|
||||||
RollTable.KIND_ROUTER:
|
|
||||||
go_button.custom_minimum_size = Vector2(38, 32)
|
|
||||||
go_button.tooltip_text = "Route %s: the first case that's true is chosen" % Formatter.strip_tags(table.name)
|
|
||||||
var fork := Control.new()
|
|
||||||
fork.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
||||||
fork.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
||||||
fork.draw.connect(func() -> void: draw_fork(fork, fork.size / 2.0 + Vector2(0, 0), 8.0, Style.ACCENT, 2.2))
|
|
||||||
go_button.add_child(fork)
|
|
||||||
RollTable.KIND_SHEET:
|
|
||||||
go_button.text = "Print"
|
|
||||||
go_button.add_theme_font_override("font", Style.body_bold(true))
|
|
||||||
go_button.add_theme_font_size_override("font_size", 14)
|
|
||||||
go_button.tooltip_text = "Print this sheet in the tray"
|
|
||||||
RollTable.KIND_CHECK:
|
|
||||||
go_button.text = TableCardText.check_badge(table)
|
|
||||||
go_button.custom_minimum_size = Vector2(38, 0)
|
|
||||||
go_button.tooltip_text = "Roll the check: %s\nShift-click to skip the animation" % RulesView.check_line(table, card.main.data, card.plain)
|
|
||||||
_:
|
|
||||||
left = 34
|
|
||||||
var label := "d%d" % table.die_size()
|
|
||||||
if table.has_mod() and not table.is_expr_dice():
|
|
||||||
# The dice, not the ranges' end (which a modifier stretches).
|
|
||||||
label = table.dice_label()
|
|
||||||
elif table.is_expr_dice():
|
|
||||||
label = table.dice_label() if table.dice_label().length() <= 5 else "Roll"
|
|
||||||
go_button.text = label
|
|
||||||
go_button.tooltip_text = "Roll %s on %s\nShift-click to skip the animation" % [table.roll_text() if table.is_ranged() else table.dice_label(), table.name]
|
|
||||||
var normal_style := Style.box(Style.BG, 8, [left, 6, 10, 6])
|
|
||||||
normal_style.border_width_bottom = 2
|
|
||||||
normal_style.border_color = Style.BG_DEEP
|
|
||||||
var hover_style := normal_style.duplicate() as StyleBoxFlat
|
|
||||||
hover_style.bg_color = Style.BG_HOVER
|
|
||||||
var pressed_style := normal_style.duplicate() as StyleBoxFlat
|
|
||||||
pressed_style.border_width_bottom = 1
|
|
||||||
pressed_style.content_margin_top = 7
|
|
||||||
pressed_style.content_margin_bottom = 5
|
|
||||||
Style.skin_button(go_button, normal_style, hover_style, pressed_style, Style.ACCENT)
|
|
||||||
if table.kind == RollTable.KIND_ROLL:
|
|
||||||
var die := DieIcon.new()
|
|
||||||
die.spinning = card._rolling
|
|
||||||
die_icon = die
|
|
||||||
go_button.add_child(die)
|
|
||||||
go_button.resized.connect(func() -> void: die.position = Vector2(8, (go_button.size.y - 20.0) / 2.0 - 1.0))
|
|
||||||
go_button.pressed.connect(func() -> void: card.main.start_roll(table.id))
|
|
||||||
roll_button = go_button
|
|
||||||
return go_button
|
|
||||||
|
|
||||||
|
|
||||||
## Kind-specific lines under the header: a choice card's question, a loop's
|
## Kind-specific lines under the header: a choice card's question, a loop's
|
||||||
## rule, a variable's name.
|
## rule, a variable's name.
|
||||||
|
|
@ -354,23 +279,6 @@ class DashedBox extends StyleBox:
|
||||||
d += 9.0
|
d += 9.0
|
||||||
|
|
||||||
|
|
||||||
## A fork: one stem splitting into two branches, each ending in a dot (the
|
|
||||||
## router card's go button). `r` is about half the icon's height.
|
|
||||||
static func draw_fork(ci: CanvasItem, c: Vector2, r: float, color: Color, width: float = 2.0) -> void:
|
|
||||||
var base := c + Vector2(-r, 0)
|
|
||||||
var split := c + Vector2(-r * 0.15, 0)
|
|
||||||
ci.draw_line(base, split, color, width, true)
|
|
||||||
var up := c + Vector2(r * 0.85, -r * 0.75)
|
|
||||||
var down := c + Vector2(r * 0.85, r * 0.75)
|
|
||||||
for tip: Vector2 in [up, down]:
|
|
||||||
var pts := PackedVector2Array()
|
|
||||||
for k in 9:
|
|
||||||
var u := float(k) / 8.0
|
|
||||||
pts.append(split.bezier_interpolate(split + Vector2(r * 0.5, 0), tip - Vector2(r * 0.45, 0), tip, u))
|
|
||||||
ci.draw_polyline(pts, color, width, true)
|
|
||||||
ci.draw_circle(tip, width * 1.25, color)
|
|
||||||
ci.draw_circle(base, width * 0.9, color)
|
|
||||||
|
|
||||||
|
|
||||||
## Deck mode: "4 / 6 left" and a small Shuffle link under the title.
|
## Deck mode: "4 / 6 left" and a small Shuffle link under the title.
|
||||||
func _make_deck_row() -> Control:
|
func _make_deck_row() -> Control:
|
||||||
|
|
|
||||||
53
ui/table_card_odds.gd
Normal file
53
ui/table_card_odds.gd
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
class_name TableCardOdds
|
||||||
|
extends RefCounted
|
||||||
|
## The small chance labels ("17%") at the right of ranged rows in Play mode.
|
||||||
|
## When a card has a roll modifier, the chances move as its value changes, so
|
||||||
|
## refresh() rewrites the labels from the modifier's value now. TableCardRows
|
||||||
|
## owns one of these and calls track() for each label it makes.
|
||||||
|
|
||||||
|
var card: TableCard
|
||||||
|
## Chance labels by entry id, for the rows currently shown.
|
||||||
|
var labels: Dictionary = {}
|
||||||
|
|
||||||
|
|
||||||
|
func _init(p_card: TableCard) -> void:
|
||||||
|
card = p_card
|
||||||
|
|
||||||
|
|
||||||
|
## Forgets the previous build's labels.
|
||||||
|
func clear() -> void:
|
||||||
|
labels.clear()
|
||||||
|
|
||||||
|
|
||||||
|
## Remembers a row's chance label and fills it in now.
|
||||||
|
func track(chance_label: Label, entry: TableEntry) -> void:
|
||||||
|
labels[entry.id] = chance_label
|
||||||
|
set_chance(chance_label, entry, live_mod())
|
||||||
|
|
||||||
|
|
||||||
|
## The roll modifier's value now (RollRange.live_mod): {"known", "value"}.
|
||||||
|
func live_mod() -> Dictionary:
|
||||||
|
var main := card.main
|
||||||
|
return RollRange.live_mod(card.table, Roller.live_context(main.data, main.persistent_vars))
|
||||||
|
|
||||||
|
|
||||||
|
## Updates the chance labels for the modifier's current value.
|
||||||
|
func refresh() -> void:
|
||||||
|
if labels.is_empty():
|
||||||
|
return
|
||||||
|
var modifier := live_mod()
|
||||||
|
for eid: String in labels:
|
||||||
|
var entry := card.table.find_entry(eid)
|
||||||
|
if entry != null and is_instance_valid(labels[eid]):
|
||||||
|
set_chance(labels[eid], entry, modifier)
|
||||||
|
|
||||||
|
|
||||||
|
## Writes one label's chance (and its tooltip) for a modifier value.
|
||||||
|
func set_chance(chance_label: Label, entry: TableEntry, modifier: Dictionary) -> void:
|
||||||
|
var table := card.table
|
||||||
|
var chance := TablePreview.chance_text(table, entry, int(modifier["value"])) if modifier["known"] else ""
|
||||||
|
if chance_label.text != chance:
|
||||||
|
chance_label.text = chance
|
||||||
|
if table.has_mod():
|
||||||
|
chance_label.tooltip_text = "Chance with the modifier at %s" % Describe.signed_number(int(modifier["value"])) if modifier["known"] \
|
||||||
|
else "The chance depends on the modifier"
|
||||||
1
ui/table_card_odds.gd.uid
Normal file
1
ui/table_card_odds.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://v0200lujmgdn
|
||||||
81
ui/table_card_rebuild.gd
Normal file
81
ui/table_card_rebuild.gd
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
class_name TableCardRebuild
|
||||||
|
extends RefCounted
|
||||||
|
## Rebuilds a TableCard from its RollTable. It throws away the old contents
|
||||||
|
## (but keeps the frame, group mark, grip and shield), then adds the header,
|
||||||
|
## the inputs box, the body (a variable's value or the result list), the
|
||||||
|
## warning line and, in Build mode, the footer. TableCard.rebuild() calls run().
|
||||||
|
|
||||||
|
var card: TableCard
|
||||||
|
|
||||||
|
|
||||||
|
func _init(p_card: TableCard) -> void:
|
||||||
|
card = p_card
|
||||||
|
|
||||||
|
|
||||||
|
func run() -> void:
|
||||||
|
var table := card.table
|
||||||
|
var main := card.main
|
||||||
|
for child in card.get_children():
|
||||||
|
if child == card.frame or child == card.group_mark or child == card.grip or child == card.shield:
|
||||||
|
continue
|
||||||
|
card.remove_child(child)
|
||||||
|
child.queue_free()
|
||||||
|
card.skin.sync_frame()
|
||||||
|
card.rows.clear()
|
||||||
|
card.rows_ui.clear()
|
||||||
|
card.more_row = null
|
||||||
|
card.list_scroll = null
|
||||||
|
card.header_ui.clear()
|
||||||
|
card.value_ui.clear()
|
||||||
|
card.plain = RulesView.plain(main)
|
||||||
|
if main.has_method("inspector_selection"):
|
||||||
|
card._selected_eid = read_selected_entry(main.call("inspector_selection"))
|
||||||
|
|
||||||
|
var build := main.mode == Main.Mode.BUILD
|
||||||
|
card.custom_minimum_size = Vector2(card.card_width(), 0)
|
||||||
|
card._shrink.call_deferred()
|
||||||
|
var ranged := table.is_ranged()
|
||||||
|
var collapsed := card.is_collapsed()
|
||||||
|
var column := TableCard.vbox(0)
|
||||||
|
card.add_child(column)
|
||||||
|
column.add_child(card.header_ui.make(build, ranged))
|
||||||
|
if not table.inputs.is_empty() and table.kind != RollTable.KIND_VARIABLE:
|
||||||
|
column.add_child(card.header_ui.make_inputs_box())
|
||||||
|
|
||||||
|
if table.kind == RollTable.KIND_VARIABLE:
|
||||||
|
column.add_child(card.value_ui.make_collection_body(build) if table.is_collection() else card.value_ui.make_variable_body(build))
|
||||||
|
_finish(column, build, ranged)
|
||||||
|
return
|
||||||
|
|
||||||
|
card.list_ui.fill(column, build, ranged, collapsed)
|
||||||
|
_finish(column, build, ranged)
|
||||||
|
card.skin.dim_drawn()
|
||||||
|
if card.list_scroll != null:
|
||||||
|
for eid in card.rows:
|
||||||
|
if main.is_entry_lit(table.id, eid):
|
||||||
|
card._reveal_when_laid_out.call_deferred(eid)
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
## The inspector's selected result on this card, or "". The inspector reports
|
||||||
|
## {kind, tid, eid}; older callers used {table_id, entry_id}.
|
||||||
|
func read_selected_entry(selection: Variant) -> String:
|
||||||
|
if selection is Dictionary:
|
||||||
|
var fields := selection as Dictionary
|
||||||
|
var tid := str(fields.get("tid", fields.get("table_id", "")))
|
||||||
|
if tid == card.table.id and str(fields.get("kind", "result")) == "result":
|
||||||
|
return str(fields.get("eid", fields.get("entry_id", "")))
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
## The parts every card ends with: the warning line, the Build footer, the
|
||||||
|
## card's style and its live labels.
|
||||||
|
func _finish(column: VBoxContainer, build: bool, ranged: bool) -> void:
|
||||||
|
card._warn_panel = card.skin.make_warning()
|
||||||
|
column.add_child(card._warn_panel)
|
||||||
|
card.update_warning()
|
||||||
|
if build:
|
||||||
|
column.add_child(card.edit_ui.make_footer(ranged))
|
||||||
|
card.skin.apply_style()
|
||||||
|
card.refresh_live()
|
||||||
|
card.input.raise_covers()
|
||||||
1
ui/table_card_rebuild.gd.uid
Normal file
1
ui/table_card_rebuild.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://wbuuav1sd6j7
|
||||||
61
ui/table_card_row_text.gd
Normal file
61
ui/table_card_row_text.gd
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
class_name TableCardRowText
|
||||||
|
extends RefCounted
|
||||||
|
## Works out the text a result row shows in Play mode. A lit row shows what
|
||||||
|
## was just rolled; other rows show the entry as written, with references
|
||||||
|
## made readable. Some card kinds add a lead-in: loop rows say "Each time ·",
|
||||||
|
## a router case starts with its condition, a check outlet with its name, a
|
||||||
|
## dynamic pick's first row with "Chosen ·", and a number/text choice with
|
||||||
|
## "Answer ·". TableCardRows calls text_for().
|
||||||
|
|
||||||
|
|
||||||
|
## The Play-mode text (BBCode) of one row of the card that `rows` belongs to.
|
||||||
|
static func text_for(rows: TableCardRows, entry: TableEntry) -> String:
|
||||||
|
var card := rows.card
|
||||||
|
var table := card.table
|
||||||
|
var main := card.main
|
||||||
|
var columns_ui := rows.columns_ui
|
||||||
|
var rolled := main.lit_text(table.id, entry.id)
|
||||||
|
if columns_ui.active():
|
||||||
|
# The lit text is "Resources: Rich · Water: …"; this row shows column 0.
|
||||||
|
rolled = str(columns_ui.rolled_cell(table.entries.find(entry), 0).get("text", ""))
|
||||||
|
var text := RichText.decorate(rolled) if rolled != "" else RichText.preview(entry.text, main.data)
|
||||||
|
var muted := Style.MUTED.to_html(false)
|
||||||
|
if table.kind == RollTable.KIND_LOOP:
|
||||||
|
var index := table.entries.find(entry)
|
||||||
|
var caption: String = TableCardRows.LOOP_ROWS[clampi(index, 0, 1)]
|
||||||
|
var plain_text := Formatter.strip_tags(entry.text).strip_edges()
|
||||||
|
if plain_text == "" or plain_text == caption:
|
||||||
|
text = "[b]%s[/b]" % caption
|
||||||
|
else:
|
||||||
|
text = "[color=#%s]%s ·[/color] %s" % [muted, caption, text]
|
||||||
|
elif table.kind == RollTable.KIND_ROUTER:
|
||||||
|
var bad := entry.when.strip_edges() != "" and Expr.check(entry.when.strip_edges()) != ""
|
||||||
|
var label := RulesView.case_label(entry, main.data, card.plain)
|
||||||
|
var condition := "[color=#%s][b]%s[/b][/color]" % [(Style.DANGER_INK if bad else Style.TRIM_DARK).to_html(false), RichText.plain(label)]
|
||||||
|
var plain_text := Formatter.strip_tags(entry.text).strip_edges()
|
||||||
|
if plain_text == "" or plain_text == TableCardText.case_label(entry) or plain_text == label or plain_text == "if …" or (plain_text == "Otherwise" and entry.when.strip_edges() == ""):
|
||||||
|
text = condition
|
||||||
|
else:
|
||||||
|
text = "%s\n%s" % [condition, text]
|
||||||
|
elif table.kind == RollTable.KIND_CHECK:
|
||||||
|
var index := table.entries.find(entry)
|
||||||
|
var outlet_name := TableCardText.check_outlet_name(index)
|
||||||
|
var head := "[color=#%s][b]%s[/b][/color]" % [TableCardText.check_outlet_color(index).to_html(false), outlet_name]
|
||||||
|
var own := Formatter.strip_tags(rolled if rolled != "" else entry.text).strip_edges()
|
||||||
|
text = head if own == "" or own == outlet_name else "%s · %s" % [head, text]
|
||||||
|
elif table.is_dynamic() and table.entries.find(entry) == 0:
|
||||||
|
var own := Formatter.strip_tags(entry.text).strip_edges()
|
||||||
|
if rolled != "":
|
||||||
|
text = "[color=#%s]Chosen ·[/color] [b]%s[/b]" % [muted, RichText.decorate(rolled)]
|
||||||
|
elif own == "" or own == Roller.CHOSEN:
|
||||||
|
text = "[i][color=#%s]Chosen: the picked option[/color][/i]" % muted
|
||||||
|
else:
|
||||||
|
text = "[color=#%s]Chosen ·[/color] %s" % [muted, text]
|
||||||
|
elif table.kind == RollTable.KIND_CHOICE and table.choice != "pick":
|
||||||
|
if rolled != "":
|
||||||
|
text = "[color=#%s]Answer ·[/color] [b]%s[/b]" % [muted, RichText.decorate(rolled)]
|
||||||
|
else:
|
||||||
|
text = "[i][color=#%s]Answer[/color][/i]" % muted
|
||||||
|
if entry.details.strip_edges() != "":
|
||||||
|
text += RichText.info_mark()
|
||||||
|
return text
|
||||||
1
ui/table_card_row_text.gd.uid
Normal file
1
ui/table_card_row_text.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://d26c4whe7qv72
|
||||||
|
|
@ -4,7 +4,8 @@ extends RefCounted
|
||||||
## collapsed card's "more" row), their Play-mode text and rule chips, and their
|
## collapsed card's "more" row), their Play-mode text and rule chips, and their
|
||||||
## highlight state (normal, flickering during a roll, lit, with the copper bar
|
## highlight state (normal, flickering during a roll, lit, with the copper bar
|
||||||
## of the inspector's selected result). Build-only controls come from
|
## of the inspector's selected result). Build-only controls come from
|
||||||
## TableCardEditing.
|
## TableCardEditing; the Play text comes from TableCardRowText and the chance
|
||||||
|
## labels from TableCardOdds.
|
||||||
|
|
||||||
enum RowState { NORMAL, FLICK, LIT }
|
enum RowState { NORMAL, FLICK, LIT }
|
||||||
|
|
||||||
|
|
@ -25,15 +26,15 @@ var columns_ui: TableCardColumns
|
||||||
## for a striped (every second) row.
|
## for a striped (every second) row.
|
||||||
var _row_styles: Array[StyleBoxFlat] = []
|
var _row_styles: Array[StyleBoxFlat] = []
|
||||||
var _flick_id := ""
|
var _flick_id := ""
|
||||||
## Chance labels by entry id (ranged rows in Play mode), kept current by
|
## Chance labels of ranged rows in Play mode (TableCardOdds).
|
||||||
## refresh_odds as the modifier's values change.
|
var odds: TableCardOdds
|
||||||
var _odds: Dictionary = {}
|
|
||||||
|
|
||||||
|
|
||||||
func _init(p_card: TableCard) -> void:
|
func _init(p_card: TableCard) -> void:
|
||||||
card = p_card
|
card = p_card
|
||||||
kind_rows = TableCardKindRows.new(self)
|
kind_rows = TableCardKindRows.new(self)
|
||||||
columns_ui = TableCardColumns.new(p_card)
|
columns_ui = TableCardColumns.new(p_card)
|
||||||
|
odds = TableCardOdds.new(p_card)
|
||||||
# Normal, flicker and lit; then the same with the copper bar of the
|
# Normal, flicker and lit; then the same with the copper bar of the
|
||||||
# inspector's selected result. Striped rows tint only the normal state, so
|
# inspector's selected result. Striped rows tint only the normal state, so
|
||||||
# the flicker and the lit result always read over the stripe.
|
# the flicker and the lit result always read over the stripe.
|
||||||
|
|
@ -52,7 +53,7 @@ func _init(p_card: TableCard) -> void:
|
||||||
func clear() -> void:
|
func clear() -> void:
|
||||||
parts.clear()
|
parts.clear()
|
||||||
columns_ui.clear()
|
columns_ui.clear()
|
||||||
_odds.clear()
|
odds.clear()
|
||||||
more_label = null
|
more_label = null
|
||||||
_flick_id = ""
|
_flick_id = ""
|
||||||
sheet_label = null
|
sheet_label = null
|
||||||
|
|
@ -159,8 +160,7 @@ func make_row(e: TableEntry, index: int, build: bool, ranged: bool, numw: float)
|
||||||
pct.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
pct.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||||
pct.mouse_filter = Control.MOUSE_FILTER_PASS
|
pct.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||||
h.add_child(pct)
|
h.add_child(pct)
|
||||||
_odds[e.id] = pct
|
odds.track(pct, e)
|
||||||
_set_odds(pct, e, live_mod())
|
|
||||||
if ranged and table.has_mod() and num != null and not RollRange.natural_reach(table, e):
|
if ranged and table.has_mod() and num != null and not RollRange.natural_reach(table, e):
|
||||||
var nat := RollRange.natural(table)
|
var nat := RollRange.natural(table)
|
||||||
num.tooltip_text = "Only a modifier reaches this: the dice alone roll %s–%s" % [table.fmt(nat.x), table.fmt(nat.y)]
|
num.tooltip_text = "Only a modifier reaches this: the dice alone roll %s–%s" % [table.fmt(nat.x), table.fmt(nat.y)]
|
||||||
|
|
@ -206,85 +206,20 @@ func add_rule_chips(col: VBoxContainer, e: TableEntry) -> void:
|
||||||
col.add_child(kind_rows.effects_chip(e))
|
col.add_child(kind_rows.effects_chip(e))
|
||||||
|
|
||||||
|
|
||||||
## Play-mode text of a row: the last rolled (expanded) text when the row is
|
## Play-mode text of a row (TableCardRowText): the rolled text when lit,
|
||||||
## lit, otherwise the entry as written with its references shown readably.
|
## otherwise the entry as written, with a lead-in for some card kinds.
|
||||||
## Loop rows read "Each time · …"; a number/text choice's row is its answer;
|
|
||||||
## a router case leads with its condition, a check outlet with its name.
|
|
||||||
func row_text(e: TableEntry) -> String:
|
func row_text(e: TableEntry) -> String:
|
||||||
var table := card.table
|
return TableCardRowText.text_for(self, e)
|
||||||
var main := card.main
|
|
||||||
var rolled := main.lit_text(table.id, e.id)
|
|
||||||
if columns_ui.active():
|
|
||||||
# The lit text is "Resources: Rich · Water: …"; this row shows column 0.
|
|
||||||
rolled = str(columns_ui.rolled_cell(table.entries.find(e), 0).get("text", ""))
|
|
||||||
var s := RichText.decorate(rolled) if rolled != "" else RichText.preview(e.text, main.data)
|
|
||||||
var muted := Style.MUTED.to_html(false)
|
|
||||||
if table.kind == RollTable.KIND_LOOP:
|
|
||||||
var index := table.entries.find(e)
|
|
||||||
var cap: String = LOOP_ROWS[clampi(index, 0, 1)]
|
|
||||||
var plain_text := Formatter.strip_tags(e.text).strip_edges()
|
|
||||||
if plain_text == "" or plain_text == cap:
|
|
||||||
s = "[b]%s[/b]" % cap
|
|
||||||
else:
|
|
||||||
s = "[color=#%s]%s ·[/color] %s" % [muted, cap, s]
|
|
||||||
elif table.kind == RollTable.KIND_ROUTER:
|
|
||||||
var bad := e.when.strip_edges() != "" and Expr.check(e.when.strip_edges()) != ""
|
|
||||||
var label := RulesView.case_label(e, main.data, card.plain)
|
|
||||||
var cond := "[color=#%s][b]%s[/b][/color]" % [(Style.DANGER_INK if bad else Style.TRIM_DARK).to_html(false), RichText.plain(label)]
|
|
||||||
var plain_text := Formatter.strip_tags(e.text).strip_edges()
|
|
||||||
if plain_text == "" or plain_text == TableCardText.case_label(e) or plain_text == label or plain_text == "if …" or (plain_text == "Otherwise" and e.when.strip_edges() == ""):
|
|
||||||
s = cond
|
|
||||||
else:
|
|
||||||
s = "%s\n%s" % [cond, s]
|
|
||||||
elif table.kind == RollTable.KIND_CHECK:
|
|
||||||
var index := table.entries.find(e)
|
|
||||||
var nm := TableCardText.check_outlet_name(index)
|
|
||||||
var head := "[color=#%s][b]%s[/b][/color]" % [TableCardText.check_outlet_color(index).to_html(false), nm]
|
|
||||||
var own := Formatter.strip_tags(rolled if rolled != "" else e.text).strip_edges()
|
|
||||||
s = head if own == "" or own == nm else "%s · %s" % [head, s]
|
|
||||||
elif table.is_dynamic() and table.entries.find(e) == 0:
|
|
||||||
var own := Formatter.strip_tags(e.text).strip_edges()
|
|
||||||
if rolled != "":
|
|
||||||
s = "[color=#%s]Chosen ·[/color] [b]%s[/b]" % [muted, RichText.decorate(rolled)]
|
|
||||||
elif own == "" or own == Roller.CHOSEN:
|
|
||||||
s = "[i][color=#%s]Chosen: the picked option[/color][/i]" % muted
|
|
||||||
else:
|
|
||||||
s = "[color=#%s]Chosen ·[/color] %s" % [muted, s]
|
|
||||||
elif table.kind == RollTable.KIND_CHOICE and table.choice != "pick":
|
|
||||||
if rolled != "":
|
|
||||||
s = "[color=#%s]Answer ·[/color] [b]%s[/b]" % [muted, RichText.decorate(rolled)]
|
|
||||||
else:
|
|
||||||
s = "[i][color=#%s]Answer[/color][/i]" % muted
|
|
||||||
if e.details.strip_edges() != "":
|
|
||||||
s += RichText.info_mark()
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
## The roll modifier's value now (RollRange.live_mod): {"known", "value"}.
|
## The roll modifier's value now (RollRange.live_mod): {"known", "value"}.
|
||||||
func live_mod() -> Dictionary:
|
func live_mod() -> Dictionary:
|
||||||
var main := card.main
|
return odds.live_mod()
|
||||||
return RollRange.live_mod(card.table, Roller.live_context(main.data, main.persistent_vars))
|
|
||||||
|
|
||||||
|
|
||||||
## Updates the chance labels for the modifier's current value.
|
## Updates the chance labels for the modifier's current value.
|
||||||
func refresh_odds() -> void:
|
func refresh_odds() -> void:
|
||||||
if _odds.is_empty():
|
odds.refresh()
|
||||||
return
|
|
||||||
var lm := live_mod()
|
|
||||||
for eid: String in _odds:
|
|
||||||
var e := card.table.find_entry(eid)
|
|
||||||
if e != null and is_instance_valid(_odds[eid]):
|
|
||||||
_set_odds(_odds[eid], e, lm)
|
|
||||||
|
|
||||||
|
|
||||||
func _set_odds(pct: Label, e: TableEntry, lm: Dictionary) -> void:
|
|
||||||
var t := card.table
|
|
||||||
var txt := TablePreview.chance_text(t, e, int(lm["value"])) if lm["known"] else ""
|
|
||||||
if pct.text != txt:
|
|
||||||
pct.text = txt
|
|
||||||
if t.has_mod():
|
|
||||||
pct.tooltip_text = "Chance with the modifier at %s" % Describe.signed_number(int(lm["value"])) if lm["known"] \
|
|
||||||
else "The chance depends on the modifier"
|
|
||||||
|
|
||||||
|
|
||||||
## Re-renders a sheet card's template from the current variables.
|
## Re-renders a sheet card's template from the current variables.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue