diff --git a/CMakeLists.txt b/CMakeLists.txt index 825f2db..f55a5a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ set(components header instance keyboard + menu mouse pad peripheral @@ -61,7 +62,7 @@ set(interfaces target_compile_options(${PROJECT_NAME} PUBLIC ${cflags}) # Dependencies for main.c -target_link_libraries(${PROJECT_NAME} PRIVATE system game) +target_link_libraries(${PROJECT_NAME} PRIVATE system menu) foreach(c ${components}) add_subdirectory("src/${c}") diff --git a/src/game/inc/game.h b/src/game/inc/game.h index 8275d54..5298b9f 100644 --- a/src/game/inc/game.h +++ b/src/game/inc/game.h @@ -1,12 +1,20 @@ #ifndef GAME_H #define GAME_H +#include + #ifdef __cplusplus extern "C" { #endif -int game(void); +struct game_cfg +{ +}; + +int game_resinit(void); +int game(const struct game_cfg *cfg); +void game_free(void); #ifdef __cplusplus } diff --git a/src/game/privinc/game_private.h b/src/game/privinc/game_private.h index 1b9449f..3ca8d62 100644 --- a/src/game/privinc/game_private.h +++ b/src/game/privinc/game_private.h @@ -6,8 +6,7 @@ extern "C" { #endif -int game_resinit(void); -void game_free(void); + #ifdef __cplusplus } diff --git a/src/game/src/game.c b/src/game/src/game.c index bcab5f2..83be2fd 100644 --- a/src/game/src/game.c +++ b/src/game/src/game.c @@ -8,13 +8,9 @@ #include #include -int game(void) +int game(const struct game_cfg *const cfg) { int ret = -1; - - if (game_resinit()) - goto end; - enum {HUMAN_PLAYERS = 1, MAP_RESOURCES = 3}; struct human_player humans[HUMAN_PLAYERS]; struct terrain_map map; @@ -109,6 +105,5 @@ int game(void) ret = 0; end: - game_free(); return ret; } diff --git a/src/main.c b/src/main.c index fd0759f..8933639 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,7 +6,7 @@ int main(void) { int ret = EXIT_SUCCESS; - if (system_init() || game()) + if (system_init() || menu()) ret = EXIT_FAILURE; system_deinit(); diff --git a/src/menu/CMakeLists.txt b/src/menu/CMakeLists.txt new file mode 100644 index 0000000..c4adb09 --- /dev/null +++ b/src/menu/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(menu + "src/menu.c" +) +target_include_directories(menu PUBLIC "inc") +target_link_libraries(menu PRIVATE camera game gfx gui system) diff --git a/src/menu/inc/menu.h b/src/menu/inc/menu.h new file mode 100644 index 0000000..4e92a3f --- /dev/null +++ b/src/menu/inc/menu.h @@ -0,0 +1,15 @@ +#ifndef MENU_H +#define MENU_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +int menu(void); + +#ifdef __cplusplus +} +#endif + +#endif /* MENU_H */ diff --git a/src/menu/src/menu.c b/src/menu/src/menu.c new file mode 100644 index 0000000..12da1a8 --- /dev/null +++ b/src/menu/src/menu.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +static void on_pressed(void *const arg) +{ + *(bool *)arg = true; +} + +int menu(void) +{ + struct camera cam = {0}; + struct gui_button play; + union peripheral p; + bool start = false; + + if (game_resinit()) + return -1; + + cursor_init(&cam.cursor); + gui_button_init(&play); + play.on_pressed = on_pressed; + play.arg = &start; + play.w = 140; + play.label.text = "Play"; + + { + 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); + + play.common.x = screen_w / 2 - play.w / 2; + play.common.y = screen_h / 2 - 20; + play.label.common.x = play.w / 2 - 20; + play.label.common.y = 4; + + 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) + return 0; + + if (gui_render(&play.common) + || cursor_render(&cam.cursor) + || gfx_draw()) + return -1; + } + + return game(NULL); +}