Refactoring the main menu to be in a different file.
This commit is contained in:
parent
d18b0185aa
commit
4d03f15aec
8
include/l3tde/game/map_editor/main_menu.h
Normal file
8
include/l3tde/game/map_editor/main_menu.h
Normal 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);
|
50
src/game/map_editor/main_menu.c
Normal file
50
src/game/map_editor/main_menu.c
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user