108 lines
2.6 KiB
C
108 lines
2.6 KiB
C
#include <menu.h>
|
|
#include <menu_private.h>
|
|
#include <gui.h>
|
|
#include <gui/button.h>
|
|
#include <gui/container.h>
|
|
#include <gui/rounded_rect.h>
|
|
#include <system.h>
|
|
#include <stdbool.h>
|
|
|
|
struct main_menu
|
|
{
|
|
bool start, settings, exit;
|
|
struct gui_button play, settings_btn, exit_btn;
|
|
struct gui_container cnt;
|
|
};
|
|
|
|
static int update(struct menu_common *const c, void *const arg)
|
|
{
|
|
struct main_menu *const m = arg;
|
|
|
|
if (gui_update(&m->play.common, &c->p, &c->cam, &c->in))
|
|
return -1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int render(const struct menu_common *const c, void *const arg)
|
|
{
|
|
const struct main_menu *const m = arg;
|
|
|
|
if (gui_render(&m->cnt.common))
|
|
return -1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int menu_main(struct menu_common *const c)
|
|
{
|
|
do
|
|
{
|
|
struct main_menu m = {0};
|
|
|
|
{
|
|
struct gui_container *const c = &m.cnt;
|
|
|
|
gui_container_init(c);
|
|
c->mode = GUI_CONTAINER_MODE_V;
|
|
c->common.hcentered = true;
|
|
c->common.vcentered = true;
|
|
c->spacing = 4;
|
|
}
|
|
|
|
{
|
|
struct gui_button *const b = &m.play;
|
|
|
|
gui_button_init(b, GUI_BUTTON_TYPE_1);
|
|
b->on_pressed = menu_on_pressed;
|
|
b->arg = &m.start;
|
|
b->u.type1.w = 140;
|
|
b->common.hcentered = true;
|
|
b->u.type1.label.text = "Play";
|
|
gui_add_child(&m.cnt.common, &b->common);
|
|
}
|
|
|
|
{
|
|
struct gui_button *const b = &m.settings_btn;
|
|
|
|
gui_button_init(b, GUI_BUTTON_TYPE_1);
|
|
b->on_pressed = menu_on_pressed;
|
|
b->arg = &m.settings;
|
|
b->u.type1.w = 140;
|
|
b->common.hcentered = true;
|
|
b->u.type1.label.text = "Settings";
|
|
gui_add_child(&m.cnt.common, &b->common);
|
|
}
|
|
|
|
if (system_can_exit())
|
|
{
|
|
struct gui_button *const b = &m.exit_btn;
|
|
|
|
gui_button_init(b, GUI_BUTTON_TYPE_1);
|
|
b->arg = &m.exit;
|
|
b->u.type1.w = 140;
|
|
b->common.hcentered = true;
|
|
b->u.type1.label.text = "Exit";
|
|
b->on_pressed = menu_on_pressed;
|
|
gui_add_child(&m.cnt.common, &b->common);
|
|
}
|
|
|
|
while (!m.start && !m.settings && !c->p.common.exit)
|
|
{
|
|
if (menu_update(c, update, render, &m))
|
|
return -1;
|
|
|
|
if (m.exit)
|
|
return 0;
|
|
}
|
|
|
|
if (m.start && menu_hostjoin(c))
|
|
return -1;
|
|
else if (m.settings && menu_settings(c))
|
|
return -1;
|
|
|
|
} while (!c->p.common.exit);
|
|
|
|
return 0;
|
|
}
|