Size audit: split ChoiceDialog and TableCard into helpers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
29d6d4eae9
commit
82d67eb64f
19 changed files with 944 additions and 781 deletions
104
ui/choice_chrome.gd
Normal file
104
ui/choice_chrome.gd
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
class_name ChoiceChrome
|
||||
extends RefCounted
|
||||
## The extras around a ChoiceDialog: the preview panel, the Minimize button,
|
||||
## the "Question waiting" pill and its toast.
|
||||
|
||||
var d: ChoiceDialog
|
||||
|
||||
|
||||
func _init(dialog: ChoiceDialog) -> void:
|
||||
d = dialog
|
||||
|
||||
|
||||
func build() -> void:
|
||||
d.preview_panel = PanelContainer.new()
|
||||
d.preview_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
d.preview_panel.clip_contents = true
|
||||
var sb := Style.box(Style.CARD, 10, [14, 11, 14, 12])
|
||||
sb.border_width_top = 3
|
||||
sb.border_color = Style.TRIM
|
||||
sb.shadow_color = Color(0, 0, 0, 0.4)
|
||||
sb.shadow_size = 16
|
||||
sb.shadow_offset = Vector2(0, 6)
|
||||
d.preview_panel.add_theme_stylebox_override("panel", sb)
|
||||
d._preview_box = VBoxContainer.new()
|
||||
d._preview_box.add_theme_constant_override("separation", 8)
|
||||
d._preview_box.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
d.preview_panel.add_child(d._preview_box)
|
||||
d.preview_panel.hide()
|
||||
d.add_child(d.preview_panel)
|
||||
|
||||
var min_btn := d.add_button("Minimize", "plain", d.minimize)
|
||||
min_btn.tooltip_text = "Hide this question to look at the spread (M or Tab)"
|
||||
d.footer.move_child(min_btn, 0)
|
||||
var spacer := Control.new()
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
d.footer.add_child(spacer)
|
||||
d.footer.move_child(spacer, 1)
|
||||
|
||||
d.pill = _bar_panel()
|
||||
var row := d.pill.get_child(0) as HBoxContainer
|
||||
var lbl := Style.make_label("Question waiting: " + d.title_label.text + " ·", Style.body_bold(), 15, Style.INK)
|
||||
lbl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
row.add_child(lbl)
|
||||
var show_btn := d.make_button("Show", "primary")
|
||||
show_btn.add_theme_font_size_override("font_size", 14)
|
||||
show_btn.pressed.connect(d.restore)
|
||||
show_btn.tooltip_text = "Bring the question back (M)"
|
||||
row.add_child(show_btn)
|
||||
var x := d.make_button("Cancel", "plain")
|
||||
x.add_theme_font_size_override("font_size", 14)
|
||||
x.tooltip_text = "Cancel the question and stop this roll"
|
||||
x.pressed.connect(func() -> void: d.answer(null))
|
||||
row.add_child(x)
|
||||
d.pill.hide()
|
||||
d.add_child(d.pill)
|
||||
|
||||
d.toast_panel = _bar_panel()
|
||||
var trow := d.toast_panel.get_child(0) as HBoxContainer
|
||||
var tl := Style.make_label("", Style.body(), 15, Style.INK)
|
||||
trow.add_child(tl)
|
||||
d.toast_panel.set_meta("label", tl)
|
||||
var ts := d.make_button("Show", "primary")
|
||||
ts.add_theme_font_size_override("font_size", 14)
|
||||
ts.pressed.connect(d.restore)
|
||||
trow.add_child(ts)
|
||||
d.toast_panel.hide()
|
||||
d.add_child(d.toast_panel)
|
||||
d._toast_timer = Timer.new()
|
||||
d._toast_timer.one_shot = true
|
||||
d._toast_timer.wait_time = 4.0
|
||||
d._toast_timer.timeout.connect(func() -> void: d.toast_panel.hide())
|
||||
d.add_child(d._toast_timer)
|
||||
|
||||
|
||||
func _bar_panel() -> PanelContainer:
|
||||
var p := PanelContainer.new()
|
||||
var sb := Style.bordered(Style.box(Style.CARD, 12, [14, 7, 8, 7]), 1, Style.DASH)
|
||||
sb.border_width_top = 3
|
||||
sb.border_color = Style.TRIM
|
||||
sb.shadow_color = Color(0, 0, 0, 0.4)
|
||||
sb.shadow_size = 14
|
||||
sb.shadow_offset = Vector2(0, 5)
|
||||
p.add_theme_stylebox_override("panel", sb)
|
||||
p.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 10)
|
||||
p.add_child(row)
|
||||
return p
|
||||
|
||||
|
||||
## Bottom centre, above the result tray; the toast sits just above it.
|
||||
func place_pill() -> void:
|
||||
if not d.minimized:
|
||||
return
|
||||
d.pill.reset_size()
|
||||
var bottom := d.size.y - 14.0
|
||||
var m := d.get_parent() as Main
|
||||
if m and m.tray and m.tray.is_inside_tree():
|
||||
bottom = m.tray.get_global_rect().position.y - d.get_global_rect().position.y - 12.0
|
||||
d.pill.position = Vector2(maxf(8.0, (d.size.x - d.pill.size.x) / 2.0), bottom - d.pill.size.y)
|
||||
if d.toast_panel.visible:
|
||||
d.toast_panel.reset_size()
|
||||
d.toast_panel.position = Vector2(maxf(8.0, (d.size.x - d.toast_panel.size.x) / 2.0), d.pill.position.y - d.toast_panel.size.y - 8.0)
|
||||
|
||||
1
ui/choice_chrome.gd.uid
Normal file
1
ui/choice_chrome.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cpcqqt3y6o5g0
|
||||
|
|
@ -46,8 +46,6 @@ var request: Dictionary
|
|||
var reply := Reply.new()
|
||||
var kind := "pick"
|
||||
|
||||
const PREVIEW_WIDTH := 350.0
|
||||
|
||||
## The board the question belongs to, for previews. Found from the parent Main
|
||||
## when not set; without one the dialog simply shows no preview.
|
||||
var board: TowerBoard
|
||||
|
|
@ -63,8 +61,8 @@ var toast_panel: PanelContainer
|
|||
var _center: Control
|
||||
var _dim: ColorRect
|
||||
var _preview_box: VBoxContainer
|
||||
var _preview_for := -2
|
||||
var _hover := -1
|
||||
var preview: ChoicePreview
|
||||
var chrome: ChoiceChrome
|
||||
var _prev_focus: Control
|
||||
var _toast_timer: Timer
|
||||
var _spin: SpinBox
|
||||
|
|
@ -86,8 +84,10 @@ func _init(p_request: Dictionary = {}) -> void:
|
|||
_center = get_child(1) as Control
|
||||
if _dim:
|
||||
_dim.color = Color(0, 0, 0, 0.32)
|
||||
preview = ChoicePreview.new(self)
|
||||
chrome = ChoiceChrome.new(self)
|
||||
_build()
|
||||
_build_chrome()
|
||||
chrome.build()
|
||||
|
||||
|
||||
func _build() -> void:
|
||||
|
|
@ -112,7 +112,7 @@ func _build_pick() -> void:
|
|||
var opts: Array = request.get("options", [])
|
||||
for k in opts.size():
|
||||
var o: Dictionary = opts[k]
|
||||
var row := _option_row(k, o)
|
||||
var row := ChoiceOptionRow.build(self, k, o)
|
||||
list.add_child(row)
|
||||
_options.append(row)
|
||||
var hint := note("Press 1–%d to choose, R for Random, M to look at the spread, Esc to cancel." % mini(9, maxi(1, opts.size())))
|
||||
|
|
@ -123,88 +123,6 @@ func _build_pick() -> void:
|
|||
r.tooltip_text = "Roll this card normally instead of choosing (R)"
|
||||
|
||||
|
||||
## One option: number key, text and details as a subtitle; the whole row is a
|
||||
## button.
|
||||
func _option_row(k: int, o: Dictionary) -> Control:
|
||||
var b := Button.new()
|
||||
b.focus_mode = Control.FOCUS_ALL
|
||||
b.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
var m := [14, 8, 14, 9]
|
||||
var n := Style.bordered(Style.box(Color.WHITE, 9, m), 1, Style.RULE)
|
||||
var h := Style.bordered(Style.box(Style.LIT, 9, m), 1, Style.ACCENT_DARK)
|
||||
Style.skin_button(b, n, h, h, Style.INK)
|
||||
b.add_theme_stylebox_override("focus", Style.focus_ring(9))
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 12)
|
||||
row.mouse_filter = MOUSE_FILTER_IGNORE
|
||||
row.set_anchors_and_offsets_preset(PRESET_FULL_RECT)
|
||||
row.offset_left = 14
|
||||
row.offset_right = -14
|
||||
row.offset_top = 8
|
||||
row.offset_bottom = -9
|
||||
var key := Style.make_label(str(k + 1) if k < 9 else "", Style.display(), 20, Style.TRIM)
|
||||
key.custom_minimum_size = Vector2(16, 0)
|
||||
key.size_flags_vertical = SIZE_SHRINK_CENTER
|
||||
key.mouse_filter = MOUSE_FILTER_IGNORE
|
||||
row.add_child(key)
|
||||
var col := VBoxContainer.new()
|
||||
col.add_theme_constant_override("separation", 1)
|
||||
col.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
col.mouse_filter = MOUSE_FILTER_IGNORE
|
||||
row.add_child(col)
|
||||
var dynamic: bool = o.get("dynamic", false)
|
||||
var shown := Formatter.escape_literal(str(o.get("label", ""))) if dynamic else str(o.get("text", ""))
|
||||
var text := RichText.label(RichText.decorate(shown), 17, Style.INK, false, true, true)
|
||||
text.mouse_filter = MOUSE_FILTER_IGNORE
|
||||
col.add_child(text)
|
||||
var det := Formatter.strip_tags(str(o.get("details", ""))).strip_edges()
|
||||
if det != "":
|
||||
var sub := Style.make_label(det, Style.body(), 13, Style.MUTED)
|
||||
sub.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
sub.max_lines_visible = 2
|
||||
sub.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
sub.mouse_filter = MOUSE_FILTER_IGNORE
|
||||
col.add_child(sub)
|
||||
b.tooltip_text = det
|
||||
var vt := str(o.get("value_text", ""))
|
||||
if dynamic and vt != "":
|
||||
var badge := PanelContainer.new()
|
||||
badge.mouse_filter = MOUSE_FILTER_IGNORE
|
||||
badge.size_flags_vertical = SIZE_SHRINK_CENTER
|
||||
badge.add_theme_stylebox_override("panel", Style.bordered(Style.box(Color(Style.ACCENT, 0.18), 6, [9, 1, 9, 2]), 1, Color(Style.ACCENT_DARK, 0.4)))
|
||||
var vl := Style.make_label(vt, Style.display(), 18, Style.TRIM_DARK)
|
||||
vl.mouse_filter = MOUSE_FILTER_IGNORE
|
||||
vl.set_meta("option_value", true)
|
||||
badge.add_child(vl)
|
||||
row.add_child(badge)
|
||||
b.add_child(row)
|
||||
# Buttons don't size to their children, so follow the row's height.
|
||||
var fit := func() -> void: b.custom_minimum_size.y = row.get_combined_minimum_size().y + 17.0
|
||||
row.minimum_size_changed.connect(fit)
|
||||
fit.call_deferred()
|
||||
if o.has("cost"):
|
||||
# What it costs; greyed out with the reason when it can't be afforded.
|
||||
var cost := Style.make_label(str(o.get("disabled", o["cost"])), Style.body_bold(), 13, Style.DANGER_INK if o.has("disabled") else Style.TRIM_DARK)
|
||||
cost.mouse_filter = MOUSE_FILTER_IGNORE
|
||||
col.add_child(cost)
|
||||
if o.has("disabled"):
|
||||
b.disabled = true
|
||||
b.modulate.a = 0.55
|
||||
b.tooltip_text = str(o["disabled"])
|
||||
var index := int(o.get("index", k))
|
||||
b.pressed.connect(func() -> void:
|
||||
if not b.disabled:
|
||||
answer(index))
|
||||
b.mouse_entered.connect(func() -> void: _set_hover(k))
|
||||
b.mouse_exited.connect(func() -> void:
|
||||
if _hover == k:
|
||||
_set_hover(-1)
|
||||
)
|
||||
b.focus_entered.connect(_refresh_preview)
|
||||
b.focus_exited.connect(_refresh_preview.call_deferred)
|
||||
return b
|
||||
|
||||
|
||||
func _build_number() -> void:
|
||||
var lo := int(request.get("min", 0))
|
||||
var hi := maxi(lo, int(request.get("max", 99)))
|
||||
|
|
@ -260,7 +178,7 @@ func _ready() -> void:
|
|||
if m:
|
||||
plain = RulesView.plain(m)
|
||||
RulesView.watch(m, _on_rules_view_changed)
|
||||
_refresh_preview()
|
||||
preview.refresh()
|
||||
if _spin:
|
||||
_spin.get_line_edit().grab_focus()
|
||||
_spin.get_line_edit().select_all()
|
||||
|
|
@ -282,8 +200,8 @@ func _on_rules_view_changed(_v: Variant = null) -> void:
|
|||
var m := get_parent() as Main
|
||||
if m:
|
||||
plain = RulesView.plain(m)
|
||||
_preview_for = -2
|
||||
_refresh_preview()
|
||||
preview.shown_for = -2
|
||||
preview.refresh()
|
||||
|
||||
|
||||
## Enter on the number or text field, or OK.
|
||||
|
|
@ -381,10 +299,10 @@ func minimize() -> void:
|
|||
_center.hide()
|
||||
if _dim:
|
||||
_dim.hide()
|
||||
_hide_preview()
|
||||
preview.hide()
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
pill.show()
|
||||
_place_pill()
|
||||
chrome.place_pill()
|
||||
|
||||
|
||||
## Brings the dialog back exactly as it was.
|
||||
|
|
@ -407,7 +325,7 @@ func restore() -> void:
|
|||
_text.grab_focus()
|
||||
elif not _options.is_empty():
|
||||
_options[0].grab_focus()
|
||||
_refresh_preview()
|
||||
preview.refresh()
|
||||
|
||||
|
||||
## Tells the player a question is waiting (they tried to start a roll or enter
|
||||
|
|
@ -419,280 +337,20 @@ func nudge(message: String = "Answer the waiting question first") -> void:
|
|||
(toast_panel.get_meta("label") as Label).text = message
|
||||
toast_panel.show()
|
||||
toast_panel.reset_size()
|
||||
_place_pill()
|
||||
chrome.place_pill()
|
||||
_toast_timer.start()
|
||||
|
||||
|
||||
func _build_chrome() -> void:
|
||||
preview_panel = PanelContainer.new()
|
||||
preview_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
preview_panel.clip_contents = true
|
||||
var sb := Style.box(Style.CARD, 10, [14, 11, 14, 12])
|
||||
sb.border_width_top = 3
|
||||
sb.border_color = Style.TRIM
|
||||
sb.shadow_color = Color(0, 0, 0, 0.4)
|
||||
sb.shadow_size = 16
|
||||
sb.shadow_offset = Vector2(0, 6)
|
||||
preview_panel.add_theme_stylebox_override("panel", sb)
|
||||
_preview_box = VBoxContainer.new()
|
||||
_preview_box.add_theme_constant_override("separation", 8)
|
||||
_preview_box.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
preview_panel.add_child(_preview_box)
|
||||
preview_panel.hide()
|
||||
add_child(preview_panel)
|
||||
|
||||
var min_btn := add_button("Minimize", "plain", minimize)
|
||||
min_btn.tooltip_text = "Hide this question to look at the spread (M or Tab)"
|
||||
footer.move_child(min_btn, 0)
|
||||
var spacer := Control.new()
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
footer.add_child(spacer)
|
||||
footer.move_child(spacer, 1)
|
||||
|
||||
pill = _bar_panel()
|
||||
var row := pill.get_child(0) as HBoxContainer
|
||||
var lbl := Style.make_label("Question waiting: " + title_label.text + " ·", Style.body_bold(), 15, Style.INK)
|
||||
lbl.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
row.add_child(lbl)
|
||||
var show_btn := make_button("Show", "primary")
|
||||
show_btn.add_theme_font_size_override("font_size", 14)
|
||||
show_btn.pressed.connect(restore)
|
||||
show_btn.tooltip_text = "Bring the question back (M)"
|
||||
row.add_child(show_btn)
|
||||
var x := make_button("Cancel", "plain")
|
||||
x.add_theme_font_size_override("font_size", 14)
|
||||
x.tooltip_text = "Cancel the question and stop this roll"
|
||||
x.pressed.connect(func() -> void: answer(null))
|
||||
row.add_child(x)
|
||||
pill.hide()
|
||||
add_child(pill)
|
||||
|
||||
toast_panel = _bar_panel()
|
||||
var trow := toast_panel.get_child(0) as HBoxContainer
|
||||
var tl := Style.make_label("", Style.body(), 15, Style.INK)
|
||||
trow.add_child(tl)
|
||||
toast_panel.set_meta("label", tl)
|
||||
var ts := make_button("Show", "primary")
|
||||
ts.add_theme_font_size_override("font_size", 14)
|
||||
ts.pressed.connect(restore)
|
||||
trow.add_child(ts)
|
||||
toast_panel.hide()
|
||||
add_child(toast_panel)
|
||||
_toast_timer = Timer.new()
|
||||
_toast_timer.one_shot = true
|
||||
_toast_timer.wait_time = 4.0
|
||||
_toast_timer.timeout.connect(func() -> void: toast_panel.hide())
|
||||
add_child(_toast_timer)
|
||||
|
||||
|
||||
func _bar_panel() -> PanelContainer:
|
||||
var p := PanelContainer.new()
|
||||
var sb := Style.bordered(Style.box(Style.CARD, 12, [14, 7, 8, 7]), 1, Style.DASH)
|
||||
sb.border_width_top = 3
|
||||
sb.border_color = Style.TRIM
|
||||
sb.shadow_color = Color(0, 0, 0, 0.4)
|
||||
sb.shadow_size = 14
|
||||
sb.shadow_offset = Vector2(0, 5)
|
||||
p.add_theme_stylebox_override("panel", sb)
|
||||
p.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 10)
|
||||
p.add_child(row)
|
||||
return p
|
||||
|
||||
|
||||
## Bottom centre, above the result tray; the toast sits just above it.
|
||||
func _place_pill() -> void:
|
||||
if not minimized:
|
||||
return
|
||||
pill.reset_size()
|
||||
var bottom := size.y - 14.0
|
||||
var m := get_parent() as Main
|
||||
if m and m.tray and m.tray.is_inside_tree():
|
||||
bottom = m.tray.get_global_rect().position.y - get_global_rect().position.y - 12.0
|
||||
pill.position = Vector2(maxf(8.0, (size.x - pill.size.x) / 2.0), bottom - pill.size.y)
|
||||
if toast_panel.visible:
|
||||
toast_panel.reset_size()
|
||||
toast_panel.position = Vector2(maxf(8.0, (size.x - toast_panel.size.x) / 2.0), pill.position.y - toast_panel.size.y - 8.0)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if minimized:
|
||||
_place_pill()
|
||||
chrome.place_pill()
|
||||
elif preview_panel.visible:
|
||||
_place_preview()
|
||||
preview.place()
|
||||
|
||||
|
||||
# ---------- Preview ----------
|
||||
|
||||
func _set_hover(k: int) -> void:
|
||||
_hover = k
|
||||
_refresh_preview()
|
||||
|
||||
|
||||
## Shows the preview for the hovered option, else the focused one, else (for
|
||||
## number and text questions) where the Answer leads.
|
||||
func _refresh_preview() -> void:
|
||||
if minimized or preview_panel == null or not is_inside_tree():
|
||||
return
|
||||
var idx := -1
|
||||
if kind == "pick":
|
||||
idx = _hover
|
||||
if idx < 0:
|
||||
for k in _options.size():
|
||||
if _options[k].has_focus():
|
||||
idx = k
|
||||
break
|
||||
else:
|
||||
idx = 0
|
||||
if idx == _preview_for:
|
||||
return
|
||||
_preview_for = idx
|
||||
for c in _preview_box.get_children():
|
||||
_preview_box.remove_child(c)
|
||||
c.queue_free()
|
||||
var content := preview_for_option(idx) if idx >= 0 else null
|
||||
if content == null:
|
||||
preview_panel.hide()
|
||||
return
|
||||
_preview_box.add_child(content)
|
||||
preview_panel.show()
|
||||
_place_preview()
|
||||
|
||||
|
||||
func _hide_preview() -> void:
|
||||
_preview_for = -2
|
||||
if preview_panel:
|
||||
preview_panel.hide()
|
||||
|
||||
|
||||
## The entry behind option `k` (a position in the request's options; for
|
||||
## number and text questions, the single Answer entry), or null.
|
||||
func _entry_for(k: int) -> TableEntry:
|
||||
if board == null:
|
||||
return null
|
||||
var t := board.get_table(str(request.get("table_id", "")))
|
||||
if t == null:
|
||||
return null
|
||||
var index := k
|
||||
if kind == "pick":
|
||||
var opts: Array = request.get("options", [])
|
||||
if k < 0 or k >= opts.size():
|
||||
return null
|
||||
var o: Dictionary = opts[k]
|
||||
index = int(o.get("entry", o.get("index", k)))
|
||||
return t.entries[index] if index >= 0 and index < t.entries.size() else null
|
||||
|
||||
|
||||
## The preview content for option `k` as a Control, or null when there is
|
||||
## nothing to say. It holds the option's details and effects, then a
|
||||
## TablePreview for each table it pipes to (with its count) and each table
|
||||
## its text mentions with [[Table]].
|
||||
## The preview content for option `k` (see ChoicePreview), or null.
|
||||
func preview_for_option(k: int) -> Control:
|
||||
var e := _entry_for(k)
|
||||
if e == null:
|
||||
return null
|
||||
var box := VBoxContainer.new()
|
||||
box.add_theme_constant_override("separation", 8)
|
||||
box.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.custom_minimum_size.x = PREVIEW_WIDTH - 28.0
|
||||
var heading := section(("Option %d" % (k + 1)) if kind == "pick" else "After you answer")
|
||||
heading.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.add_child(heading)
|
||||
var any := false
|
||||
var o: Dictionary = (request.get("options", []) as Array)[k] if kind == "pick" else {}
|
||||
var t := board.get_table(str(request.get("table_id", "")))
|
||||
if o.get("dynamic", false):
|
||||
# The variable (or list item) behind a dynamic option, and its value.
|
||||
any = true
|
||||
var what := "option = %s" % str(o.get("option", ""))
|
||||
if str(o.get("value_text", "")) != "":
|
||||
what += " · value %s" % str(o["value_text"])
|
||||
if plain:
|
||||
var src := RulesView.options_line(t, board, true) if t != null else ""
|
||||
what = "%s%s" % [Formatter.strip_tags(str(o.get("label", o.get("option", "")))), (" · level %s" % o["value_text"]) if str(o.get("value_text", "")) != "" else ""]
|
||||
if src != "":
|
||||
what += "\n" + src
|
||||
var ol := Style.make_label(what, Style.body_bold(), 13, Style.VALUE_INK)
|
||||
ol.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
ol.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.add_child(ol)
|
||||
var det := e.details.strip_edges()
|
||||
if det != "":
|
||||
any = true
|
||||
var d := RichText.label(RichText.decorate(det), 14, Style.INK, false)
|
||||
d.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.add_child(d)
|
||||
var fx: Array = Describe.effects(e.effects, board, t) if plain else Array(Effects.split(e.effects))
|
||||
if not fx.is_empty():
|
||||
any = true
|
||||
box.add_child(_rule())
|
||||
box.add_child(section("When this comes up" if plain else "Effects"))
|
||||
for st: Variant in fx:
|
||||
var l := Style.make_label(str(st), Style.body_bold(), 13, Style.VALUE_INK)
|
||||
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.add_child(l)
|
||||
var shown: Array[String] = []
|
||||
for tid in e.pipes:
|
||||
shown.append(tid)
|
||||
any = true
|
||||
box.add_child(_rule())
|
||||
var how := Describe.pipe(e, tid, board) if plain else PipeLayer._pipe_tag(e, tid)
|
||||
if how != "":
|
||||
var hl := Style.make_label(("Then: " if plain else "thread: ") + how, Style.body_bold(), 12, Style.TRIM_DARK)
|
||||
hl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
hl.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
hl.set_meta("pipe_line", true)
|
||||
box.add_child(hl)
|
||||
box.add_child(TablePreview.build(board, tid, {"count": e.count_text(tid), "vars": vars, "plain": plain}))
|
||||
var mentioned: Array[String] = []
|
||||
for name in TextExpander.references(e.text, func(n: String) -> String: return Roller.resolve(board, n)):
|
||||
var rid := Roller.resolve(board, name)
|
||||
if rid != "" and not shown.has(rid) and not mentioned.has(rid):
|
||||
mentioned.append(rid)
|
||||
if not mentioned.is_empty():
|
||||
any = true
|
||||
box.add_child(_rule())
|
||||
box.add_child(section("Mentioned in the text"))
|
||||
for rid in mentioned:
|
||||
box.add_child(TablePreview.build(board, rid, {"vars": vars, "plain": plain}))
|
||||
if not any:
|
||||
box.free()
|
||||
return null
|
||||
return box
|
||||
|
||||
|
||||
func _rule() -> Control:
|
||||
var r := ColorRect.new()
|
||||
r.color = Style.RULE
|
||||
r.custom_minimum_size.y = 1
|
||||
r.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
return r
|
||||
|
||||
|
||||
## Beside the card (right if there is room, else left), top-aligned with it
|
||||
## and kept on screen. It never overlaps the card, so it never covers options.
|
||||
func _place_preview() -> void:
|
||||
if not preview_panel.visible:
|
||||
return
|
||||
var view := size
|
||||
var cr := card.get_global_rect()
|
||||
var gap := 18.0
|
||||
var right := view.x - cr.end.x - gap - 10.0
|
||||
var left := cr.position.x - gap - 10.0
|
||||
var w := PREVIEW_WIDTH
|
||||
var x: float
|
||||
if right >= w or right >= left:
|
||||
w = clampf(right, 180.0, PREVIEW_WIDTH)
|
||||
x = cr.end.x + gap
|
||||
else:
|
||||
w = clampf(left, 180.0, PREVIEW_WIDTH)
|
||||
x = cr.position.x - gap - w
|
||||
preview_panel.custom_minimum_size.x = w
|
||||
preview_panel.size = Vector2(w, 0)
|
||||
var h := preview_panel.get_combined_minimum_size().y
|
||||
var top := clampf(cr.position.y, 10.0, maxf(10.0, view.y - 10.0 - h))
|
||||
h = minf(h, view.y - top - 10.0)
|
||||
preview_panel.position = Vector2(x, top)
|
||||
preview_panel.size = Vector2(w, h)
|
||||
return preview.preview_for_option(k)
|
||||
|
|
|
|||
85
ui/choice_option_row.gd
Normal file
85
ui/choice_option_row.gd
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
class_name ChoiceOptionRow
|
||||
extends RefCounted
|
||||
## One option button of a ChoiceDialog pick question.
|
||||
|
||||
|
||||
## One option: number key, text and details as a subtitle; the whole row is a
|
||||
## button.
|
||||
static func build(d: ChoiceDialog, k: int, o: Dictionary) -> Control:
|
||||
var b := Button.new()
|
||||
b.focus_mode = Control.FOCUS_ALL
|
||||
b.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
var m := [14, 8, 14, 9]
|
||||
var n := Style.bordered(Style.box(Color.WHITE, 9, m), 1, Style.RULE)
|
||||
var h := Style.bordered(Style.box(Style.LIT, 9, m), 1, Style.ACCENT_DARK)
|
||||
Style.skin_button(b, n, h, h, Style.INK)
|
||||
b.add_theme_stylebox_override("focus", Style.focus_ring(9))
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 12)
|
||||
row.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
row.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
row.offset_left = 14
|
||||
row.offset_right = -14
|
||||
row.offset_top = 8
|
||||
row.offset_bottom = -9
|
||||
var key := Style.make_label(str(k + 1) if k < 9 else "", Style.display(), 20, Style.TRIM)
|
||||
key.custom_minimum_size = Vector2(16, 0)
|
||||
key.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
key.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
row.add_child(key)
|
||||
var col := VBoxContainer.new()
|
||||
col.add_theme_constant_override("separation", 1)
|
||||
col.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
col.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
row.add_child(col)
|
||||
var dynamic: bool = o.get("dynamic", false)
|
||||
var shown := Formatter.escape_literal(str(o.get("label", ""))) if dynamic else str(o.get("text", ""))
|
||||
var text := RichText.label(RichText.decorate(shown), 17, Style.INK, false, true, true)
|
||||
text.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
col.add_child(text)
|
||||
var det := Formatter.strip_tags(str(o.get("details", ""))).strip_edges()
|
||||
if det != "":
|
||||
var sub := Style.make_label(det, Style.body(), 13, Style.MUTED)
|
||||
sub.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
sub.max_lines_visible = 2
|
||||
sub.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS
|
||||
sub.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
col.add_child(sub)
|
||||
b.tooltip_text = det
|
||||
var vt := str(o.get("value_text", ""))
|
||||
if dynamic and vt != "":
|
||||
var badge := PanelContainer.new()
|
||||
badge.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
badge.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
badge.add_theme_stylebox_override("panel", Style.bordered(Style.box(Color(Style.ACCENT, 0.18), 6, [9, 1, 9, 2]), 1, Color(Style.ACCENT_DARK, 0.4)))
|
||||
var vl := Style.make_label(vt, Style.display(), 18, Style.TRIM_DARK)
|
||||
vl.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
vl.set_meta("option_value", true)
|
||||
badge.add_child(vl)
|
||||
row.add_child(badge)
|
||||
b.add_child(row)
|
||||
# Buttons don't size to their children, so follow the row's height.
|
||||
var fit := func() -> void: b.custom_minimum_size.y = row.get_combined_minimum_size().y + 17.0
|
||||
row.minimum_size_changed.connect(fit)
|
||||
fit.call_deferred()
|
||||
if o.has("cost"):
|
||||
# What it costs; greyed out with the reason when it can't be afforded.
|
||||
var cost := Style.make_label(str(o.get("disabled", o["cost"])), Style.body_bold(), 13, Style.DANGER_INK if o.has("disabled") else Style.TRIM_DARK)
|
||||
cost.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
col.add_child(cost)
|
||||
if o.has("disabled"):
|
||||
b.disabled = true
|
||||
b.modulate.a = 0.55
|
||||
b.tooltip_text = str(o["disabled"])
|
||||
var index := int(o.get("index", k))
|
||||
b.pressed.connect(func() -> void:
|
||||
if not b.disabled:
|
||||
d.answer(index))
|
||||
b.mouse_entered.connect(func() -> void: d.preview.set_hover(k))
|
||||
b.mouse_exited.connect(func() -> void:
|
||||
if d.preview.hover == k:
|
||||
d.preview.set_hover(-1)
|
||||
)
|
||||
b.focus_entered.connect(d.preview.refresh)
|
||||
b.focus_exited.connect(d.preview.refresh.call_deferred)
|
||||
return b
|
||||
1
ui/choice_option_row.gd.uid
Normal file
1
ui/choice_option_row.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://7ncatbl0cnlv
|
||||
187
ui/choice_preview.gd
Normal file
187
ui/choice_preview.gd
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
class_name ChoicePreview
|
||||
extends RefCounted
|
||||
## The hover/focus preview panel beside a ChoiceDialog: the option's details,
|
||||
## effects and a TablePreview for each table it pipes to or mentions.
|
||||
|
||||
const PREVIEW_WIDTH := 350.0
|
||||
|
||||
var d: ChoiceDialog
|
||||
var hover := -1
|
||||
var shown_for := -2
|
||||
|
||||
|
||||
func _init(dialog: ChoiceDialog) -> void:
|
||||
d = dialog
|
||||
|
||||
|
||||
func set_hover(k: int) -> void:
|
||||
hover = k
|
||||
refresh()
|
||||
|
||||
|
||||
## Shows the preview for the hovered option, else the focused one, else (for
|
||||
## number and text questions) where the Answer leads.
|
||||
func refresh() -> void:
|
||||
if d.minimized or d.preview_panel == null or not d.is_inside_tree():
|
||||
return
|
||||
var idx := -1
|
||||
if d.kind == "pick":
|
||||
idx = hover
|
||||
if idx < 0:
|
||||
for k in d._options.size():
|
||||
if d._options[k].has_focus():
|
||||
idx = k
|
||||
break
|
||||
else:
|
||||
idx = 0
|
||||
if idx == shown_for:
|
||||
return
|
||||
shown_for = idx
|
||||
for c in d._preview_box.get_children():
|
||||
d._preview_box.remove_child(c)
|
||||
c.queue_free()
|
||||
var content := preview_for_option(idx) if idx >= 0 else null
|
||||
if content == null:
|
||||
d.preview_panel.hide()
|
||||
return
|
||||
d._preview_box.add_child(content)
|
||||
d.preview_panel.show()
|
||||
place()
|
||||
|
||||
|
||||
func hide() -> void:
|
||||
shown_for = -2
|
||||
if d.preview_panel:
|
||||
d.preview_panel.hide()
|
||||
|
||||
|
||||
## The entry behind option `k` (a position in the request's options; for
|
||||
## number and text questions, the single Answer entry), or null.
|
||||
func _entry_for(k: int) -> TableEntry:
|
||||
if d.board == null:
|
||||
return null
|
||||
var t := d.board.get_table(str(d.request.get("table_id", "")))
|
||||
if t == null:
|
||||
return null
|
||||
var index := k
|
||||
if d.kind == "pick":
|
||||
var opts: Array = d.request.get("options", [])
|
||||
if k < 0 or k >= opts.size():
|
||||
return null
|
||||
var o: Dictionary = opts[k]
|
||||
index = int(o.get("entry", o.get("index", k)))
|
||||
return t.entries[index] if index >= 0 and index < t.entries.size() else null
|
||||
|
||||
|
||||
## The preview content for option `k` as a Control, or null when there is
|
||||
## nothing to say. It holds the option's details and effects, then a
|
||||
## TablePreview for each table it pipes to (with its count) and each table
|
||||
## its text mentions with [[Table]].
|
||||
func preview_for_option(k: int) -> Control:
|
||||
var e := _entry_for(k)
|
||||
if e == null:
|
||||
return null
|
||||
var box := VBoxContainer.new()
|
||||
box.add_theme_constant_override("separation", 8)
|
||||
box.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.custom_minimum_size.x = PREVIEW_WIDTH - 28.0
|
||||
var heading := d.section(("Option %d" % (k + 1)) if d.kind == "pick" else "After you answer")
|
||||
heading.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.add_child(heading)
|
||||
var any := false
|
||||
var o: Dictionary = (d.request.get("options", []) as Array)[k] if d.kind == "pick" else {}
|
||||
var t := d.board.get_table(str(d.request.get("table_id", "")))
|
||||
if o.get("dynamic", false):
|
||||
# The variable (or list item) behind a dynamic option, and its value.
|
||||
any = true
|
||||
var what := "option = %s" % str(o.get("option", ""))
|
||||
if str(o.get("value_text", "")) != "":
|
||||
what += " · value %s" % str(o["value_text"])
|
||||
if d.plain:
|
||||
var src := RulesView.options_line(t, d.board, true) if t != null else ""
|
||||
what = "%s%s" % [Formatter.strip_tags(str(o.get("label", o.get("option", "")))), (" · level %s" % o["value_text"]) if str(o.get("value_text", "")) != "" else ""]
|
||||
if src != "":
|
||||
what += "\n" + src
|
||||
var ol := Style.make_label(what, Style.body_bold(), 13, Style.VALUE_INK)
|
||||
ol.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
ol.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.add_child(ol)
|
||||
var det := e.details.strip_edges()
|
||||
if det != "":
|
||||
any = true
|
||||
var dt := RichText.label(RichText.decorate(det), 14, Style.INK, false)
|
||||
dt.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.add_child(dt)
|
||||
var fx: Array = Describe.effects(e.effects, d.board, t) if d.plain else Array(Effects.split(e.effects))
|
||||
if not fx.is_empty():
|
||||
any = true
|
||||
box.add_child(_rule())
|
||||
box.add_child(d.section("When this comes up" if d.plain else "Effects"))
|
||||
for st: Variant in fx:
|
||||
var l := Style.make_label(str(st), Style.body_bold(), 13, Style.VALUE_INK)
|
||||
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
box.add_child(l)
|
||||
var shown: Array[String] = []
|
||||
for tid in e.pipes:
|
||||
shown.append(tid)
|
||||
any = true
|
||||
box.add_child(_rule())
|
||||
var how := Describe.pipe(e, tid, d.board) if d.plain else PipeLayer._pipe_tag(e, tid)
|
||||
if how != "":
|
||||
var hl := Style.make_label(("Then: " if d.plain else "thread: ") + how, Style.body_bold(), 12, Style.TRIM_DARK)
|
||||
hl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
hl.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
hl.set_meta("pipe_line", true)
|
||||
box.add_child(hl)
|
||||
box.add_child(TablePreview.build(d.board, tid, {"count": e.count_text(tid), "vars": d.vars, "plain": d.plain}))
|
||||
var mentioned: Array[String] = []
|
||||
for name in TextExpander.references(e.text, func(n: String) -> String: return Roller.resolve(d.board, n)):
|
||||
var rid := Roller.resolve(d.board, name)
|
||||
if rid != "" and not shown.has(rid) and not mentioned.has(rid):
|
||||
mentioned.append(rid)
|
||||
if not mentioned.is_empty():
|
||||
any = true
|
||||
box.add_child(_rule())
|
||||
box.add_child(d.section("Mentioned in the text"))
|
||||
for rid in mentioned:
|
||||
box.add_child(TablePreview.build(d.board, rid, {"vars": d.vars, "plain": d.plain}))
|
||||
if not any:
|
||||
box.free()
|
||||
return null
|
||||
return box
|
||||
|
||||
|
||||
func _rule() -> Control:
|
||||
var r := ColorRect.new()
|
||||
r.color = Style.RULE
|
||||
r.custom_minimum_size.y = 1
|
||||
r.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
return r
|
||||
|
||||
|
||||
## Beside the card (right if there is room, else left), top-aligned with it
|
||||
## and kept on screen. It never overlaps the card, so it never covers options.
|
||||
func place() -> void:
|
||||
if not d.preview_panel.visible:
|
||||
return
|
||||
var view := d.size
|
||||
var cr := d.card.get_global_rect()
|
||||
var gap := 18.0
|
||||
var right := view.x - cr.end.x - gap - 10.0
|
||||
var left := cr.position.x - gap - 10.0
|
||||
var w := PREVIEW_WIDTH
|
||||
var x: float
|
||||
if right >= w or right >= left:
|
||||
w = clampf(right, 180.0, PREVIEW_WIDTH)
|
||||
x = cr.end.x + gap
|
||||
else:
|
||||
w = clampf(left, 180.0, PREVIEW_WIDTH)
|
||||
x = cr.position.x - gap - w
|
||||
d.preview_panel.custom_minimum_size.x = w
|
||||
d.preview_panel.size = Vector2(w, 0)
|
||||
var h := d.preview_panel.get_combined_minimum_size().y
|
||||
var top := clampf(cr.position.y, 10.0, maxf(10.0, view.y - 10.0 - h))
|
||||
h = minf(h, view.y - top - 10.0)
|
||||
d.preview_panel.position = Vector2(x, top)
|
||||
d.preview_panel.size = Vector2(w, h)
|
||||
1
ui/choice_preview.gd.uid
Normal file
1
ui/choice_preview.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://elkuhosofvxx
|
||||
358
ui/table_card.gd
358
ui/table_card.gd
|
|
@ -49,6 +49,10 @@ var header_ui: TableCardHeader
|
|||
var rows_ui: TableCardRows
|
||||
var edit_ui: TableCardEditing
|
||||
var value_ui: TableCardValue
|
||||
var skin: TableCardSkin
|
||||
var input: TableCardInput
|
||||
var geometry: TableCardGeometry
|
||||
var list_ui: TableCardList
|
||||
## The ornamental border (null when the theme has none).
|
||||
var frame: CardFrame
|
||||
## The resize handle (CardGrip), kept as the last child.
|
||||
|
|
@ -83,32 +87,11 @@ func setup(p_main: Main, p_table: RollTable) -> void:
|
|||
theme = Style.card_theme()
|
||||
position = table.position
|
||||
|
||||
_style_normal = Style.box(Style.CARD, 10)
|
||||
if Style.CARD_FRAME == "ornate":
|
||||
_style_normal.set_content_margin_all(CardFrame.PAD)
|
||||
_style_normal.shadow_color = Color(0, 0, 0, 0.32)
|
||||
_style_normal.shadow_size = 16
|
||||
_style_normal.shadow_offset = Vector2(0, 8)
|
||||
_style_rolling = _style_normal.duplicate() as StyleBoxFlat
|
||||
Style.bordered(_style_rolling, 3, Style.ACCENT)
|
||||
_style_rolling.set_expand_margin_all(3)
|
||||
_style_rolling.shadow_color = Color(Style.ACCENT, 0.45)
|
||||
_style_rolling.shadow_size = 26
|
||||
_style_rolling.shadow_offset = Vector2.ZERO
|
||||
_style_drop = _style_rolling.duplicate() as StyleBoxFlat
|
||||
_style_drop.shadow_color = Color(0, 0, 0, 0.32)
|
||||
_style_drop.shadow_size = 16
|
||||
_style_drop.shadow_offset = Vector2(0, 8)
|
||||
_style_selected = _style_normal.duplicate() as StyleBoxFlat
|
||||
Style.bordered(_style_selected, 3, Style.TRIM)
|
||||
_style_selected.set_expand_margin_all(4)
|
||||
_style_selected.shadow_color = Color(Style.TRIM, 0.5)
|
||||
_style_selected.shadow_size = 14
|
||||
_style_selected.shadow_offset = Vector2.ZERO
|
||||
_style_dragging = _style_normal.duplicate() as StyleBoxFlat
|
||||
_style_dragging.shadow_color = Color(0, 0, 0, 0.4)
|
||||
_style_dragging.shadow_size = 26
|
||||
_style_dragging.shadow_offset = Vector2(0, 16)
|
||||
skin = TableCardSkin.new(self)
|
||||
input = TableCardInput.new(self)
|
||||
geometry = TableCardGeometry.new(self)
|
||||
list_ui = TableCardList.new(self)
|
||||
skin.build_styles()
|
||||
|
||||
if Style.CARD_FRAME == "ornate":
|
||||
frame = CardFrame.new()
|
||||
|
|
@ -126,17 +109,6 @@ func setup(p_main: Main, p_table: RollTable) -> void:
|
|||
rebuild()
|
||||
|
||||
|
||||
## The frame follows the card's own colour (RollTable.color), else the theme's.
|
||||
## Without a frame, the card's colour is a border instead.
|
||||
func _sync_frame() -> void:
|
||||
var own := Color.from_string(table.color, Color(0, 0, 0, 0)) if table.color != "" else Color(0, 0, 0, 0)
|
||||
if frame:
|
||||
frame.set_trim(own)
|
||||
else:
|
||||
for sb: StyleBoxFlat in [_style_normal, _style_dragging]:
|
||||
Style.bordered(sb, 3 if own.a > 0.0 else 0, own)
|
||||
|
||||
|
||||
func _on_rules_view_changed(_v: Variant = null) -> void:
|
||||
rebuild()
|
||||
|
||||
|
|
@ -147,7 +119,7 @@ func rebuild() -> void:
|
|||
continue
|
||||
remove_child(c)
|
||||
c.queue_free()
|
||||
_sync_frame()
|
||||
skin.sync_frame()
|
||||
rows.clear()
|
||||
rows_ui.clear()
|
||||
more_row = null
|
||||
|
|
@ -178,62 +150,27 @@ func rebuild() -> void:
|
|||
|
||||
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 = _make_warning()
|
||||
_warn_panel = skin.make_warning()
|
||||
col.add_child(_warn_panel)
|
||||
update_warning()
|
||||
if build:
|
||||
col.add_child(edit_ui.make_footer(ranged))
|
||||
_apply_style()
|
||||
skin.apply_style()
|
||||
refresh_live()
|
||||
_raise_covers()
|
||||
input.raise_covers()
|
||||
return
|
||||
|
||||
var pad := MarginContainer.new()
|
||||
pad.mouse_filter = MOUSE_FILTER_PASS
|
||||
pad.add_theme_constant_override("margin_top", 6)
|
||||
pad.add_theme_constant_override("margin_bottom", 8)
|
||||
_list_box = vbox(0)
|
||||
pad.add_child(_list_box)
|
||||
if not collapsed and (table.entries.size() > LONG_LIST or table.list_height > 0.0):
|
||||
list_scroll = ScrollContainer.new()
|
||||
list_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
list_scroll.custom_minimum_size = Vector2(0, table.list_height if table.list_height > 0.0 else LIST_HEIGHT)
|
||||
list_scroll.mouse_filter = MOUSE_FILTER_PASS
|
||||
_skin_scrollbar(list_scroll.get_v_scroll_bar())
|
||||
pad.size_flags_horizontal = SIZE_EXPAND_FILL
|
||||
list_scroll.add_child(pad)
|
||||
col.add_child(list_scroll)
|
||||
else:
|
||||
col.add_child(pad)
|
||||
list_ui.fill(col, build, ranged, collapsed)
|
||||
|
||||
var numw := _num_width(build, ranged)
|
||||
for i in table.entries.size():
|
||||
var e := table.entries[i]
|
||||
var lit := main.is_entry_lit(table.id, e.id)
|
||||
if collapsed and not lit:
|
||||
continue
|
||||
if table.kind == RollTable.KIND_SHEET:
|
||||
_list_box.add_child(rows_ui.make_sheet_row(e, build))
|
||||
elif table.kind == RollTable.KIND_ROUTER and build:
|
||||
_list_box.add_child(edit_ui.make_case_row(e, i, numw))
|
||||
elif table.kind == RollTable.KIND_CHECK:
|
||||
_list_box.add_child(rows_ui.make_check_row(e, i, build, numw))
|
||||
else:
|
||||
_list_box.add_child(rows_ui.make_row(e, i, build, ranged, numw))
|
||||
rows_ui.set_row_state(e.id, TableCardRows.RowState.LIT if lit else TableCardRows.RowState.NORMAL)
|
||||
if collapsed:
|
||||
more_row = rows_ui.make_more_row(numw)
|
||||
_list_box.add_child(more_row)
|
||||
|
||||
_warn_panel = _make_warning()
|
||||
_warn_panel = skin.make_warning()
|
||||
col.add_child(_warn_panel)
|
||||
update_warning()
|
||||
if build:
|
||||
col.add_child(edit_ui.make_footer(ranged))
|
||||
_apply_style()
|
||||
skin.apply_style()
|
||||
refresh_live()
|
||||
_raise_covers()
|
||||
_dim_drawn()
|
||||
input.raise_covers()
|
||||
skin.dim_drawn()
|
||||
if list_scroll != null:
|
||||
for eid in rows:
|
||||
if main.is_entry_lit(table.id, eid):
|
||||
|
|
@ -298,50 +235,6 @@ static func check_outlet_name(index: int) -> String:
|
|||
return TableCardText.check_outlet_name(index)
|
||||
|
||||
|
||||
func _make_warning() -> Control:
|
||||
var wrap := MarginContainer.new()
|
||||
wrap.mouse_filter = MOUSE_FILTER_PASS
|
||||
wrap.add_theme_constant_override("margin_left", 12)
|
||||
wrap.add_theme_constant_override("margin_right", 12)
|
||||
wrap.add_theme_constant_override("margin_bottom", 10)
|
||||
var panel := PanelContainer.new()
|
||||
panel.add_theme_stylebox_override("panel", Style.box(Style.WARN_BG, 6, [9, 6, 9, 6]))
|
||||
panel.mouse_filter = MOUSE_FILTER_PASS
|
||||
_warn_label = Style.make_label("", Style.body(true), 13, Style.WARN_INK)
|
||||
_warn_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
panel.add_child(_warn_label)
|
||||
wrap.add_child(panel)
|
||||
return wrap
|
||||
|
||||
|
||||
func update_warning() -> void:
|
||||
var problems := table.range_problems()
|
||||
var lines := PackedStringArray()
|
||||
for item: Dictionary in Roller.lint_router(table):
|
||||
lines.append(str(item["message"]))
|
||||
for item: Dictionary in Roller.lint_options(table):
|
||||
lines.append(str(item["message"]))
|
||||
if not lines.is_empty():
|
||||
problems = ("%s\n" % problems if problems != "" else "") + "\n".join(lines)
|
||||
_warn_label.text = problems
|
||||
_warn_panel.visible = problems != ""
|
||||
if is_instance_valid(header_ui.roll_button):
|
||||
var back := RollRange.backwards(table) != ""
|
||||
header_ui.roll_button.disabled = back
|
||||
header_ui.roll_button.modulate.a = 0.4 if back else 1.0
|
||||
|
||||
|
||||
func _skin_scrollbar(bar: VScrollBar) -> void:
|
||||
var track := Style.box(Color(0, 0, 0, 0), 3, [3, 0, 3, 0])
|
||||
var grab := Style.box(Color(0, 0, 0, 0.22), 3, [3, 0, 3, 0])
|
||||
var grab_hi := Style.box(Color(0, 0, 0, 0.35), 3, [3, 0, 3, 0])
|
||||
bar.add_theme_stylebox_override("scroll", track)
|
||||
bar.add_theme_stylebox_override("scroll_focus", track)
|
||||
bar.add_theme_stylebox_override("grabber", grab)
|
||||
bar.add_theme_stylebox_override("grabber_highlight", grab_hi)
|
||||
bar.add_theme_stylebox_override("grabber_pressed", grab_hi)
|
||||
|
||||
|
||||
# ---------- State ----------
|
||||
|
||||
## Selects a result for the inspector: main.select_result(table id, entry id)
|
||||
|
|
@ -376,22 +269,7 @@ func selected_entry() -> String:
|
|||
## Refreshes the cards-left count of a card-mode table.
|
||||
func update_deck() -> void:
|
||||
header_ui.update_deck()
|
||||
_dim_drawn()
|
||||
|
||||
|
||||
## Deck mode: results already drawn (none left in the deck) show faded until
|
||||
## the deck is shuffled.
|
||||
func _dim_drawn() -> void:
|
||||
if not table.card_mode:
|
||||
return
|
||||
var deck: DeckState = main.decks.get(table.id)
|
||||
for e in table.entries:
|
||||
var row: Control = rows.get(e.id)
|
||||
if row == null or not is_instance_valid(row):
|
||||
continue
|
||||
var gone := deck != null and deck.remaining(table, e) <= 0
|
||||
row.modulate.a = 0.38 if gone else 1.0
|
||||
row.tooltip_text = "Already drawn: Shuffle the deck to put it back" if gone else ""
|
||||
skin.dim_drawn()
|
||||
|
||||
|
||||
## Re-renders the live parts (a variable's value, a sheet, a choice's
|
||||
|
|
@ -404,24 +282,11 @@ func refresh_live() -> void:
|
|||
header_ui.refresh_live()
|
||||
|
||||
|
||||
func _apply_style() -> void:
|
||||
var s := _style_normal
|
||||
if _drop_target:
|
||||
s = _style_drop
|
||||
elif _rolling:
|
||||
s = _style_rolling
|
||||
elif _selected:
|
||||
s = _style_selected
|
||||
elif _dragging:
|
||||
s = _style_dragging
|
||||
add_theme_stylebox_override("panel", s)
|
||||
|
||||
|
||||
## Build-mode selection (Main.selection): a copper ring around the card.
|
||||
func set_selected(on: bool) -> void:
|
||||
if _selected != on:
|
||||
_selected = on
|
||||
_apply_style()
|
||||
skin.apply_style()
|
||||
|
||||
|
||||
func is_selected() -> bool:
|
||||
|
|
@ -450,34 +315,16 @@ func list_area_height() -> float:
|
|||
return 0.0
|
||||
|
||||
|
||||
## Sets the size the user dragged to (0 = automatic) and lays the card out
|
||||
## again: cheaply while a scrolling list just changes height, else rebuilt.
|
||||
func set_user_size(w: float, list_h: float) -> void:
|
||||
if table.kind == RollTable.KIND_VARIABLE or is_collapsed():
|
||||
list_h = 0.0
|
||||
var rebuild_needed := (list_h > 0.0) != is_instance_valid(list_scroll) or (list_h == 0.0 and table.list_height > 0.0)
|
||||
table.width = w
|
||||
table.list_height = list_h
|
||||
if rebuild_needed:
|
||||
rebuild()
|
||||
else:
|
||||
custom_minimum_size.x = card_width()
|
||||
if is_instance_valid(list_scroll) and list_h > 0.0:
|
||||
list_scroll.custom_minimum_size.y = list_h
|
||||
_shrink()
|
||||
main.board.geometry_rev += 1
|
||||
|
||||
|
||||
func set_rolling(on: bool) -> void:
|
||||
_rolling = on
|
||||
if is_instance_valid(header_ui.die_icon):
|
||||
header_ui.die_icon.spinning = on
|
||||
_apply_style()
|
||||
skin.apply_style()
|
||||
|
||||
|
||||
func set_drop_target(on: bool) -> void:
|
||||
_drop_target = on
|
||||
_apply_style()
|
||||
skin.apply_style()
|
||||
|
||||
|
||||
func flick_random() -> void:
|
||||
|
|
@ -493,137 +340,52 @@ func set_more_text(text: String) -> void:
|
|||
rows_ui.more_label.text = text
|
||||
|
||||
|
||||
## Updates highlights after a roll. Collapsed cards rebuild so the rolled result shows.
|
||||
func refresh_lit() -> void:
|
||||
update_deck()
|
||||
if is_collapsed():
|
||||
var want: Array = []
|
||||
for e in table.entries:
|
||||
if main.is_entry_lit(table.id, e.id):
|
||||
want.append(e.id)
|
||||
if want != rows.keys():
|
||||
rebuild()
|
||||
elif rows_ui.more_label:
|
||||
rows_ui.more_label.text = rows_ui.more_text()
|
||||
return
|
||||
for eid in rows:
|
||||
rows_ui.update_row_text(eid)
|
||||
rows_ui.restate(eid)
|
||||
|
||||
|
||||
## Scrolls a long list so the given result sits in the middle.
|
||||
func reveal(eid: String) -> void:
|
||||
if list_scroll == null or not rows.has(eid):
|
||||
return
|
||||
var row: Control = rows[eid]
|
||||
list_scroll.scroll_vertical = int(row.position.y + 6.0 - list_scroll.size.y / 2.0 + row.size.y / 2.0)
|
||||
|
||||
|
||||
## A burst of sparkles over a result as it lands.
|
||||
func sparkle(eid: String) -> void:
|
||||
var row: Control = rows.get(eid)
|
||||
if row and row.is_inside_tree() and row.is_visible_in_tree():
|
||||
# Into the card layer, so a rebuild of this card doesn't cut it short.
|
||||
var at := get_global_transform().affine_inverse() * row.get_global_transform().origin
|
||||
Sparkles.burst(get_parent(), Rect2(position + at, row.size))
|
||||
|
||||
|
||||
func hidden_has_pipes() -> bool:
|
||||
for e in table.entries:
|
||||
if not rows.has(e.id) and (not e.pipes.is_empty() or not main.ref_targets_for(e).is_empty()):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
# ---------- Geometry (world coordinates) ----------
|
||||
|
||||
func inlet_point() -> Vector2:
|
||||
return Vector2(position.x, position.y + INLET_Y)
|
||||
|
||||
|
||||
## Where a pipe leaves this card for an entry: its row, or the "more" row when the
|
||||
## entry is hidden in a collapsed card. Rows scrolled out of a long list clamp to
|
||||
## its edge. Returns {} if there's nowhere to anchor.
|
||||
func anchor_for(eid: String) -> Dictionary:
|
||||
var row: Control = rows.get(eid, more_row)
|
||||
if row == null or not row.is_inside_tree():
|
||||
return {}
|
||||
var to_world := main.board.world.get_global_transform().affine_inverse()
|
||||
var r := row.get_global_rect()
|
||||
var y := (to_world * (r.position + Vector2(0, r.size.y / 2.0))).y
|
||||
var shown := true
|
||||
if list_scroll != null and rows.has(eid):
|
||||
var sr := list_scroll.get_global_rect()
|
||||
var top := (to_world * sr.position).y + 14.0
|
||||
var bottom := (to_world * sr.end).y - 14.0
|
||||
shown = y >= top - 4.0 and y <= bottom + 4.0
|
||||
y = clampf(y, top, bottom)
|
||||
return {"pos": Vector2(position.x + size.x, y), "visible": shown}
|
||||
|
||||
|
||||
# ---------- Input ----------
|
||||
|
||||
|
||||
# ---------- Delegates (the helpers hold the code; these keep the public API) ----------
|
||||
|
||||
func update_warning() -> void:
|
||||
skin.update_warning()
|
||||
|
||||
|
||||
func set_user_size(w: float, list_h: float) -> void:
|
||||
geometry.set_user_size(w, list_h)
|
||||
|
||||
|
||||
func inlet_point() -> Vector2:
|
||||
return geometry.inlet_point()
|
||||
|
||||
|
||||
func anchor_for(eid: String) -> Dictionary:
|
||||
return geometry.anchor_for(eid)
|
||||
|
||||
|
||||
func _gui_input(ev: InputEvent) -> void:
|
||||
# Clicks on the card body shouldn't pan the board; the wheel still passes through.
|
||||
var mb := ev as InputEventMouseButton
|
||||
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
|
||||
accept_event()
|
||||
elif open_menu_on(mb):
|
||||
accept_event()
|
||||
input.gui_input(ev)
|
||||
|
||||
|
||||
## The grip, then the zoomed-out shield, stay on top of the rebuilt content.
|
||||
func _raise_covers() -> void:
|
||||
move_child(grip, -1)
|
||||
move_child(shield, -1)
|
||||
shield.set_name_tip(Formatter.strip_tags(table.name))
|
||||
if table.kind == RollTable.KIND_VARIABLE:
|
||||
shield.on_roll = Callable()
|
||||
|
||||
|
||||
## Right-click: the card's actions menu (Actions.card). True when it opened.
|
||||
func open_menu_on(mb: InputEventMouseButton) -> bool:
|
||||
if mb == null:
|
||||
return false
|
||||
if mb == null or mb.button_index != MOUSE_BUTTON_RIGHT or not mb.pressed:
|
||||
return false
|
||||
main.details().hide_for()
|
||||
Actions.popup_at(main, Actions.card(main, table), mb.global_position)
|
||||
return true
|
||||
return input.open_menu_on(mb)
|
||||
|
||||
|
||||
## Dragging the header moves the card (and, in Build, every selected card).
|
||||
## In Build, Ctrl- or Shift-click adds the card to the selection or takes it
|
||||
## out; dropping a card into a group frame adds it to that group (Main).
|
||||
func _on_header_input(ev: InputEvent, header: Control) -> void:
|
||||
var mb := ev as InputEventMouseButton
|
||||
if open_menu_on(mb):
|
||||
header.accept_event()
|
||||
return
|
||||
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
|
||||
if mb.pressed:
|
||||
main.details().hide_for()
|
||||
var build := main.mode == Main.Mode.BUILD
|
||||
if build and (mb.ctrl_pressed or mb.shift_pressed or mb.meta_pressed):
|
||||
main.toggle_selected(table.id)
|
||||
header.accept_event()
|
||||
return
|
||||
if build and not main.is_selected(table.id):
|
||||
main.clear_selection()
|
||||
_dragging = true
|
||||
_drag_offset = main.board.world_mouse() - position
|
||||
get_parent().move_child(self, -1)
|
||||
main.begin_card_drag(self)
|
||||
elif _dragging:
|
||||
_dragging = false
|
||||
main.end_card_drag(self)
|
||||
else:
|
||||
main.mark_dirty()
|
||||
_apply_style()
|
||||
header.accept_event()
|
||||
return
|
||||
var mm := ev as InputEventMouseMotion
|
||||
if mm and _dragging:
|
||||
var p := main.board.world_mouse() - _drag_offset
|
||||
main.drag_card(self, p.round())
|
||||
header.accept_event()
|
||||
input.on_header_input(ev, header)
|
||||
|
||||
|
||||
func refresh_lit() -> void:
|
||||
list_ui.refresh_lit()
|
||||
|
||||
|
||||
func reveal(eid: String) -> void:
|
||||
list_ui.reveal(eid)
|
||||
|
||||
|
||||
func sparkle(eid: String) -> void:
|
||||
list_ui.sparkle(eid)
|
||||
|
||||
|
||||
func hidden_has_pipes() -> bool:
|
||||
return list_ui.hidden_has_pipes()
|
||||
|
|
|
|||
51
ui/table_card_geometry.gd
Normal file
51
ui/table_card_geometry.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
class_name TableCardGeometry
|
||||
extends RefCounted
|
||||
## Where things are on a card, in world coordinates, and user resizing.
|
||||
|
||||
var card: TableCard
|
||||
|
||||
|
||||
func _init(p_card: TableCard) -> void:
|
||||
card = p_card
|
||||
|
||||
|
||||
func inlet_point() -> Vector2:
|
||||
return Vector2(card.position.x, card.position.y + TableCard.INLET_Y)
|
||||
|
||||
|
||||
## Where a pipe leaves this card for an entry: its row, or the "more" row when the
|
||||
## entry is hidden in a collapsed card. Rows scrolled out of a long list clamp to
|
||||
## its edge. Returns {} if there's nowhere to anchor.
|
||||
func anchor_for(eid: String) -> Dictionary:
|
||||
var row: Control = card.rows.get(eid, card.more_row)
|
||||
if row == null or not row.is_inside_tree():
|
||||
return {}
|
||||
var to_world := card.main.board.world.get_global_transform().affine_inverse()
|
||||
var r := row.get_global_rect()
|
||||
var y := (to_world * (r.position + Vector2(0, r.size.y / 2.0))).y
|
||||
var shown := true
|
||||
if card.list_scroll != null and card.rows.has(eid):
|
||||
var sr := card.list_scroll.get_global_rect()
|
||||
var top := (to_world * sr.position).y + 14.0
|
||||
var bottom := (to_world * sr.end).y - 14.0
|
||||
shown = y >= top - 4.0 and y <= bottom + 4.0
|
||||
y = clampf(y, top, bottom)
|
||||
return {"pos": Vector2(card.position.x + card.size.x, y), "visible": shown}
|
||||
|
||||
|
||||
## Sets the size the user dragged to (0 = automatic) and lays the card out
|
||||
## again: cheaply while a scrolling list just changes height, else rebuilt.
|
||||
func set_user_size(w: float, list_h: float) -> void:
|
||||
if card.table.kind == RollTable.KIND_VARIABLE or card.is_collapsed():
|
||||
list_h = 0.0
|
||||
var rebuild_needed := (list_h > 0.0) != is_instance_valid(card.list_scroll) or (list_h == 0.0 and card.table.list_height > 0.0)
|
||||
card.table.width = w
|
||||
card.table.list_height = list_h
|
||||
if rebuild_needed:
|
||||
card.rebuild()
|
||||
else:
|
||||
card.custom_minimum_size.x = card.card_width()
|
||||
if is_instance_valid(card.list_scroll) and list_h > 0.0:
|
||||
card.list_scroll.custom_minimum_size.y = list_h
|
||||
card._shrink()
|
||||
card.main.board.geometry_rev += 1
|
||||
1
ui/table_card_geometry.gd.uid
Normal file
1
ui/table_card_geometry.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b0yf1ayoinso8
|
||||
75
ui/table_card_input.gd
Normal file
75
ui/table_card_input.gd
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
class_name TableCardInput
|
||||
extends RefCounted
|
||||
## Mouse input on a card: the context menu and dragging by the header.
|
||||
|
||||
var card: TableCard
|
||||
|
||||
|
||||
func _init(p_card: TableCard) -> void:
|
||||
card = p_card
|
||||
|
||||
|
||||
func gui_input(ev: InputEvent) -> void:
|
||||
# Clicks on the card body shouldn't pan the board; the wheel still passes through.
|
||||
var mb := ev as InputEventMouseButton
|
||||
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
|
||||
card.accept_event()
|
||||
elif open_menu_on(mb):
|
||||
card.accept_event()
|
||||
|
||||
|
||||
## The grip, then the zoomed-out shield, stay on top of the rebuilt content.
|
||||
func raise_covers() -> void:
|
||||
card.move_child(card.grip, -1)
|
||||
card.move_child(card.shield, -1)
|
||||
card.shield.set_name_tip(Formatter.strip_tags(card.table.name))
|
||||
if card.table.kind == RollTable.KIND_VARIABLE:
|
||||
card.shield.on_roll = Callable()
|
||||
|
||||
|
||||
## Right-click: the card's actions menu (Actions.card). True when it opened.
|
||||
func open_menu_on(mb: InputEventMouseButton) -> bool:
|
||||
if mb == null:
|
||||
return false
|
||||
if mb == null or mb.button_index != MOUSE_BUTTON_RIGHT or not mb.pressed:
|
||||
return false
|
||||
card.main.details().hide_for()
|
||||
Actions.popup_at(card.main, Actions.card(card.main, card.table), mb.global_position)
|
||||
return true
|
||||
|
||||
|
||||
## Dragging the header moves the card (and, in Build, every selected card).
|
||||
## In Build, Ctrl- or Shift-click adds the card to the selection or takes it
|
||||
## out; dropping a card into a group frame adds it to that group (Main).
|
||||
func on_header_input(ev: InputEvent, header: Control) -> void:
|
||||
var mb := ev as InputEventMouseButton
|
||||
if open_menu_on(mb):
|
||||
header.accept_event()
|
||||
return
|
||||
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
|
||||
if mb.pressed:
|
||||
card.main.details().hide_for()
|
||||
var build := card.main.mode == Main.Mode.BUILD
|
||||
if build and (mb.ctrl_pressed or mb.shift_pressed or mb.meta_pressed):
|
||||
card.main.toggle_selected(card.table.id)
|
||||
header.accept_event()
|
||||
return
|
||||
if build and not card.main.is_selected(card.table.id):
|
||||
card.main.clear_selection()
|
||||
card._dragging = true
|
||||
card._drag_offset = card.main.board.world_mouse() - card.position
|
||||
card.get_parent().move_child(card, -1)
|
||||
card.main.begin_card_drag(card)
|
||||
elif card._dragging:
|
||||
card._dragging = false
|
||||
card.main.end_card_drag(card)
|
||||
else:
|
||||
card.main.mark_dirty()
|
||||
card.skin.apply_style()
|
||||
header.accept_event()
|
||||
return
|
||||
var mm := ev as InputEventMouseMotion
|
||||
if mm and card._dragging:
|
||||
var p := card.main.board.world_mouse() - card._drag_offset
|
||||
card.main.drag_card(card, p.round())
|
||||
header.accept_event()
|
||||
1
ui/table_card_input.gd.uid
Normal file
1
ui/table_card_input.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://04buql2wav2u
|
||||
134
ui/table_card_kind_rows.gd
Normal file
134
ui/table_card_kind_rows.gd
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
class_name TableCardKindRows
|
||||
extends RefCounted
|
||||
## The check-outlet and sheet rows of a TableCard (TableCardRows delegates here).
|
||||
|
||||
var rows: TableCardRows
|
||||
var card: TableCard
|
||||
|
||||
|
||||
func _init(p_rows: TableCardRows) -> void:
|
||||
rows = p_rows
|
||||
card = p_rows.card
|
||||
|
||||
|
||||
## One outlet of a check card: "8+ Success · the bars give" / "≤7 Failure",
|
||||
## with the outlet named in green or red. Build edits the text after the name.
|
||||
func make_check_row(e: TableEntry, index: int, build: bool, numw: float) -> Control:
|
||||
var table := card.table
|
||||
var main := card.main
|
||||
var row := PanelContainer.new()
|
||||
row.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
row.custom_minimum_size = Vector2(0, 36)
|
||||
var h := TableCard.hbox(8)
|
||||
row.add_child(h)
|
||||
var outs := RulesView.check_outlets(table)
|
||||
var num := Style.make_label(outs[index] if index < 2 else str(index + 1), Style.display(true), 16, Style.MUTED)
|
||||
num.custom_minimum_size = Vector2(maxf(numw, 34.0), 0)
|
||||
num.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
||||
num.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
h.add_child(num)
|
||||
var col := TableCard.vbox(2)
|
||||
col.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
col.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
h.add_child(col)
|
||||
var text: RichTextLabel = null
|
||||
if build:
|
||||
var line := TableCard.hbox(6)
|
||||
col.add_child(line)
|
||||
var nm := Style.make_label(TableCardText.check_outlet_name(index), Style.body_bold(true), 15, TableCardText.check_outlet_color(index))
|
||||
nm.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
line.add_child(nm)
|
||||
var edit := card.edit_ui.text_edit(e, index, false)
|
||||
# The outlet name is already shown, so a result text that just repeats
|
||||
# it ("Success") shows as an empty field with a hint instead.
|
||||
if e.text.strip_edges() == TableCardText.check_outlet_name(index):
|
||||
edit.text = ""
|
||||
edit.placeholder_text = "What happens on a %s (optional)" % TableCardText.check_outlet_name(index).to_lower()
|
||||
line.add_child(edit)
|
||||
rows.add_rule_chips(col, e)
|
||||
card.edit_ui.hook_select(row, e.id)
|
||||
else:
|
||||
text = RichText.label(rows.row_text(e), 16, Style.INK, true)
|
||||
text.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
RichText.hook_hover(text, main)
|
||||
col.add_child(text)
|
||||
rows.add_rule_chips(col, e)
|
||||
row.mouse_entered.connect(func() -> void: main.details().show_entry(row, table.id, e.id))
|
||||
rows.register(e, row, num, text, index)
|
||||
return row
|
||||
|
||||
|
||||
## A sheet card's one row: the rendered template in Play, its editor in Build.
|
||||
func make_sheet_row(e: TableEntry, build: bool) -> Control:
|
||||
var main := card.main
|
||||
var row := PanelContainer.new()
|
||||
row.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
row.custom_minimum_size = Vector2(0, 36)
|
||||
var v := TableCard.vbox(6)
|
||||
row.add_child(v)
|
||||
if build:
|
||||
var te := TextEdit.new()
|
||||
te.text = e.text
|
||||
te.placeholder_text = "[b]Name[/b] {@name}\nHP {@hp} · Skills {@skill_*}"
|
||||
te.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY
|
||||
te.custom_minimum_size = Vector2(0, 90)
|
||||
te.scroll_fit_content_height = true
|
||||
te.add_theme_font_override("font", Style.body(true))
|
||||
te.add_theme_font_size_override("font_size", 14)
|
||||
te.add_theme_color_override("font_color", Style.INK)
|
||||
te.add_theme_color_override("font_placeholder_color", Style.MUTED)
|
||||
te.add_theme_color_override("caret_color", Style.INK)
|
||||
te.add_theme_color_override("selection_color", Color(Style.ACCENT, 0.55))
|
||||
te.add_theme_stylebox_override("normal", Style.bordered(Style.box(Color.WHITE, 5, [7, 4, 7, 4]), 1, Style.RULE))
|
||||
te.add_theme_stylebox_override("focus", Style.bordered(Style.box(Color.WHITE, 5, [7, 4, 7, 4]), 1, Style.TRIM))
|
||||
te.tooltip_text = "The sheet's template: BBCode with {@var}, {@prefix_*} and {= expr}"
|
||||
te.text_changed.connect(func() -> void:
|
||||
e.text = te.text
|
||||
e.page = ""
|
||||
main.mark_dirty()
|
||||
)
|
||||
te.focus_entered.connect(func() -> void: card.select_entry(e.id))
|
||||
v.add_child(te)
|
||||
var tools := TableCard.vbox(2)
|
||||
if e.effects.strip_edges() != "":
|
||||
tools.add_child(effects_chip(e))
|
||||
var pv := Style.make_label("Preview on the spread in Play", Style.body_italic(true), 12, Style.MUTED)
|
||||
pv.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
tools.add_child(pv)
|
||||
v.add_child(tools)
|
||||
card.edit_ui.hook_select(row, e.id)
|
||||
rows.sheet_label = null
|
||||
else:
|
||||
rows.sheet_label = RichText.label("", 15, Style.INK, true)
|
||||
rows.sheet_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
RichText.hook_hover(rows.sheet_label, main)
|
||||
v.add_child(rows.sheet_label)
|
||||
row.mouse_entered.connect(func() -> void: main.details().show_entry(row, card.table.id, e.id))
|
||||
rows.register(e, row, null, null, 0)
|
||||
return row
|
||||
|
||||
|
||||
## A subtle brass chip summarising an entry's effects: "Luck −1 · Gold + 2D"
|
||||
## in plain words, "@luck -= 1 · @gold += 2d6" as text. Its tooltip has the
|
||||
## other form, every statement on its own line.
|
||||
func effects_chip(e: TableEntry) -> Control:
|
||||
var plain := card.plain
|
||||
var bad := not Effects.validate(TemplateKit.probe(e.effects)).is_empty()
|
||||
var chip := PanelContainer.new()
|
||||
chip.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
chip.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
|
||||
var bg := Color(Style.DANGER_INK, 0.1) if bad else Color(Style.ACCENT, 0.2)
|
||||
var line := Color(Style.DANGER_INK, 0.4) if bad else Color(Style.ACCENT_DARK, 0.3)
|
||||
chip.add_theme_stylebox_override("panel", Style.bordered(Style.box(bg, 5, [6, 0, 6, 1]), 1, line))
|
||||
var summary := RulesView.effects_line(e.effects, card.main.data, card.table, plain)
|
||||
# Cut long summaries by hand: a clipped Label would collapse to nothing.
|
||||
summary = RulesView.cut(summary, TableCardRows.PLAIN_CHIP_CHARS if plain else TableCardRows.CHIP_CHARS)
|
||||
var l := Style.make_label(summary, Style.body_bold(true) if plain else Style.body(true), 12, Style.DANGER_INK if bad else Style.TRIM_DARK)
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
chip.add_child(l)
|
||||
chip.set_meta("effects_chip", summary)
|
||||
if plain:
|
||||
chip.tooltip_text = "\n".join(Effects.split(e.effects))
|
||||
else:
|
||||
chip.tooltip_text = "\n".join(Describe.effects(e.effects, card.main.data, card.table))
|
||||
return chip
|
||||
1
ui/table_card_kind_rows.gd.uid
Normal file
1
ui/table_card_kind_rows.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bt2yi8813tfkt
|
||||
90
ui/table_card_list.gd
Normal file
90
ui/table_card_list.gd
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
class_name TableCardList
|
||||
extends RefCounted
|
||||
## Builds the scrolling or plain list of result rows inside a TableCard.
|
||||
|
||||
var card: TableCard
|
||||
|
||||
|
||||
func _init(p_card: TableCard) -> void:
|
||||
card = p_card
|
||||
|
||||
|
||||
func fill(col: VBoxContainer, build: bool, ranged: bool, collapsed: bool) -> void:
|
||||
var pad := MarginContainer.new()
|
||||
pad.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
pad.add_theme_constant_override("margin_top", 6)
|
||||
pad.add_theme_constant_override("margin_bottom", 8)
|
||||
card._list_box = TableCard.vbox(0)
|
||||
pad.add_child(card._list_box)
|
||||
if not collapsed and (card.table.entries.size() > TableCard.LONG_LIST or card.table.list_height > 0.0):
|
||||
card.list_scroll = ScrollContainer.new()
|
||||
card.list_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
card.list_scroll.custom_minimum_size = Vector2(0, card.table.list_height if card.table.list_height > 0.0 else TableCard.LIST_HEIGHT)
|
||||
card.list_scroll.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
card.skin.skin_scrollbar(card.list_scroll.get_v_scroll_bar())
|
||||
pad.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
card.list_scroll.add_child(pad)
|
||||
col.add_child(card.list_scroll)
|
||||
else:
|
||||
col.add_child(pad)
|
||||
|
||||
var numw := card._num_width(build, ranged)
|
||||
for i in card.table.entries.size():
|
||||
var e := card.table.entries[i]
|
||||
var lit := card.main.is_entry_lit(card.table.id, e.id)
|
||||
if collapsed and not lit:
|
||||
continue
|
||||
if card.table.kind == RollTable.KIND_SHEET:
|
||||
card._list_box.add_child(card.rows_ui.make_sheet_row(e, build))
|
||||
elif card.table.kind == RollTable.KIND_ROUTER and build:
|
||||
card._list_box.add_child(card.edit_ui.make_case_row(e, i, numw))
|
||||
elif card.table.kind == RollTable.KIND_CHECK:
|
||||
card._list_box.add_child(card.rows_ui.make_check_row(e, i, build, numw))
|
||||
else:
|
||||
card._list_box.add_child(card.rows_ui.make_row(e, i, build, ranged, numw))
|
||||
card.rows_ui.set_row_state(e.id, TableCardRows.RowState.LIT if lit else TableCardRows.RowState.NORMAL)
|
||||
if collapsed:
|
||||
card.more_row = card.rows_ui.make_more_row(numw)
|
||||
card._list_box.add_child(card.more_row)
|
||||
|
||||
|
||||
## Updates highlights after a roll. Collapsed cards rebuild so the rolled result shows.
|
||||
func refresh_lit() -> void:
|
||||
card.update_deck()
|
||||
if card.is_collapsed():
|
||||
var want: Array = []
|
||||
for e in card.table.entries:
|
||||
if card.main.is_entry_lit(card.table.id, e.id):
|
||||
want.append(e.id)
|
||||
if want != card.rows.keys():
|
||||
card.rebuild()
|
||||
elif card.rows_ui.more_label:
|
||||
card.rows_ui.more_label.text = card.rows_ui.more_text()
|
||||
return
|
||||
for eid in card.rows:
|
||||
card.rows_ui.update_row_text(eid)
|
||||
card.rows_ui.restate(eid)
|
||||
|
||||
|
||||
## Scrolls a long list so the given result sits in the middle.
|
||||
func reveal(eid: String) -> void:
|
||||
if card.list_scroll == null or not card.rows.has(eid):
|
||||
return
|
||||
var row: Control = card.rows[eid]
|
||||
card.list_scroll.scroll_vertical = int(row.position.y + 6.0 - card.list_scroll.size.y / 2.0 + row.size.y / 2.0)
|
||||
|
||||
|
||||
## A burst of sparkles over a result as it lands.
|
||||
func sparkle(eid: String) -> void:
|
||||
var row: Control = card.rows.get(eid)
|
||||
if row and row.is_inside_tree() and row.is_visible_in_tree():
|
||||
# Into the card layer, so a rebuild of this card doesn't cut it short.
|
||||
var at := card.get_global_transform().affine_inverse() * row.get_global_transform().origin
|
||||
Sparkles.burst(card.get_parent(), Rect2(card.position + at, row.size))
|
||||
|
||||
|
||||
func hidden_has_pipes() -> bool:
|
||||
for e in card.table.entries:
|
||||
if not card.rows.has(e.id) and (not e.pipes.is_empty() or not card.main.ref_targets_for(e).is_empty()):
|
||||
return true
|
||||
return false
|
||||
1
ui/table_card_list.gd.uid
Normal file
1
ui/table_card_list.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bfpfx7thdh0jr
|
||||
|
|
@ -18,6 +18,7 @@ var card: TableCard
|
|||
var parts: Dictionary = {}
|
||||
var more_label: Label
|
||||
var sheet_label: RichTextLabel
|
||||
var kind_rows: TableCardKindRows
|
||||
|
||||
## Row styles by state, then +3 for the inspector's selected result, then +6
|
||||
## for a striped (every second) row.
|
||||
|
|
@ -30,6 +31,7 @@ var _odds: Dictionary = {}
|
|||
|
||||
func _init(p_card: TableCard) -> void:
|
||||
card = p_card
|
||||
kind_rows = TableCardKindRows.new(self)
|
||||
# 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
|
||||
# the flicker and the lit result always read over the stripe.
|
||||
|
|
@ -194,54 +196,7 @@ func add_rule_chips(col: VBoxContainer, e: TableEntry) -> void:
|
|||
si.set_meta("show_if_line", true)
|
||||
col.add_child(si)
|
||||
if e.effects.strip_edges() != "":
|
||||
col.add_child(_effects_chip(e))
|
||||
|
||||
|
||||
## One outlet of a check card: "8+ Success · the bars give" / "≤7 Failure",
|
||||
## with the outlet named in green or red. Build edits the text after the name.
|
||||
func make_check_row(e: TableEntry, index: int, build: bool, numw: float) -> Control:
|
||||
var table := card.table
|
||||
var main := card.main
|
||||
var row := PanelContainer.new()
|
||||
row.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
row.custom_minimum_size = Vector2(0, 36)
|
||||
var h := TableCard.hbox(8)
|
||||
row.add_child(h)
|
||||
var outs := RulesView.check_outlets(table)
|
||||
var num := Style.make_label(outs[index] if index < 2 else str(index + 1), Style.display(true), 16, Style.MUTED)
|
||||
num.custom_minimum_size = Vector2(maxf(numw, 34.0), 0)
|
||||
num.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
||||
num.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
h.add_child(num)
|
||||
var col := TableCard.vbox(2)
|
||||
col.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
col.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
h.add_child(col)
|
||||
var text: RichTextLabel = null
|
||||
if build:
|
||||
var line := TableCard.hbox(6)
|
||||
col.add_child(line)
|
||||
var nm := Style.make_label(TableCardText.check_outlet_name(index), Style.body_bold(true), 15, TableCardText.check_outlet_color(index))
|
||||
nm.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
line.add_child(nm)
|
||||
var edit := card.edit_ui.text_edit(e, index, false)
|
||||
# The outlet name is already shown, so a result text that just repeats
|
||||
# it ("Success") shows as an empty field with a hint instead.
|
||||
if e.text.strip_edges() == TableCardText.check_outlet_name(index):
|
||||
edit.text = ""
|
||||
edit.placeholder_text = "What happens on a %s (optional)" % TableCardText.check_outlet_name(index).to_lower()
|
||||
line.add_child(edit)
|
||||
add_rule_chips(col, e)
|
||||
card.edit_ui.hook_select(row, e.id)
|
||||
else:
|
||||
text = RichText.label(row_text(e), 16, Style.INK, true)
|
||||
text.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
RichText.hook_hover(text, main)
|
||||
col.add_child(text)
|
||||
add_rule_chips(col, e)
|
||||
row.mouse_entered.connect(func() -> void: main.details().show_entry(row, table.id, e.id))
|
||||
register(e, row, num, text, index)
|
||||
return row
|
||||
col.add_child(kind_rows.effects_chip(e))
|
||||
|
||||
|
||||
## Play-mode text of a row: the last rolled (expanded) text when the row is
|
||||
|
|
@ -295,82 +250,6 @@ func row_text(e: TableEntry) -> String:
|
|||
return s
|
||||
|
||||
|
||||
## A subtle brass chip summarising an entry's effects: "Luck −1 · Gold + 2D"
|
||||
## in plain words, "@luck -= 1 · @gold += 2d6" as text. Its tooltip has the
|
||||
## other form, every statement on its own line.
|
||||
func _effects_chip(e: TableEntry) -> Control:
|
||||
var plain := card.plain
|
||||
var bad := not Effects.validate(TemplateKit.probe(e.effects)).is_empty()
|
||||
var chip := PanelContainer.new()
|
||||
chip.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
chip.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
|
||||
var bg := Color(Style.DANGER_INK, 0.1) if bad else Color(Style.ACCENT, 0.2)
|
||||
var line := Color(Style.DANGER_INK, 0.4) if bad else Color(Style.ACCENT_DARK, 0.3)
|
||||
chip.add_theme_stylebox_override("panel", Style.bordered(Style.box(bg, 5, [6, 0, 6, 1]), 1, line))
|
||||
var summary := RulesView.effects_line(e.effects, card.main.data, card.table, plain)
|
||||
# Cut long summaries by hand: a clipped Label would collapse to nothing.
|
||||
summary = RulesView.cut(summary, PLAIN_CHIP_CHARS if plain else CHIP_CHARS)
|
||||
var l := Style.make_label(summary, Style.body_bold(true) if plain else Style.body(true), 12, Style.DANGER_INK if bad else Style.TRIM_DARK)
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
chip.add_child(l)
|
||||
chip.set_meta("effects_chip", summary)
|
||||
if plain:
|
||||
chip.tooltip_text = "\n".join(Effects.split(e.effects))
|
||||
else:
|
||||
chip.tooltip_text = "\n".join(Describe.effects(e.effects, card.main.data, card.table))
|
||||
return chip
|
||||
|
||||
|
||||
## A sheet card's one row: the rendered template in Play, its editor in Build.
|
||||
func make_sheet_row(e: TableEntry, build: bool) -> Control:
|
||||
var main := card.main
|
||||
var row := PanelContainer.new()
|
||||
row.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
row.custom_minimum_size = Vector2(0, 36)
|
||||
var v := TableCard.vbox(6)
|
||||
row.add_child(v)
|
||||
if build:
|
||||
var te := TextEdit.new()
|
||||
te.text = e.text
|
||||
te.placeholder_text = "[b]Name[/b] {@name}\nHP {@hp} · Skills {@skill_*}"
|
||||
te.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY
|
||||
te.custom_minimum_size = Vector2(0, 90)
|
||||
te.scroll_fit_content_height = true
|
||||
te.add_theme_font_override("font", Style.body(true))
|
||||
te.add_theme_font_size_override("font_size", 14)
|
||||
te.add_theme_color_override("font_color", Style.INK)
|
||||
te.add_theme_color_override("font_placeholder_color", Style.MUTED)
|
||||
te.add_theme_color_override("caret_color", Style.INK)
|
||||
te.add_theme_color_override("selection_color", Color(Style.ACCENT, 0.55))
|
||||
te.add_theme_stylebox_override("normal", Style.bordered(Style.box(Color.WHITE, 5, [7, 4, 7, 4]), 1, Style.RULE))
|
||||
te.add_theme_stylebox_override("focus", Style.bordered(Style.box(Color.WHITE, 5, [7, 4, 7, 4]), 1, Style.TRIM))
|
||||
te.tooltip_text = "The sheet's template: BBCode with {@var}, {@prefix_*} and {= expr}"
|
||||
te.text_changed.connect(func() -> void:
|
||||
e.text = te.text
|
||||
e.page = ""
|
||||
main.mark_dirty()
|
||||
)
|
||||
te.focus_entered.connect(func() -> void: card.select_entry(e.id))
|
||||
v.add_child(te)
|
||||
var tools := TableCard.vbox(2)
|
||||
if e.effects.strip_edges() != "":
|
||||
tools.add_child(_effects_chip(e))
|
||||
var pv := Style.make_label("Preview on the spread in Play", Style.body_italic(true), 12, Style.MUTED)
|
||||
pv.size_flags_vertical = Control.SIZE_SHRINK_CENTER
|
||||
tools.add_child(pv)
|
||||
v.add_child(tools)
|
||||
card.edit_ui.hook_select(row, e.id)
|
||||
sheet_label = null
|
||||
else:
|
||||
sheet_label = RichText.label("", 15, Style.INK, true)
|
||||
sheet_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
RichText.hook_hover(sheet_label, main)
|
||||
v.add_child(sheet_label)
|
||||
row.mouse_entered.connect(func() -> void: main.details().show_entry(row, card.table.id, e.id))
|
||||
register(e, row, null, null, 0)
|
||||
return row
|
||||
|
||||
|
||||
## The roll modifier's value now (RollRange.live_mod): {"known", "value"}.
|
||||
func live_mod() -> Dictionary:
|
||||
var main := card.main
|
||||
|
|
@ -491,3 +370,12 @@ func clear_flick() -> void:
|
|||
if _flick_id != "":
|
||||
restate(_flick_id)
|
||||
_flick_id = ""
|
||||
|
||||
|
||||
## Check outlets and sheet rows live in TableCardKindRows.
|
||||
func make_check_row(e: TableEntry, index: int, build: bool, numw: float) -> Control:
|
||||
return kind_rows.make_check_row(e, index, build, numw)
|
||||
|
||||
|
||||
func make_sheet_row(e: TableEntry, build: bool) -> Control:
|
||||
return kind_rows.make_sheet_row(e, build)
|
||||
|
|
|
|||
121
ui/table_card_skin.gd
Normal file
121
ui/table_card_skin.gd
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
class_name TableCardSkin
|
||||
extends RefCounted
|
||||
## The card shell look: frame colour, drop/warning panels and scrollbars.
|
||||
|
||||
var card: TableCard
|
||||
|
||||
|
||||
func _init(p_card: TableCard) -> void:
|
||||
card = p_card
|
||||
|
||||
|
||||
## The frame follows the card's own colour (RollTable.color), else the theme's.
|
||||
## Without a frame, the card's colour is a border instead.
|
||||
func sync_frame() -> void:
|
||||
var own := Color.from_string(card.table.color, Color(0, 0, 0, 0)) if card.table.color != "" else Color(0, 0, 0, 0)
|
||||
if card.frame:
|
||||
card.frame.set_trim(own)
|
||||
else:
|
||||
for sb: StyleBoxFlat in [card._style_normal, card._style_dragging]:
|
||||
Style.bordered(sb, 3 if own.a > 0.0 else 0, own)
|
||||
|
||||
|
||||
func apply_style() -> void:
|
||||
var s := card._style_normal
|
||||
if card._drop_target:
|
||||
s = card._style_drop
|
||||
elif card._rolling:
|
||||
s = card._style_rolling
|
||||
elif card._selected:
|
||||
s = card._style_selected
|
||||
elif card._dragging:
|
||||
s = card._style_dragging
|
||||
card.add_theme_stylebox_override("panel", s)
|
||||
|
||||
|
||||
func make_warning() -> Control:
|
||||
var wrap := MarginContainer.new()
|
||||
wrap.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
wrap.add_theme_constant_override("margin_left", 12)
|
||||
wrap.add_theme_constant_override("margin_right", 12)
|
||||
wrap.add_theme_constant_override("margin_bottom", 10)
|
||||
var panel := PanelContainer.new()
|
||||
panel.add_theme_stylebox_override("panel", Style.box(Style.WARN_BG, 6, [9, 6, 9, 6]))
|
||||
panel.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
card._warn_label = Style.make_label("", Style.body(true), 13, Style.WARN_INK)
|
||||
card._warn_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
panel.add_child(card._warn_label)
|
||||
wrap.add_child(panel)
|
||||
return wrap
|
||||
|
||||
|
||||
func update_warning() -> void:
|
||||
var problems := card.table.range_problems()
|
||||
var lines := PackedStringArray()
|
||||
for item: Dictionary in Roller.lint_router(card.table):
|
||||
lines.append(str(item["message"]))
|
||||
for item: Dictionary in Roller.lint_options(card.table):
|
||||
lines.append(str(item["message"]))
|
||||
if not lines.is_empty():
|
||||
problems = ("%s\n" % problems if problems != "" else "") + "\n".join(lines)
|
||||
card._warn_label.text = problems
|
||||
card._warn_panel.visible = problems != ""
|
||||
if is_instance_valid(card.header_ui.roll_button):
|
||||
var back := RollRange.backwards(card.table) != ""
|
||||
card.header_ui.roll_button.disabled = back
|
||||
card.header_ui.roll_button.modulate.a = 0.4 if back else 1.0
|
||||
|
||||
|
||||
func skin_scrollbar(bar: VScrollBar) -> void:
|
||||
var track := Style.box(Color(0, 0, 0, 0), 3, [3, 0, 3, 0])
|
||||
var grab := Style.box(Color(0, 0, 0, 0.22), 3, [3, 0, 3, 0])
|
||||
var grab_hi := Style.box(Color(0, 0, 0, 0.35), 3, [3, 0, 3, 0])
|
||||
bar.add_theme_stylebox_override("scroll", track)
|
||||
bar.add_theme_stylebox_override("scroll_focus", track)
|
||||
bar.add_theme_stylebox_override("grabber", grab)
|
||||
bar.add_theme_stylebox_override("grabber_highlight", grab_hi)
|
||||
bar.add_theme_stylebox_override("grabber_pressed", grab_hi)
|
||||
|
||||
|
||||
## Deck mode: results already drawn (none left in the deck) show faded until
|
||||
## the deck is shuffled.
|
||||
func dim_drawn() -> void:
|
||||
if not card.table.card_mode:
|
||||
return
|
||||
var deck: DeckState = card.main.decks.get(card.table.id)
|
||||
for e in card.table.entries:
|
||||
var row: Control = card.rows.get(e.id)
|
||||
if row == null or not is_instance_valid(row):
|
||||
continue
|
||||
var gone := deck != null and deck.remaining(card.table, e) <= 0
|
||||
row.modulate.a = 0.38 if gone else 1.0
|
||||
row.tooltip_text = "Already drawn: Shuffle the deck to put it back" if gone else ""
|
||||
|
||||
|
||||
func build_styles() -> void:
|
||||
card._style_normal = Style.box(Style.CARD, 10)
|
||||
if Style.CARD_FRAME == "ornate":
|
||||
card._style_normal.set_content_margin_all(CardFrame.PAD)
|
||||
card._style_normal.shadow_color = Color(0, 0, 0, 0.32)
|
||||
card._style_normal.shadow_size = 16
|
||||
card._style_normal.shadow_offset = Vector2(0, 8)
|
||||
card._style_rolling = card._style_normal.duplicate() as StyleBoxFlat
|
||||
Style.bordered(card._style_rolling, 3, Style.ACCENT)
|
||||
card._style_rolling.set_expand_margin_all(3)
|
||||
card._style_rolling.shadow_color = Color(Style.ACCENT, 0.45)
|
||||
card._style_rolling.shadow_size = 26
|
||||
card._style_rolling.shadow_offset = Vector2.ZERO
|
||||
card._style_drop = card._style_rolling.duplicate() as StyleBoxFlat
|
||||
card._style_drop.shadow_color = Color(0, 0, 0, 0.32)
|
||||
card._style_drop.shadow_size = 16
|
||||
card._style_drop.shadow_offset = Vector2(0, 8)
|
||||
card._style_selected = card._style_normal.duplicate() as StyleBoxFlat
|
||||
Style.bordered(card._style_selected, 3, Style.TRIM)
|
||||
card._style_selected.set_expand_margin_all(4)
|
||||
card._style_selected.shadow_color = Color(Style.TRIM, 0.5)
|
||||
card._style_selected.shadow_size = 14
|
||||
card._style_selected.shadow_offset = Vector2.ZERO
|
||||
card._style_dragging = card._style_normal.duplicate() as StyleBoxFlat
|
||||
card._style_dragging.shadow_color = Color(0, 0, 0, 0.4)
|
||||
card._style_dragging.shadow_size = 26
|
||||
card._style_dragging.shadow_offset = Vector2(0, 16)
|
||||
1
ui/table_card_skin.gd.uid
Normal file
1
ui/table_card_skin.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d1d40kxh00kie
|
||||
Loading…
Reference in a new issue