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 and the minimap. ## 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 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.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) 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)