diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-01-28 03:01:13 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2024-01-28 15:17:49 +0100 |
| commit | fd53c7da8c5f2b79b87f624e313ff508072361ad (patch) | |
| tree | db569413cd3d42034a22368a7980aa99d7d55235 /src/menu | |
| parent | e49e3073c67af785447ddb0ecbdc521b68cf3ea9 (diff) | |
| download | jancity-fd53c7da8c5f2b79b87f624e313ff508072361ad.tar.gz | |
Big rushed update
Diffstat (limited to 'src/menu')
| -rw-r--r-- | src/menu/src/gamecfg_menu.c | 5 | ||||
| -rw-r--r-- | src/menu/src/main_menu.c | 50 | ||||
| -rw-r--r-- | src/menu/src/menu.c | 20 |
3 files changed, 70 insertions, 5 deletions
diff --git a/src/menu/src/gamecfg_menu.c b/src/menu/src/gamecfg_menu.c index 85a99d2..d85e7f6 100644 --- a/src/menu/src/gamecfg_menu.c +++ b/src/menu/src/gamecfg_menu.c @@ -736,9 +736,10 @@ int menu_gamecfg(struct menu_common *const c, struct net_host *const h, if (start) { - struct game_cfg cfg = + const struct game_cfg cfg = { - .p = &c->p + .p = &c->p, + .map = "city1.txt" }; return game(&cfg); diff --git a/src/menu/src/main_menu.c b/src/menu/src/main_menu.c index a7b9e73..8beed92 100644 --- a/src/menu/src/main_menu.c +++ b/src/menu/src/main_menu.c @@ -4,14 +4,27 @@ #include <gui/button.h> #include <gui/container.h> #include <gui/rounded_rect.h> +#include <util.h> #include <system.h> #include <stdbool.h> +enum role +{ + CREDITS_NAME_COPYRIGHT, + CREDITS_ROLE_GFX, + CREDITS_ROLE_PROGRAMMING, + CREDITS_ROLE_ENGINE, + CREDITS_ROLE_LANGUAGE, + + MAX_CREDIT_ROLES +}; + struct main_menu { bool start, settings, exit; struct gui_button play, settings_btn, exit_btn; struct gui_container cnt; + struct gui_label title, roles[MAX_CREDIT_ROLES]; }; static int update(struct menu_common *const c, void *const arg) @@ -34,6 +47,32 @@ static int render(const struct menu_common *const c, void *const arg) return 0; } +static void update_roles(struct main_menu *const m) +{ + static const char *const roles[] = + { + [CREDITS_NAME_COPYRIGHT] = "(C) 2024 Xavier Del Campo Romero", + [CREDITS_ROLE_GFX] = "Gfx: Kenney, Ivan Voirol", + [CREDITS_ROLE_PROGRAMMING] = "Coding: me", + [CREDITS_ROLE_ENGINE] = "Engine: also me lol", + [CREDITS_ROLE_LANGUAGE] = "Written in good old C" + }; + + UTIL_STATIC_ASSERT(sizeof roles / sizeof *roles + == sizeof m->roles / sizeof *m->roles, + "unexpected sizes"); + + for (size_t i = 0; i < sizeof roles / sizeof *roles; i++) + { + struct gui_label *const l = &m->roles[i]; + + gui_label_init(l); + l->common.hcentered = true; + l->text = roles[i]; + gui_add_child(&m->cnt.common, &l->common); + } +} + int menu_main(struct menu_common *const c) { do @@ -51,6 +90,15 @@ int menu_main(struct menu_common *const c) } { + struct gui_label *const l = &m.title; + + gui_label_init(l); + l->common.hcentered = true; + l->text = "Jancity, a city sandbox"; + gui_add_child(&m.cnt.common, &l->common); + } + + { struct gui_button *const b = &m.play; gui_button_init(b, GUI_BUTTON_TYPE_1); @@ -87,6 +135,8 @@ int menu_main(struct menu_common *const c) gui_add_child(&m.cnt.common, &b->common); } + update_roles(&m); + while (!m.start && !m.settings && !c->p.common.exit) { if (menu_update(c, update, render, &m)) diff --git a/src/menu/src/menu.c b/src/menu/src/menu.c index cc508e7..682c7f2 100644 --- a/src/menu/src/menu.c +++ b/src/menu/src/menu.c @@ -34,9 +34,15 @@ int menu_update(struct menu_common *const c, rect_sort(r); if (render && render(c, arg)) + { + fprintf(stderr, "%s: render cb failed\n", __func__); return -1; + } else if (input_render(&c->in, &c->p)) + { + fprintf(stderr, "%s: input_render failed\n", __func__); return -1; + } switch (c->p.common.type) { @@ -53,7 +59,10 @@ int menu_update(struct menu_common *const c, } if (gfx_draw()) + { + fprintf(stderr, "%s: gfx_draw failed\n", __func__); return -1; + } return 0; } @@ -72,11 +81,16 @@ int menu(void) peripheral_init(&cfg, &c.p); settings_load("settings.ini", &c.s); - const struct game_cfg gcfg = +#if 1 + + struct game_cfg gcfg = { - .p = &c.p, - .map = "city1.txt" + .map = "city1.txt", + .p = &c.p }; return game(&gcfg); +#else + return menu_main(&c); +#endif } |
