TableTower/ui/view_menu.gd
RobinFiredrake 193794a9e0 The Book: reusable results (Pages) to drag onto tables
BookPage (text with BBCode, details, tags, a name) lives in the spread file
under "book"; a result linked to a page (TableEntry.page) follows its
text and details, so one edit reaches every copy. The Book panel (View ▾,
☰ or right-click) lists pages with search over names, text and tags, and
edits the selected page with a live preview. Drag a page onto a result to
link it, or onto a card to add it as a new result. The inspector offers
Save to the Book, or shows the page with Unlink; editing a result's own
text unlinks it; linked rows show a §. Undo covers the Book.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 19:02:46 -06:00

79 lines
2.8 KiB
GDScript

class_name ViewMenu
extends MenuButton
## The top bar's "View ▾" menu: how rules read (plain words or rule text),
## collapsing or expanding every table, striped result rows, the minimap and the theme.
## These are view preferences, so they live in one menu instead of the bar.
const ID_PLAIN := 0
const ID_TEXT := 1
const ID_COLLAPSE := 2
const ID_STRIPES := 3
const ID_MINIMAP := 4
const ID_THEME := 5
const ID_LIST := 6
const ID_BOOK := 7
var m: Main
func setup(p_main: Main) -> void:
m = p_main
Style.menu_button("View ▾", false, self)
tooltip_text = "How rules read, collapsing tables, striped rows and the minimap"
var pm := get_popup()
ModalCard.style_popup(pm)
pm.add_separator("Rules")
pm.add_radio_check_item("Plain words", ID_PLAIN)
pm.set_item_tooltip(pm.get_item_index(ID_PLAIN), "Show rules in plain words: “Subtract 1 from Luck”")
pm.add_radio_check_item("Rule text", ID_TEXT)
pm.set_item_tooltip(pm.get_item_index(ID_TEXT), "Show rules as the text they're stored as: @luck -= 1")
pm.add_separator("Tables")
pm.add_item("Collapse all tables", ID_COLLAPSE)
pm.add_separator("Show")
pm.add_check_item("Striped rows", ID_STRIPES)
pm.add_check_item("Minimap (M)", ID_MINIMAP)
pm.add_check_item("List view", ID_LIST)
pm.add_check_item("Book", ID_BOOK)
pm.set_item_tooltip(pm.get_item_index(ID_BOOK), "Reusable results (Pages) to drag onto tables")
pm.set_item_tooltip(pm.get_item_index(ID_LIST), "The cards as a list with folders, beside the spread")
pm.add_separator()
pm.add_item("Theme…", ID_THEME)
pm.set_item_tooltip(pm.get_item_index(ID_THEME), "Colours, background, fonts and logo; save your own theme")
pm.about_to_popup.connect(sync)
pm.id_pressed.connect(activate)
## Brings the checks and the Collapse/Expand label up to date.
func sync() -> void:
var pm := get_popup()
pm.set_item_checked(pm.get_item_index(ID_PLAIN), m.rules_plain())
pm.set_item_checked(pm.get_item_index(ID_TEXT), not m.rules_plain())
pm.set_item_text(pm.get_item_index(ID_COLLAPSE), collapse_label())
pm.set_item_checked(pm.get_item_index(ID_STRIPES), m.local_state.striped_rows())
pm.set_item_checked(pm.get_item_index(ID_MINIMAP), m.board.minimap.visible)
pm.set_item_checked(pm.get_item_index(ID_LIST), m.list_view.visible)
pm.set_item_checked(pm.get_item_index(ID_BOOK), m.book.visible)
func collapse_label() -> String:
return "Collapse all tables" if m._any_expanded() else "Expand all tables"
func activate(id: int) -> void:
match id:
ID_PLAIN:
m.set_rules_view("plain")
ID_TEXT:
m.set_rules_view("text")
ID_COLLAPSE:
m.set_all_collapsed(m._any_expanded())
ID_STRIPES:
m.local_state.set_striped_rows(not m.local_state.striped_rows())
ID_MINIMAP:
m.nav.set_minimap_visible(not m.board.minimap.visible, true)
ID_LIST:
m.list_view.toggle()
ID_BOOK:
m.book.toggle()
ID_THEME:
m.add_child(ThemeDialog.new(m))