ludic/examples/games/menu.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

47 lines
1.8 KiB
Text

# menu.ludic — a retained-UI title screen. The UI is declared as DATA (the `ui`
# block); the engine lays it out (stacked panel, padding/gap/alignment), draws
# it (background, TrueType labels, focusable buttons), and routes keyboard focus
# and activation. The game only loads a font, opens the UI, and reads clicks.
program Menu {
# the macOS system font: the toolchain targets macOS today, and the sample keeps
# the repo free of a bundled font
const FONT_PATH: string = "/System/Library/Fonts/Supplemental/Arial.ttf"
const BACKDROP: int = 0x0e0e16
state MenuState {
title_font: int = 0
}
ui MainMenu {
panel id: Root w: 288 pad: 16 gap: 6 bg: 0x1a1a2c border: 0x4a4a72 skin: "assets/ui/panel.png" inset: 10 align: center {
label text: "CHRONO RIFT" font: MenuState.title_font size: 26 fg: 0xffe060 align: center
label text: "a Ludic retained-UI demo" font: MenuState.title_font size: 14 fg: 0x9aa0c8 align: center
spacer h: 4
button id: NewGame text: "New Game" font: MenuState.title_font size: 16 w: 236
button id: Continue text: "Continue" font: MenuState.title_font size: 16 w: 236
button id: Options text: "Options" font: MenuState.title_font size: 16 w: 236
button id: Quit text: "Quit" font: MenuState.title_font size: 16 w: 236
}
}
handler Boot(menu_st: mut MenuState) phase Start {
menu_st.title_font = Font.load(FONT_PATH)
Ui.build()
Ui.open(UI_MainMenu)
}
handler Nav phase Update {
Ui.tick(Input.key())
if Ui.clicked(UI_NewGame) { Ui.set_text(UI_NewGame, "Starting...") }
if Ui.clicked(UI_Continue) { Ui.set_text(UI_Continue, "No save") }
if Ui.clicked(UI_Options) { Ui.set_text(UI_Options, "Soon (TM)") }
if Ui.clicked(UI_Quit) { quit() }
}
handler Draw phase Render {
Screen.clear(BACKDROP)
Ui.render()
Screen.show()
}
}