97 lines
2.6 KiB
Scheme
97 lines
2.6 KiB
Scheme
(include raylib.h)
|
|
(include raygui.h)
|
|
(pub import pages)
|
|
(import main)
|
|
(import utils)
|
|
(import audio)
|
|
|
|
(pub record menu-state
|
|
((app-state (* app-state))
|
|
(bg Texture2D)
|
|
(btn-to-game int)
|
|
(btn-toggle-music int)
|
|
(btn-exit int)))
|
|
|
|
(define WIN-WIDTH 1440)
|
|
(define WIN-HEIGHT 900)
|
|
|
|
(define BTN-WIDTH 320.0)
|
|
(define BTN-HEIGHT 72.0)
|
|
|
|
(define MUSIC-BTN-WIDTH 240.0)
|
|
(define MUSIC-BTN-HEIGHT 60.0)
|
|
(define MUSIC-BTN-MARGIN 40.0)
|
|
|
|
(pub fn mk-menu ((app-state (* app-state))) page
|
|
(var state _ (mem-alloc menu-state))
|
|
(= (. state app-state) app-state)
|
|
(= (. state btn-to-game) 0)
|
|
(= (. state btn-toggle-music) 0)
|
|
(= (. state btn-exit) 0)
|
|
(audio-play-menu-music)
|
|
(var img Image (LoadImage "res/img/menu.png"))
|
|
(ImageResize (& img) WIN-WIDTH WIN-HEIGHT)
|
|
(= (. state bg) (LoadTextureFromImage img))
|
|
(return (page/menu state)))
|
|
|
|
(pub fn rm-menu ((state (* menu-state))) void
|
|
(free state)
|
|
(return))
|
|
|
|
(pub fn render-menu ((state (* menu-state))) void
|
|
(BeginDrawing)
|
|
(ClearBackground BLACK)
|
|
(DrawTexture (. state bg) 0 0 WHITE)
|
|
|
|
(= (. state btn-to-game)
|
|
(GuiButton #(Rectangle : 80.0
|
|
(- WIN-HEIGHT 350.0)
|
|
BTN-WIDTH
|
|
BTN-HEIGHT) "To game"))
|
|
|
|
(= (. state btn-exit)
|
|
(GuiButton #(Rectangle : 80.0
|
|
(- WIN-HEIGHT 240.0)
|
|
BTN-WIDTH
|
|
BTN-HEIGHT) "Quit"))
|
|
|
|
(var music-label (* const char) "Music: On")
|
|
(if (! (audio-music-enabled))
|
|
(= music-label "Music: Off"))
|
|
(= (. state btn-toggle-music)
|
|
(GuiButton #(Rectangle :
|
|
(- WIN-WIDTH (+ MUSIC-BTN-MARGIN MUSIC-BTN-WIDTH))
|
|
MUSIC-BTN-MARGIN
|
|
MUSIC-BTN-WIDTH
|
|
MUSIC-BTN-HEIGHT) music-label))
|
|
|
|
(EndDrawing))
|
|
|
|
(pub fn update-menu ((state (* menu-state))) void
|
|
(var clicked bool false)
|
|
(if (== (. state btn-toggle-music) 1)
|
|
(do
|
|
(= (. state btn-toggle-music) 0)
|
|
(= clicked true)
|
|
(audio-toggle-music)))
|
|
|
|
(if (== (. state btn-to-game) 1)
|
|
(do
|
|
(= (. state btn-to-game) 0)
|
|
(= clicked true)
|
|
(.change-page (. state app-state) (sum-type page game))))
|
|
|
|
(if (== (. state btn-exit) 1)
|
|
(do
|
|
(= (. state btn-exit) 0)
|
|
(= clicked true)
|
|
(.quit (. state app-state))))
|
|
|
|
;; Any menu key press or click is a UI interaction too
|
|
(var key-pressed bool (!= 0 (GetKeyPressed)))
|
|
(var mouse-pressed bool (IsMouseButtonPressed MOUSE-BUTTON-LEFT))
|
|
(if (|| mouse-pressed key-pressed)
|
|
(audio-unlock))
|
|
(if (|| clicked key-pressed)
|
|
(audio-play-menu-click)))
|