Size audit 2: split result_tray and inspector
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ad264cd2f0
commit
f47f659ff4
8 changed files with 239 additions and 188 deletions
|
|
@ -50,46 +50,7 @@ func setup(p_main: Main) -> void:
|
|||
custom_minimum_size = Vector2(WIDTH, 0)
|
||||
size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
visibility_changed.connect(_sync_splitter)
|
||||
var sb := Style.box(Style.CARD, 0, [0, 0, 0, 0])
|
||||
sb.border_width_left = 1
|
||||
sb.border_color = Color(0, 0, 0, 0.25)
|
||||
add_theme_stylebox_override("panel", sb)
|
||||
var stack := Control.new()
|
||||
stack.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
add_child(stack)
|
||||
|
||||
_body = VBoxContainer.new()
|
||||
_body.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
_body.add_theme_constant_override("separation", 0)
|
||||
stack.add_child(_body)
|
||||
_scroll = ScrollContainer.new()
|
||||
_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
_scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
_body.add_child(_scroll)
|
||||
var pad := MarginContainer.new()
|
||||
pad.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
for k in ["margin_left", "margin_right"]:
|
||||
pad.add_theme_constant_override(k, 16)
|
||||
pad.add_theme_constant_override("margin_top", 14)
|
||||
pad.add_theme_constant_override("margin_bottom", 18)
|
||||
_scroll.add_child(pad)
|
||||
_content = InspectorKit.vbox(14)
|
||||
pad.add_child(_content)
|
||||
|
||||
_strip = PanelContainer.new()
|
||||
_strip.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
_strip.add_theme_stylebox_override("panel", Style.box(Style.CARD, 0, [2, 8, 2, 8]))
|
||||
var open := Button.new()
|
||||
open.text = "«"
|
||||
open.tooltip_text = "Show the inspector"
|
||||
open.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
|
||||
Style.skin_button(open, Style.box(Color(0, 0, 0, 0), 5, [4, 2, 4, 2]), Style.box(Style.HOVER_ROW, 5, [4, 2, 4, 2]),
|
||||
Style.box(Style.HOVER_ROW, 5, [4, 2, 4, 2]), Style.TRIM_DARK)
|
||||
open.add_theme_font_size_override("font_size", 18)
|
||||
open.pressed.connect(func() -> void: set_collapsed(false))
|
||||
_strip.add_child(open)
|
||||
_strip.hide()
|
||||
stack.add_child(_strip)
|
||||
InspectorFrame.build(self)
|
||||
rebuild()
|
||||
|
||||
|
||||
|
|
@ -189,7 +150,7 @@ func wrote(t: RollTable, all_cards: bool = false, rebuild_panel: bool = false) -
|
|||
for f in _live:
|
||||
if f.is_valid():
|
||||
f.call()
|
||||
_refresh_title()
|
||||
InspectorFrame.refresh_title(self)
|
||||
if rebuild_panel:
|
||||
rebuild()
|
||||
|
||||
|
|
@ -325,7 +286,7 @@ func rebuild() -> void:
|
|||
t = null
|
||||
if t == null:
|
||||
selection = {}
|
||||
_empty()
|
||||
InspectorFrame.show_empty(self)
|
||||
else:
|
||||
match str(selection.get("kind", "card")):
|
||||
"result":
|
||||
|
|
@ -346,48 +307,7 @@ func rebuild() -> void:
|
|||
|
||||
|
||||
func _head(kind: String, title: String) -> Control:
|
||||
var h := InspectorKit.hbox(6)
|
||||
var v := InspectorKit.vbox(2)
|
||||
v.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
v.add_child(InspectorKit.flabel(kind))
|
||||
var tl := Style.make_label(title, Style.display(), 22, Style.INK)
|
||||
_title_label = tl
|
||||
tl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
tl.custom_minimum_size = Vector2(120, 0)
|
||||
v.add_child(tl)
|
||||
h.add_child(v)
|
||||
var hide_b := Button.new()
|
||||
hide_b.text = "»"
|
||||
hide_b.tooltip_text = "Hide the inspector"
|
||||
hide_b.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
|
||||
Style.skin_button(hide_b, Style.box(Color(0, 0, 0, 0), 5, [6, 0, 6, 2]), Style.box(Style.HOVER_ROW, 5, [6, 0, 6, 2]),
|
||||
Style.box(Style.HOVER_ROW, 5, [6, 0, 6, 2]), Style.MUTED, Style.INK)
|
||||
hide_b.add_theme_font_size_override("font_size", 18)
|
||||
hide_b.focus_mode = Control.FOCUS_NONE
|
||||
hide_b.pressed.connect(func() -> void: set_collapsed(true))
|
||||
h.add_child(hide_b)
|
||||
return h
|
||||
|
||||
|
||||
## Keeps the heading in step with the name or text being typed.
|
||||
func _refresh_title() -> void:
|
||||
if not is_instance_valid(_title_label):
|
||||
return
|
||||
var t := selected_table()
|
||||
match str(selection.get("kind", "")):
|
||||
"card":
|
||||
if t:
|
||||
_title_label.text = _title_of(t.name, "(no name)")
|
||||
"result":
|
||||
var e := selected_entry()
|
||||
if e:
|
||||
_title_label.text = _title_of(e.text, "(no text)")
|
||||
|
||||
|
||||
func _empty() -> void:
|
||||
_content.add_child(_head("Inspector", "Nothing selected"))
|
||||
_content.add_child(InspectorKit.note("Select a card, a result or a thread to edit it.", Style.MUTED, 15))
|
||||
_content.add_child(InspectorKit.note("Click a card's title for the card, a result's text for the result, or a thread on the felt for its options.", Style.MUTED, 13))
|
||||
return InspectorFrame.head(self, kind, title)
|
||||
|
||||
|
||||
static func _title_of(s: String, fallback: String) -> String:
|
||||
|
|
|
|||
98
ui/inspector_frame.gd
Normal file
98
ui/inspector_frame.gd
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
class_name InspectorFrame
|
||||
extends RefCounted
|
||||
## The inspector's frame: the panel and its scroll area, the thin strip shown
|
||||
## when it is hidden, the heading at the top of each section (with its hide
|
||||
## button), and the "Nothing selected" page. Inspector calls these; the
|
||||
## sections themselves (card, result, thread) live in other helpers.
|
||||
|
||||
|
||||
## Builds the panel's frame into `insp`: the scrolling body and the hidden strip.
|
||||
static func build(insp: Inspector) -> void:
|
||||
var panel_box := Style.box(Style.CARD, 0, [0, 0, 0, 0])
|
||||
panel_box.border_width_left = 1
|
||||
panel_box.border_color = Color(0, 0, 0, 0.25)
|
||||
insp.add_theme_stylebox_override("panel", panel_box)
|
||||
var stack := Control.new()
|
||||
stack.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
insp.add_child(stack)
|
||||
|
||||
insp._body = VBoxContainer.new()
|
||||
insp._body.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
insp._body.add_theme_constant_override("separation", 0)
|
||||
stack.add_child(insp._body)
|
||||
insp._scroll = ScrollContainer.new()
|
||||
insp._scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
insp._scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
insp._body.add_child(insp._scroll)
|
||||
var pad := MarginContainer.new()
|
||||
pad.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
for margin_name in ["margin_left", "margin_right"]:
|
||||
pad.add_theme_constant_override(margin_name, 16)
|
||||
pad.add_theme_constant_override("margin_top", 14)
|
||||
pad.add_theme_constant_override("margin_bottom", 18)
|
||||
insp._scroll.add_child(pad)
|
||||
insp._content = InspectorKit.vbox(14)
|
||||
pad.add_child(insp._content)
|
||||
|
||||
insp._strip = PanelContainer.new()
|
||||
insp._strip.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
insp._strip.add_theme_stylebox_override("panel", Style.box(Style.CARD, 0, [2, 8, 2, 8]))
|
||||
var open := Button.new()
|
||||
open.text = "«"
|
||||
open.tooltip_text = "Show the inspector"
|
||||
open.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
|
||||
Style.skin_button(open, Style.box(Color(0, 0, 0, 0), 5, [4, 2, 4, 2]), Style.box(Style.HOVER_ROW, 5, [4, 2, 4, 2]),
|
||||
Style.box(Style.HOVER_ROW, 5, [4, 2, 4, 2]), Style.TRIM_DARK)
|
||||
open.add_theme_font_size_override("font_size", 18)
|
||||
open.pressed.connect(func() -> void: insp.set_collapsed(false))
|
||||
insp._strip.add_child(open)
|
||||
insp._strip.hide()
|
||||
stack.add_child(insp._strip)
|
||||
|
||||
|
||||
## The heading of a section: a small kind line, a big title, and the » button
|
||||
## that hides the inspector. Remembers the title label so it can follow typing.
|
||||
static func head(insp: Inspector, kind: String, title: String) -> Control:
|
||||
var row := InspectorKit.hbox(6)
|
||||
var column := InspectorKit.vbox(2)
|
||||
column.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
column.add_child(InspectorKit.flabel(kind))
|
||||
var title_label := Style.make_label(title, Style.display(), 22, Style.INK)
|
||||
insp._title_label = title_label
|
||||
title_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
title_label.custom_minimum_size = Vector2(120, 0)
|
||||
column.add_child(title_label)
|
||||
row.add_child(column)
|
||||
var hide_button := Button.new()
|
||||
hide_button.text = "»"
|
||||
hide_button.tooltip_text = "Hide the inspector"
|
||||
hide_button.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
|
||||
Style.skin_button(hide_button, Style.box(Color(0, 0, 0, 0), 5, [6, 0, 6, 2]), Style.box(Style.HOVER_ROW, 5, [6, 0, 6, 2]),
|
||||
Style.box(Style.HOVER_ROW, 5, [6, 0, 6, 2]), Style.MUTED, Style.INK)
|
||||
hide_button.add_theme_font_size_override("font_size", 18)
|
||||
hide_button.focus_mode = Control.FOCUS_NONE
|
||||
hide_button.pressed.connect(func() -> void: insp.set_collapsed(true))
|
||||
row.add_child(hide_button)
|
||||
return row
|
||||
|
||||
|
||||
## Keeps the heading in step with the name or text being typed.
|
||||
static func refresh_title(insp: Inspector) -> void:
|
||||
if not is_instance_valid(insp._title_label):
|
||||
return
|
||||
var card := insp.selected_table()
|
||||
match str(insp.selection.get("kind", "")):
|
||||
"card":
|
||||
if card:
|
||||
insp._title_label.text = Inspector._title_of(card.name, "(no name)")
|
||||
"result":
|
||||
var entry := insp.selected_entry()
|
||||
if entry:
|
||||
insp._title_label.text = Inspector._title_of(entry.text, "(no text)")
|
||||
|
||||
|
||||
## The page shown when nothing is selected.
|
||||
static func show_empty(insp: Inspector) -> void:
|
||||
insp._content.add_child(head(insp, "Inspector", "Nothing selected"))
|
||||
insp._content.add_child(InspectorKit.note("Select a card, a result or a thread to edit it.", Style.MUTED, 15))
|
||||
insp._content.add_child(InspectorKit.note("Click a card's title for the card, a result's text for the result, or a thread on the felt for its options.", Style.MUTED, 13))
|
||||
1
ui/inspector_frame.gd.uid
Normal file
1
ui/inspector_frame.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dbsifj7dpr1ax
|
||||
|
|
@ -12,8 +12,9 @@ extends PanelContainer
|
|||
## opens the pop-over for that step (default: the last one with reasons)
|
||||
## after a roll.
|
||||
##
|
||||
## Pieces: TrayChips builds the chips and links, TrayText words them, and
|
||||
## EarlierRolls is the Earlier tab.
|
||||
## Pieces: TrayChips builds the chips and links, TrayText words them,
|
||||
## TrayControls builds the tabs, Copy menu and sheet headline, TrayWhy opens
|
||||
## the Why pop-over, and EarlierRolls is the Earlier tab.
|
||||
##
|
||||
## The tray keeps the height the player drags it to (a PanelSplitter above it,
|
||||
## setting "tray_height"); the chips, the sheet, Earlier and Variables each
|
||||
|
|
@ -97,7 +98,7 @@ func setup(p_main: Main) -> void:
|
|||
main.start_roll(main.current["root"])
|
||||
)
|
||||
head.add_child(_again)
|
||||
_copy = _make_copy_menu()
|
||||
_copy = TrayControls.copy_menu(main)
|
||||
head.add_child(_copy)
|
||||
_halt = PanelContainer.new()
|
||||
_halt.add_theme_stylebox_override("panel", Style.box(Style.WARN_BG, 8, [10, 3, 10, 4]))
|
||||
|
|
@ -111,28 +112,7 @@ func setup(p_main: Main) -> void:
|
|||
now.add_child(_pause_box)
|
||||
|
||||
# A chain that reached a sheet card leads with the rendered sheet.
|
||||
_headline = PanelContainer.new()
|
||||
var hsb := Style.box(Style.CARD, 10, [16, 10, 16, 12])
|
||||
Style.bordered(hsb, 2, Style.ACCENT)
|
||||
_headline.add_theme_stylebox_override("panel", hsb)
|
||||
_headline.size_flags_horizontal = SIZE_SHRINK_BEGIN
|
||||
var hv := VBoxContainer.new()
|
||||
hv.add_theme_constant_override("separation", 2)
|
||||
_headline.add_child(hv)
|
||||
_headline_cap = Style.make_label("", Style.body(), 12, Style.MUTED)
|
||||
hv.add_child(_headline_cap)
|
||||
# A sheet wraps at a fixed width and scrolls inside the tray, so a long
|
||||
# sheet can't widen the window or take over the tray.
|
||||
_headline_text = RichText.label("", 17, Style.INK, false, true)
|
||||
_headline_text.custom_minimum_size = Vector2(HEADLINE_W, 0)
|
||||
RichText.hook_hover(_headline_text, main)
|
||||
_headline_scroll = ScrollContainer.new()
|
||||
_headline_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
_headline_scroll.custom_minimum_size = Vector2(HEADLINE_W + 12, 0)
|
||||
_headline_scroll.add_child(_headline_text)
|
||||
hv.add_child(_headline_scroll)
|
||||
_headline.hide()
|
||||
_headline.size_flags_vertical = SIZE_SHRINK_BEGIN
|
||||
TrayControls.build_headline(self)
|
||||
# The headline sits left of the chips, so a sheet doesn't make the tray taller.
|
||||
var body_row := HBoxContainer.new()
|
||||
body_row.add_theme_constant_override("separation", 14)
|
||||
|
|
@ -163,10 +143,10 @@ func setup(p_main: Main) -> void:
|
|||
var tabs := HBoxContainer.new()
|
||||
tabs.add_theme_constant_override("separation", 14)
|
||||
right.add_child(tabs)
|
||||
_tab_earlier = _tab("EARLIER")
|
||||
_tab_earlier = TrayControls.tab_button("EARLIER")
|
||||
_tab_earlier.pressed.connect(func() -> void: set_side(Side.EARLIER))
|
||||
tabs.add_child(_tab_earlier)
|
||||
_tab_vars = _tab("VARIABLES")
|
||||
_tab_vars = TrayControls.tab_button("VARIABLES")
|
||||
_tab_vars.tooltip_text = "Saved variables for this spread"
|
||||
_tab_vars.pressed.connect(func() -> void: set_side(Side.VARIABLES))
|
||||
tabs.add_child(_tab_vars)
|
||||
|
|
@ -188,21 +168,6 @@ func _on_rules_view_changed(_v: Variant = null) -> void:
|
|||
render()
|
||||
|
||||
|
||||
func _tab(text: String) -> Button:
|
||||
var b := Button.new()
|
||||
b.text = text
|
||||
b.toggle_mode = true
|
||||
b.add_theme_font_override("font", Style.caps())
|
||||
b.add_theme_font_size_override("font_size", 12)
|
||||
var n := Style.box(Color(0, 0, 0, 0), 0, [0, 0, 0, 3])
|
||||
var on := Style.box(Color(0, 0, 0, 0), 0, [0, 0, 0, 1])
|
||||
on.border_width_bottom = 2
|
||||
on.border_color = Style.ACCENT
|
||||
Style.skin_button(b, n, n, on, Style.ON_BG_MUTED, Style.ON_BG, Style.ON_BG)
|
||||
b.add_theme_stylebox_override("focus", Style.box(Color(0, 0, 0, 0)))
|
||||
return b
|
||||
|
||||
|
||||
func set_side(s: int) -> void:
|
||||
side = s
|
||||
_tab_earlier.set_pressed_no_signal(s == Side.EARLIER)
|
||||
|
|
@ -213,38 +178,6 @@ func set_side(s: int) -> void:
|
|||
_vars.render()
|
||||
|
||||
|
||||
func _make_copy_menu() -> MenuButton:
|
||||
var m := MenuButton.new()
|
||||
m.text = "Copy"
|
||||
m.tooltip_text = "Copy this result, or save it as a file"
|
||||
m.flat = false
|
||||
var normal := Style.bordered(Style.box(Color(1, 1, 1, 0.04), 8, [12, 6, 12, 6]), 1, Color(1, 1, 1, 0.16))
|
||||
var hover := Style.bordered(Style.box(Color(1, 1, 1, 0.1), 8, [12, 6, 12, 6]), 1, Color(1, 1, 1, 0.16))
|
||||
Style.skin_button(m, normal, hover, hover, Style.ON_BG)
|
||||
m.add_theme_font_size_override("font_size", 15)
|
||||
var pm := m.get_popup()
|
||||
pm.add_item("Copy as text", COPY_TEXT)
|
||||
pm.add_item("Copy as BBCode", COPY_BBCODE)
|
||||
pm.add_item("Copy with details", COPY_DETAILS)
|
||||
pm.add_theme_stylebox_override("panel", Style.bordered(Style.box(Style.CARD, 8, [6, 6, 6, 6]), 1, Style.RULE))
|
||||
pm.add_theme_stylebox_override("hover", Style.box(Style.LIT, 5, [8, 4, 8, 4]))
|
||||
pm.add_theme_color_override("font_color", Style.INK)
|
||||
pm.add_theme_color_override("font_hover_color", Style.INK)
|
||||
pm.add_theme_font_override("font", Style.body())
|
||||
pm.add_theme_font_size_override("font_size", 15)
|
||||
pm.id_pressed.connect(func(id: int) -> void: main.copy_current(id))
|
||||
# Save as a file to use outside the app (SheetExport).
|
||||
var save := PopupMenu.new()
|
||||
ModalCard.style_popup(save)
|
||||
for i in SheetExport.FORMATS.size():
|
||||
save.add_item(str(SheetExport.FORMATS[i]["label"]) + "…", i)
|
||||
save.id_pressed.connect(func(i: int) -> void: SheetExport.save(main, i))
|
||||
pm.add_child(save)
|
||||
pm.add_separator()
|
||||
pm.add_submenu_node_item("Save as a file", save)
|
||||
return m
|
||||
|
||||
|
||||
func render() -> void:
|
||||
for c in _pause_box.get_children():
|
||||
c.queue_free()
|
||||
|
|
@ -311,40 +244,12 @@ func render() -> void:
|
|||
|
||||
## --why[=<step index>]: opens the Why pop-over once after a roll (screenshots).
|
||||
func _open_why_from_flag() -> void:
|
||||
for a in OS.get_cmdline_user_args():
|
||||
if a == "--why" or a.begins_with("--why="):
|
||||
_why_flag_done = true
|
||||
await get_tree().create_timer(0.4).timeout
|
||||
if not main.current.get("done", false):
|
||||
_why_flag_done = false # a new roll began; wait for it to end
|
||||
return
|
||||
var at := -1
|
||||
if a == "--why":
|
||||
for k: int in why_buttons:
|
||||
at = maxi(at, k)
|
||||
else:
|
||||
at = a.get_slice("=", 1).to_int()
|
||||
if why_buttons.has(at):
|
||||
(why_buttons[at] as Button).emit_signal("pressed")
|
||||
return
|
||||
TrayWhy.open_from_flag(self)
|
||||
|
||||
|
||||
## Opens (or, from the same button, closes) the Why pop-over for steps[index].
|
||||
func open_why(index: int, from: Control = null) -> void:
|
||||
if _why.visible and from != null and _why.opener == from:
|
||||
_why.close()
|
||||
return
|
||||
var steps: Array = main.current.get("steps", [])
|
||||
if index < 0 or index >= steps.size():
|
||||
return
|
||||
main.details().hide_for()
|
||||
var at := Rect2(global_position + Vector2(20, 20), Vector2.ZERO)
|
||||
var chip: Control = null
|
||||
if from != null:
|
||||
# Above the whole chip, so it never hides the step it explains.
|
||||
chip = from.get_parent().get_parent() as Control
|
||||
at = chip.get_global_rect() if chip != null else from.get_global_rect()
|
||||
_why.open(steps, index, main.data, RulesView.plain(main), at, from, chip)
|
||||
TrayWhy.open(self, index, from)
|
||||
|
||||
|
||||
func why_popover() -> WhyPopover:
|
||||
|
|
|
|||
81
ui/tray_controls.gd
Normal file
81
ui/tray_controls.gd
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
class_name TrayControls
|
||||
extends RefCounted
|
||||
## Builds the result tray's fixed controls: the EARLIER / VARIABLES tab
|
||||
## buttons, the Copy menu (with "Save as a file"), and the sheet headline box
|
||||
## that shows a finished sheet left of the chips. ResultTray.setup() calls these.
|
||||
|
||||
|
||||
## A flat tab button with an accent underline when pressed.
|
||||
static func tab_button(text: String) -> Button:
|
||||
var button := Button.new()
|
||||
button.text = text
|
||||
button.toggle_mode = true
|
||||
button.add_theme_font_override("font", Style.caps())
|
||||
button.add_theme_font_size_override("font_size", 12)
|
||||
var normal := Style.box(Color(0, 0, 0, 0), 0, [0, 0, 0, 3])
|
||||
var pressed := Style.box(Color(0, 0, 0, 0), 0, [0, 0, 0, 1])
|
||||
pressed.border_width_bottom = 2
|
||||
pressed.border_color = Style.ACCENT
|
||||
Style.skin_button(button, normal, normal, pressed, Style.ON_BG_MUTED, Style.ON_BG, Style.ON_BG)
|
||||
button.add_theme_stylebox_override("focus", Style.box(Color(0, 0, 0, 0)))
|
||||
return button
|
||||
|
||||
|
||||
## The Copy menu: copy as text, BBCode or with details, or save as a file.
|
||||
static func copy_menu(main: Main) -> MenuButton:
|
||||
var menu := MenuButton.new()
|
||||
menu.text = "Copy"
|
||||
menu.tooltip_text = "Copy this result, or save it as a file"
|
||||
menu.flat = false
|
||||
var normal := Style.bordered(Style.box(Color(1, 1, 1, 0.04), 8, [12, 6, 12, 6]), 1, Color(1, 1, 1, 0.16))
|
||||
var hover := Style.bordered(Style.box(Color(1, 1, 1, 0.1), 8, [12, 6, 12, 6]), 1, Color(1, 1, 1, 0.16))
|
||||
Style.skin_button(menu, normal, hover, hover, Style.ON_BG)
|
||||
menu.add_theme_font_size_override("font_size", 15)
|
||||
var popup := menu.get_popup()
|
||||
popup.add_item("Copy as text", ResultTray.COPY_TEXT)
|
||||
popup.add_item("Copy as BBCode", ResultTray.COPY_BBCODE)
|
||||
popup.add_item("Copy with details", ResultTray.COPY_DETAILS)
|
||||
popup.add_theme_stylebox_override("panel", Style.bordered(Style.box(Style.CARD, 8, [6, 6, 6, 6]), 1, Style.RULE))
|
||||
popup.add_theme_stylebox_override("hover", Style.box(Style.LIT, 5, [8, 4, 8, 4]))
|
||||
popup.add_theme_color_override("font_color", Style.INK)
|
||||
popup.add_theme_color_override("font_hover_color", Style.INK)
|
||||
popup.add_theme_font_override("font", Style.body())
|
||||
popup.add_theme_font_size_override("font_size", 15)
|
||||
popup.id_pressed.connect(func(id: int) -> void: main.copy_current(id))
|
||||
# Save as a file to use outside the app (SheetExport).
|
||||
var save := PopupMenu.new()
|
||||
ModalCard.style_popup(save)
|
||||
for i in SheetExport.FORMATS.size():
|
||||
save.add_item(str(SheetExport.FORMATS[i]["label"]) + "…", i)
|
||||
save.id_pressed.connect(func(i: int) -> void: SheetExport.save(main, i))
|
||||
popup.add_child(save)
|
||||
popup.add_separator()
|
||||
popup.add_submenu_node_item("Save as a file", save)
|
||||
return menu
|
||||
|
||||
|
||||
## Builds the sheet headline box into tray._headline (hidden until a chain
|
||||
## reaches a sheet card), with its caption, text and scroll area.
|
||||
static func build_headline(tray: ResultTray) -> void:
|
||||
tray._headline = PanelContainer.new()
|
||||
var headline_box := Style.box(Style.CARD, 10, [16, 10, 16, 12])
|
||||
Style.bordered(headline_box, 2, Style.ACCENT)
|
||||
tray._headline.add_theme_stylebox_override("panel", headline_box)
|
||||
tray._headline.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
|
||||
var column := VBoxContainer.new()
|
||||
column.add_theme_constant_override("separation", 2)
|
||||
tray._headline.add_child(column)
|
||||
tray._headline_cap = Style.make_label("", Style.body(), 12, Style.MUTED)
|
||||
column.add_child(tray._headline_cap)
|
||||
# A sheet wraps at a fixed width and scrolls inside the tray, so a long
|
||||
# sheet can't widen the window or take over the tray.
|
||||
tray._headline_text = RichText.label("", 17, Style.INK, false, true)
|
||||
tray._headline_text.custom_minimum_size = Vector2(ResultTray.HEADLINE_W, 0)
|
||||
RichText.hook_hover(tray._headline_text, tray.main)
|
||||
tray._headline_scroll = ScrollContainer.new()
|
||||
tray._headline_scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
||||
tray._headline_scroll.custom_minimum_size = Vector2(ResultTray.HEADLINE_W + 12, 0)
|
||||
tray._headline_scroll.add_child(tray._headline_text)
|
||||
column.add_child(tray._headline_scroll)
|
||||
tray._headline.hide()
|
||||
tray._headline.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
|
||||
1
ui/tray_controls.gd.uid
Normal file
1
ui/tray_controls.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://muegbqbokl8m
|
||||
44
ui/tray_why.gd
Normal file
44
ui/tray_why.gd
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
class_name TrayWhy
|
||||
extends RefCounted
|
||||
## Opens the result tray's "Why this?" pop-over (WhyPopover): from a chip's
|
||||
## button, or once after a roll when the app was started with --why
|
||||
## (for screenshots). ResultTray.open_why() calls open().
|
||||
|
||||
|
||||
## Opens (or, from the same button, closes) the Why pop-over for steps[index].
|
||||
static func open(tray: ResultTray, index: int, from: Control = null) -> void:
|
||||
var popover := tray._why
|
||||
if popover.visible and from != null and popover.opener == from:
|
||||
popover.close()
|
||||
return
|
||||
var steps: Array = tray.main.current.get("steps", [])
|
||||
if index < 0 or index >= steps.size():
|
||||
return
|
||||
tray.main.details().hide_for()
|
||||
var at := Rect2(tray.global_position + Vector2(20, 20), Vector2.ZERO)
|
||||
var chip: Control = null
|
||||
if from != null:
|
||||
# Above the whole chip, so it never hides the step it explains.
|
||||
chip = from.get_parent().get_parent() as Control
|
||||
at = chip.get_global_rect() if chip != null else from.get_global_rect()
|
||||
popover.open(steps, index, tray.main.data, RulesView.plain(tray.main), at, from, chip)
|
||||
|
||||
|
||||
## --why[=<step index>]: opens the Why pop-over once after a roll (screenshots).
|
||||
static func open_from_flag(tray: ResultTray) -> void:
|
||||
for arg in OS.get_cmdline_user_args():
|
||||
if arg == "--why" or arg.begins_with("--why="):
|
||||
tray._why_flag_done = true
|
||||
await tray.get_tree().create_timer(0.4).timeout
|
||||
if not tray.main.current.get("done", false):
|
||||
tray._why_flag_done = false # a new roll began; wait for it to end
|
||||
return
|
||||
var at := -1
|
||||
if arg == "--why":
|
||||
for step_index: int in tray.why_buttons:
|
||||
at = maxi(at, step_index)
|
||||
else:
|
||||
at = arg.get_slice("=", 1).to_int()
|
||||
if tray.why_buttons.has(at):
|
||||
(tray.why_buttons[at] as Button).emit_signal("pressed")
|
||||
return
|
||||
1
ui/tray_why.gd.uid
Normal file
1
ui/tray_why.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cvvctiyc4sl7j
|
||||
Loading…
Reference in a new issue