Refactoring the main menu to be in a different file.

This commit is contained in:
sergiotarxz 2021-12-22 12:58:21 +01:00
parent d18b0185aa
commit 4d03f15aec
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,8 @@
#pragma once
#include <l3tde/game/map_editor.h>
void
map_editor_main_menu_render (MapEditorStatus *status);
void
map_editor_main_menu_handle_input (MapEditorStatus *status);

View File

@ -0,0 +1,50 @@
#include <l3tde/game/map_editor/main_menu.h>
#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;
}
}