Adding initial editor and fields for X and Y.
This commit is contained in:
parent
4d03f15aec
commit
4e3f8400c1
@ -3,7 +3,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <form.h>
|
||||
|
||||
#include <l3tde/overworld.h>
|
||||
|
||||
#define ctrl(x) ((x) & 0x1f)
|
||||
#define KEY_INTRO '\n'
|
||||
|
||||
typedef enum {
|
||||
SELECT_MAP,
|
||||
@ -27,6 +30,8 @@ typedef struct {
|
||||
bool is_button_accept_selected;
|
||||
FIELD **fields;
|
||||
FORM *form_creation;
|
||||
L3TDEMapPtr map;
|
||||
L3TDEOverworldPtr overworld;
|
||||
} MapEditorStatus;
|
||||
|
||||
void
|
||||
|
7
include/l3tde/game/map_editor/editor.h
Normal file
7
include/l3tde/game/map_editor/editor.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <l3tde/game/map_editor.h>
|
||||
void
|
||||
map_editor_editor_render (MapEditorStatus *status);
|
||||
void
|
||||
map_editor_editor_handle_input (MapEditorStatus *status);
|
@ -13,7 +13,7 @@ typedef struct {
|
||||
typedef L3TDEOverworld * L3TDEOverworldPtr;
|
||||
|
||||
L3TDEOverworldPtr
|
||||
l3tde_overworld_create ();
|
||||
l3tde_overworld_create (void);
|
||||
|
||||
L3TDEMapPtr
|
||||
l3tde_overworld_get_map (L3TDEOverworldPtr self,
|
||||
|
@ -12,7 +12,9 @@ sources = [
|
||||
'src/overworld.c',
|
||||
'src/game.c',
|
||||
'src/game/map_editor.c',
|
||||
'src/game/map_editor/main_menu.c',
|
||||
'src/game/map_editor/creation_form.c',
|
||||
'src/game/map_editor/editor.c',
|
||||
'src/map.c',
|
||||
'src/map/warp.c',
|
||||
'src/map/node.c',
|
||||
|
@ -5,19 +5,13 @@
|
||||
#include <form.h>
|
||||
|
||||
#include <l3tde/game/map_editor.h>
|
||||
#include <l3tde/game/map_editor/main_menu.h>
|
||||
#include <l3tde/game/map_editor/creation_form.h>
|
||||
|
||||
#define KEY_INTRO '\n'
|
||||
const char *OPTIONS_STR[N_OPTIONS] = {
|
||||
"Create a new map.",
|
||||
"Open an existing map."
|
||||
};
|
||||
#include <l3tde/game/map_editor/editor.h>
|
||||
|
||||
static void
|
||||
map_editor_render (MapEditorStatus *status);
|
||||
static void
|
||||
map_editor_print_main_menu (MapEditorStatus *status);
|
||||
static void
|
||||
map_editor_handle_input (MapEditorStatus *status);
|
||||
|
||||
void
|
||||
@ -38,6 +32,7 @@ map_editor_loop () {
|
||||
status->current_form = SELECT_MAP;
|
||||
status->form_creation = NULL;
|
||||
status->fields = NULL;
|
||||
status->map = NULL;
|
||||
while (1) {
|
||||
map_editor_render (status);
|
||||
map_editor_handle_input (status);
|
||||
@ -46,57 +41,14 @@ map_editor_loop () {
|
||||
endwin ();
|
||||
}
|
||||
|
||||
static void
|
||||
map_editor_handle_input_select_map (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;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
map_editor_handle_input_map_editor (MapEditorStatus *status) {
|
||||
int input = getch ();
|
||||
switch (input) {
|
||||
case ctrl ('c'):
|
||||
case 'q':
|
||||
status->exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
map_editor_handle_input (MapEditorStatus *status) {
|
||||
switch (status->current_form) {
|
||||
case SELECT_MAP:
|
||||
map_editor_handle_input_select_map (status);
|
||||
map_editor_main_menu_handle_input (status);
|
||||
break;
|
||||
case MAP_EDITOR:
|
||||
map_editor_handle_input_map_editor (status);
|
||||
map_editor_editor_handle_input (status);
|
||||
break;
|
||||
case MAP_CREATION_FORM:
|
||||
map_editor_creation_form_handle_input (status);
|
||||
@ -109,24 +61,15 @@ map_editor_handle_input (MapEditorStatus *status) {
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
map_editor_render (MapEditorStatus *status) {
|
||||
if (status->current_form == SELECT_MAP) {
|
||||
map_editor_print_main_menu (status);
|
||||
map_editor_main_menu_render (status);
|
||||
}
|
||||
if (status->current_form == MAP_CREATION_FORM) {
|
||||
map_editor_creation_form_render (status);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
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]);
|
||||
if (status->selected_option == i) attroff (A_REVERSE);
|
||||
if (status->current_form == MAP_EDITOR) {
|
||||
map_editor_editor_render (status);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <l3tde/game/map_editor.h>
|
||||
#include <l3tde/game/map_editor/creation_form.h>
|
||||
#include <l3tde/overworld.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define BACKSPACE 127
|
||||
#define KEY_TAB '\t'
|
||||
@ -13,6 +15,14 @@ map_editor_creation_form_move_to_field (MapEditorStatus *status, int move_to);
|
||||
static FIELD *
|
||||
map_editor_get_last_field (FIELD **fields);
|
||||
|
||||
typedef enum {
|
||||
MAP_NAME_FIELD,
|
||||
MAP_DESCRIPTION_FIELD,
|
||||
X_FIELD,
|
||||
Y_FIELD,
|
||||
N_FIELDS
|
||||
} FieldsFormCreation;
|
||||
|
||||
void
|
||||
map_editor_creation_form_handle_input (MapEditorStatus *status) {
|
||||
FORM *form = status->form_creation;
|
||||
@ -28,6 +38,39 @@ map_editor_creation_form_handle_input (MapEditorStatus *status) {
|
||||
case KEY_RIGHT:
|
||||
form_driver (form, REQ_NEXT_CHAR);
|
||||
break;
|
||||
case KEY_INTRO:
|
||||
if (status->is_button_accept_selected) {
|
||||
L3TDEOverworldPtr overworld = l3tde_overworld_create ();
|
||||
char *x_str = field_buffer (status->fields[X_FIELD], 0);
|
||||
char *y_str = field_buffer (status->fields[Y_FIELD], 0);
|
||||
if (!x_str || !y_str) {
|
||||
goto cleanup_key_intro;
|
||||
}
|
||||
errno = 0;
|
||||
size_t x = strtoll (x_str, NULL, 10);
|
||||
if (errno == EINVAL || errno == ERANGE) {
|
||||
mvprintw (11, 0, "X is not a number.");
|
||||
goto cleanup_key_intro;
|
||||
}
|
||||
errno = 0;
|
||||
size_t y = strtoll (y_str, NULL, 10);
|
||||
if (errno == EINVAL || errno == ERANGE) {
|
||||
mvprintw (11, 0, "Y is not a number.");
|
||||
goto cleanup_key_intro;
|
||||
}
|
||||
status->current_form = MAP_EDITOR;
|
||||
status->overworld = overworld;
|
||||
L3TDEMapNodePtr **nodes = malloc (sizeof *nodes * x);
|
||||
for (int i = 0; i < x; i++) {
|
||||
nodes[i] = malloc (sizeof **nodes * y);
|
||||
for (int j = 0; j < y; j++) {
|
||||
nodes[i][j] = l3tde_map_node_create (overworld->terrains[0], 0);
|
||||
}
|
||||
}
|
||||
|
||||
cleanup_key_intro:
|
||||
break;
|
||||
}
|
||||
case KEY_TAB:
|
||||
case KEY_DOWN:
|
||||
if (!status->is_button_accept_selected
|
||||
@ -65,27 +108,32 @@ void
|
||||
map_editor_creation_form_render (MapEditorStatus *status) {
|
||||
if (status->first_render_map_creation_form) {
|
||||
erase ();
|
||||
status->fields = malloc (sizeof *(status->fields) * 3);
|
||||
status->fields = malloc (sizeof *(status->fields) * N_FIELDS + 1);
|
||||
curs_set (1);
|
||||
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;
|
||||
status->fields[MAP_NAME_FIELD] = new_field (1, 10, 1, 0, 50, 0);
|
||||
status->fields[MAP_DESCRIPTION_FIELD] = new_field (1, 10, 3, 0, 50, 0);
|
||||
status->fields[X_FIELD] = new_field (1, 10, 5, 0, 50, 0);
|
||||
status->fields[Y_FIELD] = new_field (1, 10, 7, 0, 50, 0);
|
||||
status->fields[N_FIELDS] = 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));
|
||||
for (int i = 0; i < N_FIELDS; i++) {
|
||||
set_field_fore (status->fields[i], COLOR_PAIR (1));
|
||||
set_field_back (status->fields[i], 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.");
|
||||
mvprintw (0, 0, "Map name.");
|
||||
mvprintw (2, 0, "Map description.");
|
||||
mvprintw (4, 0, "Set the x max value.");
|
||||
mvprintw (6, 0, "Set the y max value.");
|
||||
attron (COLOR_PAIR (1));
|
||||
mvprintw (5, 0, "Accept");
|
||||
mvprintw (9, 0, "Accept");
|
||||
attroff (COLOR_PAIR (1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
map_editor_creation_form_move_to_field (MapEditorStatus *status, int move_to) {
|
||||
FORM *form = status->form_creation;
|
||||
@ -98,7 +146,7 @@ map_editor_creation_form_move_to_field (MapEditorStatus *status, int move_to) {
|
||||
static void
|
||||
map_editor_creation_form_move_to_button_accept (MapEditorStatus *status) {
|
||||
status->is_button_accept_selected = true;
|
||||
wmove (stdscr, 5, 0);
|
||||
wmove (stdscr, 9, 0);
|
||||
}
|
||||
|
||||
static FIELD *
|
||||
|
16
src/game/map_editor/editor.c
Normal file
16
src/game/map_editor/editor.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <l3tde/game/map_editor/editor.h>
|
||||
void
|
||||
map_editor_editor_handle_input (MapEditorStatus *status) {
|
||||
int input = getch ();
|
||||
switch (input) {
|
||||
case ctrl ('c'):
|
||||
case 'q':
|
||||
status->exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
map_editor_editor_render (MapEditorStatus *status) {
|
||||
erase ();
|
||||
}
|
@ -30,7 +30,7 @@ l3tde_overworld_iterate_nodes_x_axys (
|
||||
L3TDEOverworldPtr self, JsonArray *nodes_x_axys);
|
||||
|
||||
L3TDEOverworldPtr
|
||||
l3tde_overworld_create () {
|
||||
l3tde_overworld_create (void) {
|
||||
L3TDEOverworldPtr self = malloc (sizeof *self);
|
||||
char **map_files = NULL;
|
||||
size_t map_files_len = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user