83 lines
1.7 KiB
C
83 lines
1.7 KiB
C
#include <menu.h>
|
|
#include <camera.h>
|
|
#include <game.h>
|
|
#include <gfx.h>
|
|
#include <gui.h>
|
|
#include <gui/button.h>
|
|
#include <gui/container.h>
|
|
#include <system.h>
|
|
#include <stdbool.h>
|
|
|
|
static void on_pressed(void *const arg)
|
|
{
|
|
*(bool *)arg = true;
|
|
}
|
|
|
|
int menu(void)
|
|
{
|
|
struct camera cam = {0};
|
|
struct gui_button play, exit_btn;
|
|
struct gui_container cnt;
|
|
union peripheral p;
|
|
bool start = false, exit = false;
|
|
|
|
if (game_resinit())
|
|
return -1;
|
|
|
|
cursor_init(&cam.cursor);
|
|
gui_container_init(&cnt);
|
|
cnt.mode = GUI_CONTAINER_MODE_V;
|
|
cnt.common.hcentered = true;
|
|
cnt.common.vcentered = true;
|
|
gui_button_init(&play);
|
|
gui_button_init(&exit_btn);
|
|
play.on_pressed = on_pressed;
|
|
play.arg = &start;
|
|
play.w = 140;
|
|
play.common.hcentered = true;
|
|
play.label.text = "Play";
|
|
|
|
exit_btn.arg = &exit;
|
|
exit_btn.w = 140;
|
|
exit_btn.common.hcentered = true;
|
|
exit_btn.label.text = "Exit";
|
|
exit_btn.on_pressed = on_pressed;
|
|
gui_add_child(&cnt.common, &play.common);
|
|
gui_add_child(&cnt.common, &exit_btn.common);
|
|
|
|
{
|
|
const struct peripheral_cfg cfg =
|
|
{
|
|
.type = PERIPHERAL_TYPE_KEYBOARD_MOUSE
|
|
};
|
|
|
|
peripheral_init(&cfg, &p);
|
|
}
|
|
|
|
while (!start)
|
|
{
|
|
system_loop();
|
|
peripheral_update(&p);
|
|
camera_update(&cam, &p);
|
|
|
|
if (gui_update(&play.common, &p, &cam))
|
|
return -1;
|
|
|
|
rect_get_or_ret(r, -1);
|
|
rect_init(r);
|
|
r->w = screen_w;
|
|
r->h = screen_h;
|
|
rect_sort(r);
|
|
|
|
if (p.common.exit || exit)
|
|
return 0;
|
|
|
|
if (gui_render(&cnt.common)
|
|
|| cursor_render(&cam.cursor)
|
|
|| gfx_draw())
|
|
return -1;
|
|
}
|
|
|
|
return game(NULL);
|
|
}
|