diff --git a/include/l3tde/game/map_editor/main_menu.h b/include/l3tde/game/map_editor/main_menu.h new file mode 100644 index 0000000..d1da176 --- /dev/null +++ b/include/l3tde/game/map_editor/main_menu.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +void +map_editor_main_menu_render (MapEditorStatus *status); +void +map_editor_main_menu_handle_input (MapEditorStatus *status); diff --git a/src/game/map_editor/main_menu.c b/src/game/map_editor/main_menu.c new file mode 100644 index 0000000..8494901 --- /dev/null +++ b/src/game/map_editor/main_menu.c @@ -0,0 +1,50 @@ +#include + +#define KEY_INTRO '\n' + +static const char *OPTIONS_STR[N_OPTIONS] = { + "Create a new map.", + "Open an existing map." +}; + +void +map_editor_main_menu_render (MapEditorStatus *status) { + erase (); + for (int i = 0; i < N_OPTIONS; i++) { + if (status->selected_option == i) attron (A_REVERSE); + mvprintw (i, 0, "%s", OPTIONS_STR[i]); + if (status->selected_option == i) attroff (A_REVERSE); + } +} + +void +map_editor_main_menu_handle_input (MapEditorStatus *status) { + int input = getch (); + switch (input) { + case KEY_INTRO: + if (status->selected_option == CREATE_NEW_MAP) { + status->first_render_map_creation_form = true; + status->is_button_accept_selected = false; + status->current_form = MAP_CREATION_FORM; + } + break; + case KEY_DOWN: + if (status->selected_option < N_OPTIONS - 1) { + status->selected_option++; + } else { + status->selected_option = 0; + } + break; + case KEY_UP: + if (status->selected_option > 0) { + status->selected_option--; + } else { + status->selected_option = N_OPTIONS - 1; + } + break; + case 'q': + case ctrl ('c'): + status->exit = true; + break; + } +}