234 lines
8.6 KiB
GDScript3
234 lines
8.6 KiB
GDScript3
|
|
class_name MainMenu
|
||
|
|
extends Control
|
||
|
|
## The main menu, laid out like the mockup (docs/SHEETS.md): on the theme's
|
||
|
|
## spread background, the app's name over Spreads (first: the app's main job),
|
||
|
|
## Sheets, then Settings and Quit side by side, titles only (the user's pick,
|
||
|
|
## 2026-11-29). Beside them Morgan and "Pick up where you left off". A footer
|
||
|
|
## names the theme.
|
||
|
|
|
||
|
|
var m: Main
|
||
|
|
var buttons: Dictionary = {} # label -> Button
|
||
|
|
var recent_rows: VBoxContainer
|
||
|
|
var row: BoxContainer
|
||
|
|
var _backdrop: BoardBackdrop
|
||
|
|
var _theme_label: Label
|
||
|
|
|
||
|
|
|
||
|
|
func setup(p_main: Main) -> void:
|
||
|
|
m = p_main
|
||
|
|
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
|
|
_backdrop = BoardBackdrop.new(ThemeStore.current)
|
||
|
|
draw.connect(func() -> void: _backdrop.draw(self, Rect2(Vector2.ZERO, size)))
|
||
|
|
resized.connect(queue_redraw)
|
||
|
|
var page := VBoxContainer.new()
|
||
|
|
page.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
|
|
page.add_theme_constant_override("separation", 0)
|
||
|
|
add_child(page)
|
||
|
|
var center := CenterContainer.new()
|
||
|
|
center.size_flags_vertical = SIZE_EXPAND_FILL
|
||
|
|
page.add_child(center)
|
||
|
|
# Side by side; a narrow window (a phone) stacks them (_fit_columns).
|
||
|
|
row = BoxContainer.new()
|
||
|
|
row.add_theme_constant_override("separation", 64)
|
||
|
|
resized.connect(_fit_columns)
|
||
|
|
center.add_child(row)
|
||
|
|
row.add_child(_left_column())
|
||
|
|
row.add_child(_right_column())
|
||
|
|
page.add_child(_footer())
|
||
|
|
|
||
|
|
|
||
|
|
func _fit_columns() -> void:
|
||
|
|
row.vertical = size.x < 920.0
|
||
|
|
|
||
|
|
|
||
|
|
func _left_column() -> VBoxContainer:
|
||
|
|
var col := VBoxContainer.new()
|
||
|
|
col.custom_minimum_size = Vector2(420, 0)
|
||
|
|
col.add_theme_constant_override("separation", 28)
|
||
|
|
var names := VBoxContainer.new()
|
||
|
|
names.add_theme_constant_override("separation", 2)
|
||
|
|
names.add_child(Style.make_label("RANDOM TABLES & SHEETS", Style.caps(), 13, Style.ON_BG_MUTED))
|
||
|
|
names.add_child(Style.make_label("Table Tarot", Style.display(), 72, Style.ACCENT))
|
||
|
|
col.add_child(names)
|
||
|
|
var nav := VBoxContainer.new()
|
||
|
|
nav.add_theme_constant_override("separation", 10)
|
||
|
|
col.add_child(nav)
|
||
|
|
nav.add_child(_big_button("Spreads", MenuIcons.SPREAD, true, func() -> void: m.screens.show(MainScreens.SPREAD)))
|
||
|
|
nav.add_child(_big_button("Sheets", MenuIcons.SHEET, false, func() -> void: m.screens.show(MainScreens.SHEETS)))
|
||
|
|
var pair := GridContainer.new()
|
||
|
|
pair.columns = 2
|
||
|
|
pair.add_theme_constant_override("h_separation", 10)
|
||
|
|
nav.add_child(pair)
|
||
|
|
pair.add_child(_small_button("Settings", MenuIcons.SETTINGS, open_settings))
|
||
|
|
pair.add_child(_small_button("Quit", MenuIcons.QUIT, quit))
|
||
|
|
return col
|
||
|
|
|
||
|
|
|
||
|
|
func _right_column() -> VBoxContainer:
|
||
|
|
var col := VBoxContainer.new()
|
||
|
|
col.custom_minimum_size = Vector2(380, 0)
|
||
|
|
col.add_theme_constant_override("separation", 20)
|
||
|
|
var mark := _mascot()
|
||
|
|
if mark:
|
||
|
|
col.add_child(mark)
|
||
|
|
var recent := VBoxContainer.new()
|
||
|
|
recent.add_theme_constant_override("separation", 8)
|
||
|
|
recent.add_child(Style.make_label("PICK UP WHERE YOU LEFT OFF", Style.caps(), 12, Style.ON_BG_MUTED))
|
||
|
|
recent_rows = VBoxContainer.new()
|
||
|
|
recent_rows.add_theme_constant_override("separation", 8)
|
||
|
|
recent.add_child(recent_rows)
|
||
|
|
col.add_child(recent)
|
||
|
|
visibility_changed.connect(func() -> void:
|
||
|
|
if visible:
|
||
|
|
refresh_recent())
|
||
|
|
return col
|
||
|
|
|
||
|
|
|
||
|
|
## Morgan (or the theme's logo) drawn large and sharp.
|
||
|
|
func _mascot() -> Control:
|
||
|
|
if Style.LOGO == "fortune_teller" or Style.LOGO == "mascot":
|
||
|
|
var tr := TextureRect.new()
|
||
|
|
tr.texture = MascotArt.texture(ThemeStore.current, 512)
|
||
|
|
tr.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
||
|
|
tr.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||
|
|
tr.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS
|
||
|
|
tr.custom_minimum_size = Vector2(380, 280)
|
||
|
|
return tr
|
||
|
|
var mark := MainTopBar.logo()
|
||
|
|
if mark:
|
||
|
|
mark.custom_minimum_size = Vector2(380, 200)
|
||
|
|
return mark
|
||
|
|
|
||
|
|
|
||
|
|
func _footer() -> PanelContainer:
|
||
|
|
var bar := PanelContainer.new()
|
||
|
|
bar.add_theme_stylebox_override("panel", Style.box(Style.BG_DEEP, 0, [32, 12, 32, 12]))
|
||
|
|
_theme_label = Style.make_label("Theme: %s" % str(ThemeStore.current.get("name", "")), Style.body(), 13, Style.ON_BG_MUTED)
|
||
|
|
bar.add_child(_theme_label)
|
||
|
|
return bar
|
||
|
|
|
||
|
|
|
||
|
|
## A tall menu button: an icon and a big title. `primary` fills it with the accent.
|
||
|
|
func _big_button(text: String, icon: String, primary: bool, on_press: Callable) -> Button:
|
||
|
|
var b := Button.new()
|
||
|
|
b.name = text
|
||
|
|
b.custom_minimum_size = Vector2(0, 66)
|
||
|
|
b.focus_mode = Control.FOCUS_NONE
|
||
|
|
var fg := Style.INK if primary else Style.ON_BG
|
||
|
|
var margins := [64, 14, 20, 14]
|
||
|
|
var normal := Style.bordered(Style.box(Style.ACCENT if primary else Color(1, 1, 1, 0.05), 10, margins), 1, Style.ACCENT if primary else Color(1, 1, 1, 0.18))
|
||
|
|
var hover := Style.bordered(Style.box(Style.ACCENT.lightened(0.12) if primary else Color(1, 1, 1, 0.1), 10, margins), 1, Style.ACCENT if primary else Color(1, 1, 1, 0.3))
|
||
|
|
Style.skin_button(b, normal, hover, hover, fg)
|
||
|
|
b.text = text
|
||
|
|
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
|
|
b.add_theme_font_override("font", Style.display())
|
||
|
|
b.add_theme_font_size_override("font_size", 28)
|
||
|
|
var icon_box := MenuIcons.make(icon, fg, 28)
|
||
|
|
icon_box.position = Vector2(22, 19)
|
||
|
|
b.add_child(icon_box)
|
||
|
|
b.pressed.connect(on_press)
|
||
|
|
buttons[text] = b
|
||
|
|
return b
|
||
|
|
|
||
|
|
|
||
|
|
func _small_button(text: String, icon: String, on_press: Callable) -> Button:
|
||
|
|
var b := Button.new()
|
||
|
|
b.name = text
|
||
|
|
b.custom_minimum_size = Vector2(0, 52)
|
||
|
|
b.size_flags_horizontal = SIZE_EXPAND_FILL
|
||
|
|
b.focus_mode = Control.FOCUS_NONE
|
||
|
|
var margins := [50, 12, 16, 12]
|
||
|
|
var normal := Style.bordered(Style.box(Color(1, 1, 1, 0.05), 10, margins), 1, Color(1, 1, 1, 0.18))
|
||
|
|
var hover := Style.bordered(Style.box(Color(1, 1, 1, 0.1), 10, margins), 1, Color(1, 1, 1, 0.3))
|
||
|
|
Style.skin_button(b, normal, hover, hover, Style.ON_BG)
|
||
|
|
b.text = text
|
||
|
|
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||
|
|
b.add_theme_font_size_override("font_size", 18)
|
||
|
|
var icon_box := MenuIcons.make(icon, Style.ON_BG, 20)
|
||
|
|
icon_box.position = Vector2(18, 16)
|
||
|
|
b.add_child(icon_box)
|
||
|
|
b.pressed.connect(on_press)
|
||
|
|
buttons[text] = b
|
||
|
|
return b
|
||
|
|
|
||
|
|
|
||
|
|
## The open spread and your newest sheets, newest first (at most three rows).
|
||
|
|
func refresh_recent() -> void:
|
||
|
|
for c in recent_rows.get_children():
|
||
|
|
recent_rows.remove_child(c)
|
||
|
|
c.queue_free()
|
||
|
|
if m.data:
|
||
|
|
var n := m.data.tables.size()
|
||
|
|
recent_rows.add_child(_recent_row(m.data.name, "Spread · %d %s" % [n, "card" if n == 1 else "cards"], "",
|
||
|
|
func() -> void: m.screens.show(MainScreens.SPREAD)))
|
||
|
|
var sheets := m.screens.sheets
|
||
|
|
for row: Dictionary in sheets.store.list().slice(0, 2):
|
||
|
|
var id := str(row["id"])
|
||
|
|
recent_rows.add_child(_recent_row(str(row["name"]), "Sheet", _ago(int(row["modified"])), func() -> void:
|
||
|
|
m.screens.show(MainScreens.SHEETS)
|
||
|
|
sheets.open_sheet(id)))
|
||
|
|
|
||
|
|
|
||
|
|
func _recent_row(title: String, sub: String, when: String, on_press: Callable) -> Button:
|
||
|
|
var b := Button.new()
|
||
|
|
b.name = title.validate_node_name()
|
||
|
|
b.focus_mode = Control.FOCUS_NONE
|
||
|
|
b.custom_minimum_size = Vector2(0, 58)
|
||
|
|
var normal := Style.box(Style.CARD, 8, [14, 10, 14, 10])
|
||
|
|
var hover := Style.box(Style.CARD_HOVER, 8, [14, 10, 14, 10])
|
||
|
|
Style.skin_button(b, normal, hover, hover, Style.INK)
|
||
|
|
var h := HBoxContainer.new()
|
||
|
|
h.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||
|
|
h.offset_left = 14
|
||
|
|
h.offset_right = -14
|
||
|
|
h.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||
|
|
b.add_child(h)
|
||
|
|
var text := VBoxContainer.new()
|
||
|
|
text.size_flags_horizontal = SIZE_EXPAND_FILL
|
||
|
|
text.alignment = BoxContainer.ALIGNMENT_CENTER
|
||
|
|
text.add_theme_constant_override("separation", 0)
|
||
|
|
text.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||
|
|
h.add_child(text)
|
||
|
|
text.add_child(Style.make_label(title, Style.body_bold(), 15, Style.INK))
|
||
|
|
text.add_child(Style.make_label(sub, Style.body(), 13, Style.MUTED))
|
||
|
|
var w := Style.make_label(when, Style.body(), 13, Style.MUTED)
|
||
|
|
w.size_flags_vertical = SIZE_SHRINK_CENTER
|
||
|
|
h.add_child(w)
|
||
|
|
b.pressed.connect(on_press)
|
||
|
|
return b
|
||
|
|
|
||
|
|
|
||
|
|
static func _ago(unix: int) -> String:
|
||
|
|
var secs := int(Time.get_unix_time_from_system()) - unix
|
||
|
|
if secs < 90:
|
||
|
|
return "just now"
|
||
|
|
if secs < 3600:
|
||
|
|
return "%d min ago" % (secs / 60)
|
||
|
|
if secs < 86400:
|
||
|
|
return "%d h ago" % (secs / 3600)
|
||
|
|
return "%d d ago" % (secs / 86400)
|
||
|
|
|
||
|
|
|
||
|
|
## The app-wide settings that live outside a spread: theme and sound.
|
||
|
|
func open_settings() -> void:
|
||
|
|
var d := ModalCard.new("Settings", 420.0)
|
||
|
|
var theme_button := ModalCard.make_button("Theme…", "plain")
|
||
|
|
theme_button.pressed.connect(func() -> void:
|
||
|
|
d.close()
|
||
|
|
m.add_child(ThemeDialog.new(m)))
|
||
|
|
d.body.add_child(theme_button)
|
||
|
|
if m.sound:
|
||
|
|
var sound_button := ModalCard.make_button("Sound…", "plain")
|
||
|
|
sound_button.pressed.connect(func() -> void:
|
||
|
|
SoundPanel.open(m, sound_button.get_global_rect().get_center()))
|
||
|
|
d.body.add_child(sound_button)
|
||
|
|
d.add_button("Done", "primary", d.close)
|
||
|
|
m._add_modal(d)
|
||
|
|
|
||
|
|
|
||
|
|
func quit() -> void:
|
||
|
|
if m._save_timer and not m._save_timer.is_stopped():
|
||
|
|
m._save_now()
|
||
|
|
m.screens.sheets.leave()
|
||
|
|
m.get_tree().quit()
|