Adding a enter button.
This commit is contained in:
parent
5579d66080
commit
cfb5dd00f3
|
@ -7,6 +7,9 @@
|
|||
#include <l3tde/game/map_editor.h>
|
||||
|
||||
#define BACKSPACE 127
|
||||
#define KEY_INTRO '\n'
|
||||
#define KEY_TAB '\t'
|
||||
#define ctrl(x) ((x) & 0x1f)
|
||||
|
||||
typedef enum {
|
||||
SELECT_MAP,
|
||||
|
@ -75,7 +78,7 @@ static void
|
|||
map_editor_handle_input_select_map (MapEditorStatus *status) {
|
||||
int input = getch ();
|
||||
switch (input) {
|
||||
case '\n':
|
||||
case KEY_INTRO:
|
||||
if (status->selected_option == CREATE_NEW_MAP) {
|
||||
status->first_render_map_creation_form = true;
|
||||
status->current_form = MAP_CREATION_FORM;
|
||||
|
@ -96,6 +99,7 @@ map_editor_handle_input_select_map (MapEditorStatus *status) {
|
|||
}
|
||||
break;
|
||||
case 'q':
|
||||
case ctrl ('c'):
|
||||
status->exit = true;
|
||||
break;
|
||||
}
|
||||
|
@ -105,6 +109,7 @@ static void
|
|||
map_editor_handle_input_map_editor (MapEditorStatus *status) {
|
||||
int input = getch ();
|
||||
switch (input) {
|
||||
case ctrl ('c'):
|
||||
case 'q':
|
||||
status->exit = true;
|
||||
break;
|
||||
|
@ -138,19 +143,33 @@ map_editor_render_map_creation_form (MapEditorStatus *status) {
|
|||
status->fields[0] = new_field (1, 10, 1, 0, 50, 0);
|
||||
status->fields[1] = new_field (1, 10, 3, 0, 50, 0);
|
||||
status->fields[2] = NULL;
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLUE);
|
||||
set_field_fore (status->fields[0], COLOR_PAIR(1));
|
||||
set_field_back (status->fields[0], COLOR_PAIR(1));
|
||||
set_field_fore (status->fields[1], COLOR_PAIR(1));
|
||||
set_field_back (status->fields[1], COLOR_PAIR(1));
|
||||
status->form_creation = new_form(status->fields);
|
||||
init_pair (1, COLOR_WHITE, COLOR_BLUE);
|
||||
set_field_fore (status->fields[0], COLOR_PAIR (1));
|
||||
set_field_back (status->fields[0], COLOR_PAIR (1));
|
||||
set_field_fore (status->fields[1], COLOR_PAIR (1));
|
||||
set_field_back (status->fields[1], COLOR_PAIR (1));
|
||||
status->form_creation = new_form (status->fields);
|
||||
post_form (status->form_creation);
|
||||
status->first_render_map_creation_form = false;
|
||||
mvprintw (0, 0, "Set the x max value.");
|
||||
mvprintw (2, 0, "Set the y max value.");
|
||||
attron (COLOR_PAIR (1));
|
||||
mvprintw (5, 0, "Accept");
|
||||
attroff (COLOR_PAIR (1));
|
||||
}
|
||||
}
|
||||
|
||||
static FIELD *
|
||||
map_editor_get_last_field (FIELD **fields) {
|
||||
FIELD *last_field = NULL;
|
||||
size_t i = 0;
|
||||
do {
|
||||
last_field = fields[i];
|
||||
i++;
|
||||
} while (fields[i] != NULL);
|
||||
return last_field;
|
||||
}
|
||||
|
||||
static void
|
||||
map_editor_render (MapEditorStatus *status) {
|
||||
if (status->current_form == SELECT_MAP) {
|
||||
|
@ -166,7 +185,7 @@ map_editor_print_main_menu (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]);
|
||||
mvprintw (i, 0, "%s", OPTIONS_STR[i]);
|
||||
if (status->selected_option == i) attroff (A_REVERSE);
|
||||
}
|
||||
}
|
||||
|
@ -175,19 +194,36 @@ static void
|
|||
map_editor_handle_input_creation_form (MapEditorStatus *status) {
|
||||
FORM *form = status->form_creation;
|
||||
int ch;
|
||||
ch = getch();
|
||||
switch(ch) {
|
||||
ch = getch ();
|
||||
switch (ch) {
|
||||
case BACKSPACE:
|
||||
form_driver(form, REQ_DEL_PREV);
|
||||
form_driver (form, REQ_DEL_PREV);
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
form_driver(form, REQ_PREV_CHAR);
|
||||
form_driver (form, REQ_PREV_CHAR);
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
form_driver(form, REQ_NEXT_CHAR);
|
||||
form_driver (form, REQ_NEXT_CHAR);
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
if (map_editor_get_last_field (status->fields)
|
||||
== current_field (status->form_creation)) {
|
||||
wmove (stdscr, 5, 0);
|
||||
} else {
|
||||
form_driver (form, REQ_NEXT_FIELD);
|
||||
}
|
||||
break;
|
||||
case KEY_TAB:
|
||||
form_driver (form, REQ_NEXT_FIELD);
|
||||
break;
|
||||
case KEY_UP:
|
||||
form_driver (form, REQ_PREV_FIELD);
|
||||
break;
|
||||
case ctrl ('c'):
|
||||
status->exit = 1;
|
||||
break;
|
||||
default:
|
||||
form_driver(form, ch);
|
||||
form_driver (form, ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue