123 lines
3.6 KiB
Scheme
123 lines
3.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)
|
|
(mus-on Texture2D)
|
|
(mus-off 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-SIZE 64.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))
|
|
(= (. state mus-on) (LoadTexture "res/img/mus.png"))
|
|
(= (. state mus-off) (LoadTexture "res/img/mus_off.png"))
|
|
(return (page/menu state)))
|
|
|
|
(pub fn rm-menu ((state (* menu-state))) void
|
|
(if (IsTextureValid (. state bg))
|
|
(UnloadTexture (. state bg)))
|
|
(if (IsTextureValid (. state mus-on))
|
|
(UnloadTexture (. state mus-on)))
|
|
(if (IsTextureValid (. state mus-off))
|
|
(UnloadTexture (. state mus-off)))
|
|
(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-x float (- WIN-WIDTH (+ MUSIC-BTN-MARGIN MUSIC-BTN-SIZE)))
|
|
(= (. state btn-toggle-music)
|
|
(GuiButton #(Rectangle :
|
|
music-x
|
|
MUSIC-BTN-MARGIN
|
|
MUSIC-BTN-SIZE
|
|
MUSIC-BTN-SIZE) ""))
|
|
|
|
(var music-icon Texture2D (. state mus-on))
|
|
(if (! (audio-music-enabled))
|
|
(= music-icon (. state mus-off)))
|
|
(if (IsTextureValid music-icon)
|
|
(DrawTexturePro music-icon
|
|
#(Rectangle :
|
|
0.0f
|
|
0.0f
|
|
(cast (. music-icon width) float)
|
|
(cast (. music-icon height) float))
|
|
#(Rectangle :
|
|
music-x
|
|
MUSIC-BTN-MARGIN
|
|
MUSIC-BTN-SIZE
|
|
MUSIC-BTN-SIZE)
|
|
#(Vector2 : 0.0f 0.0f)
|
|
0.0f
|
|
WHITE))
|
|
|
|
(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)))
|