Fixed some editor bugs and did initial work on editor layouts

dev
shariq 8 years ago
parent 6a1132fa91
commit f721492a91
  1. 2612
      include/nuklear.h
  2. 4
      orgfile.org
  3. 266
      src/editor.c
  4. 2
      src/game.c
  5. 13
      src/gui.c
  6. 3
      src/gui.h

File diff suppressed because it is too large Load Diff

@ -307,7 +307,9 @@ x Log output on every run.
** DONE Variant type ** DONE Variant type
- State "DONE" from "TODO" [2017-03-22 Wed 02:14] - State "DONE" from "TODO" [2017-03-22 Wed 02:14]
** TODO Log and debug/stats output in gui ** TODO Log and debug/stats output in gui
** TODO Editor ** TODO Editor automatic window layout adjusting to the current window resolution
** DONE Editor
- State "DONE" from "TODO" [2017-06-20 Tue 01:12]
** TODO Event Subsystem ** TODO Event Subsystem
** TODO Keybindings for gui? ** TODO Keybindings for gui?
** TODO Textual/Binary format for data serialization and persistance ** TODO Textual/Binary format for data serialization and persistance

@ -30,9 +30,6 @@ struct Editor_State
{ {
bool enabled; bool enabled;
bool renderer_settings_window; bool renderer_settings_window;
bool debug_vars_window;
bool entity_list_window;
bool entity_inspector_window;
int selected_entity_id; int selected_entity_id;
int top_panel_height; int top_panel_height;
}; };
@ -53,11 +50,8 @@ void editor_init(void)
{ {
editor_state.enabled = true; editor_state.enabled = true;
editor_state.renderer_settings_window = false; editor_state.renderer_settings_window = false;
editor_state.debug_vars_window = true;
editor_state.entity_list_window = true;
editor_state.entity_inspector_window = false;
editor_state.selected_entity_id = -1; editor_state.selected_entity_id = -1;
editor_state.top_panel_height = 30; editor_state.top_panel_height = 20;
debug_vars_list = array_new(struct Debug_Variable); debug_vars_list = array_new(struct Debug_Variable);
empty_indices = array_new(int); empty_indices = array_new(int);
} }
@ -145,46 +139,150 @@ void editor_update(float dt)
int win_width = 0, win_height = 0; int win_width = 0, win_height = 0;
window_get_drawable_size(game_state->window, &win_width, &win_height); window_get_drawable_size(game_state->window, &win_width, &win_height);
int half_width = win_width / 2, half_height = win_height / 2; int half_width = win_width / 2, half_height = win_height / 2;
static int default_window_flags = NK_WINDOW_BORDER | static int window_flags = NK_WINDOW_BORDER |
NK_WINDOW_CLOSABLE | NK_WINDOW_CLOSABLE |
NK_WINDOW_MOVABLE | NK_WINDOW_MOVABLE |
NK_WINDOW_SCROLL_AUTO_HIDE | NK_WINDOW_SCROLL_AUTO_HIDE |
NK_WINDOW_SCALABLE; NK_WINDOW_SCALABLE;
/* Top Panel */ /* Main enacapsulating window */
if(nk_begin(context, "Top_Panel", nk_recti(0, 0, win_width, win_height - (win_height - editor_state.top_panel_height)), struct nk_style_item default_background = context->style.window.fixed_background;
NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR)) struct nk_vec2 default_padding = context->style.window.padding;
context->style.window.padding = nk_vec2(0.f, 0.f);
context->style.window.fixed_background = nk_style_item_hide();
if(nk_begin(context, "Editor", nk_recti(0, 0, win_width, win_height), NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_BACKGROUND))
{ {
float ratios[] = {0.1f, 0.1f, 0.1f, 0.1f, 0.5f, 0.1f}; context->style.window.fixed_background = default_background;
static int frames = 0; /* Top Panel */
static int fps = 0; nk_layout_row_dynamic(context, editor_state.top_panel_height + 10, 1);
static float seconds = 0.f; nk_group_begin(context, "Menubar", NK_WINDOW_NO_SCROLLBAR);
seconds += dt;
frames++;
if(seconds >= 1.f)
{ {
fps = frames; static float top_panel_ratios[] = {0.1f, 0.1f, 0.7f, 0.1f};
seconds = 0.f; static int frames = 0;
frames = 0; static int fps = 0;
static float seconds = 0.f;
seconds += dt;
frames++;
if(seconds >= 1.f)
{
fps = frames;
seconds = 0.f;
frames = 0;
}
nk_layout_row(context, NK_DYNAMIC, editor_state.top_panel_height, sizeof(top_panel_ratios) / sizeof(float), top_panel_ratios);
if(nk_button_label(context, "Render Settings"))
editor_state.renderer_settings_window = !editor_state.renderer_settings_window;
if(nk_button_label(context, "Save config"))
config_vars_save("config.cfg", DT_USER);
nk_spacing(context, 1);
nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "FPS : %.d", fps);
nk_group_end(context);
} }
nk_layout_row(context, NK_DYNAMIC, 22, sizeof(ratios), ratios);
if(nk_button_label(context, "Render Settings"))
editor_state.renderer_settings_window = !editor_state.renderer_settings_window; static float main_editor_ratios[] = {0.2f, 0.6f, 0.2f};
if(nk_button_label(context, "Debug Variables")) nk_layout_row(context, NK_DYNAMIC, win_height - editor_state.top_panel_height, sizeof(main_editor_ratios) / sizeof(float), main_editor_ratios);
editor_state.debug_vars_window = !editor_state.debug_vars_window;
if(nk_button_label(context, "Entities List")) /* Left */
editor_state.entity_list_window = !editor_state.entity_list_window; if(nk_group_begin(context, "Editor Left", NK_WINDOW_SCROLL_AUTO_HIDE))
if(nk_button_label(context, "Save config")) {
config_vars_save("config.cfg", DT_USER); /* Entities List */
if(nk_tree_push(context, NK_TREE_TAB, "Entities", NK_MAXIMIZED))
{
nk_layout_row_dynamic(context, 250, 1);
if(nk_group_begin(context, "Entity Name", NK_WINDOW_SCROLL_AUTO_HIDE))
{
struct Entity* entity_list = entity_get_all();
for(int i = 0; i < array_len(entity_list); i++)
{
struct Entity* entity = &entity_list[i];
nk_layout_row_dynamic(context, 20, 1);
if(nk_selectable_label(context, entity->name, NK_TEXT_ALIGN_LEFT, &entity->editor_selected))
{
log_message(entity->editor_selected ? "selected" : "deselected");
if(editor_state.selected_entity_id != -1)
{
struct Entity* currently_selected = entity_get(editor_state.selected_entity_id);
currently_selected->editor_selected = false;
}
if(entity->editor_selected)
{
editor_state.selected_entity_id = entity->id;
}
else
{
editor_state.selected_entity_id = -1;
}
}
}
nk_group_end(context);
}
nk_tree_pop(context);
}
/* Debug Variables */
if(nk_tree_push(context, NK_TREE_TAB, "Debug Variables", NK_MAXIMIZED))
{
static char variant_str[MAX_VARIANT_STR_LEN] = {'\0'};
nk_layout_row_dynamic(context, 250, 1);
if(nk_group_begin(context, "Name", NK_WINDOW_SCROLL_AUTO_HIDE))
{
for(int i = 0; i < array_len(debug_vars_list); i++)
{
struct Debug_Variable* debug_var = &debug_vars_list[i];
if(debug_var->data.type == VT_NONE) continue;
nk_layout_row_dynamic(context, 20, 2);
nk_label(context, debug_var->name, NK_TEXT_ALIGN_LEFT);
variant_to_str(&debug_var->data, variant_str, MAX_VARIANT_STR_LEN);
nk_label(context, variant_str, NK_TEXT_ALIGN_RIGHT);
memset(variant_str, '\0', MAX_VARIANT_STR_LEN);
}
nk_group_end(context);
}
nk_tree_pop(context);
}
nk_group_end(context);
}
/* Empty Space in the center */
nk_spacing(context, 1); nk_spacing(context, 1);
nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "FPS : %.d", fps);
/* Right */
if(nk_group_begin(context, "Editor Right", NK_WINDOW_NO_SCROLLBAR))
{
/* Entity Inspector */
if(nk_tree_push(context, NK_TREE_TAB, "Inspector", NK_MAXIMIZED))
{
if(editor_state.selected_entity_id != -1)
{
struct Entity* entity = entity_get(editor_state.selected_entity_id);
static const int row_height = 15;
nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "Name", NK_TEXT_ALIGN_LEFT); nk_label(context, entity->name, NK_TEXT_ALIGN_RIGHT);
nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "ID", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%d", entity->id);
}
else
{
nk_label(context, "No Entity Selected", NK_TEXT_ALIGN_CENTERED);
}
nk_tree_pop(context);
}
nk_group_end(context);
}
} }
nk_end(context); nk_end(context);
context->style.window.padding = default_padding;
/* Render Settings Window */ /* Render Settings Window */
if(editor_state.renderer_settings_window) if(editor_state.renderer_settings_window)
{ {
if(nk_begin_titled(context, "Renderer_Settings_Window", "Renderer Settings", nk_rect(half_width, half_height, 300, 350), default_window_flags)) if(nk_begin_titled(context, "Renderer_Settings_Window", "Renderer Settings", nk_rect(half_width, half_height, 300, 350), window_flags))
{ {
static struct Render_Settings render_settings; static struct Render_Settings render_settings;
renderer_settings_get(&render_settings); renderer_settings_get(&render_settings);
@ -218,11 +316,11 @@ void editor_update(float dt)
nk_layout_row_dynamic(context, 25, 2); nk_layout_row_dynamic(context, 25, 2);
nk_label(context, "Fog Mode", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); nk_label(context, "Fog Mode", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
render_settings.fog.mode = nk_combo(context, render_settings.fog.mode = nk_combo(context,
fog_modes, fog_modes,
4, 4,
render_settings.fog.mode, render_settings.fog.mode,
20, 20,
nk_vec2(180, 100)); nk_vec2(180, 100));
nk_layout_row_dynamic(context, 25, 2); nk_layout_row_dynamic(context, 25, 2);
nk_label(context, "Density", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); nk_label(context, "Density", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
@ -262,90 +360,6 @@ void editor_update(float dt)
} }
nk_end(context); nk_end(context);
} }
/* Debug Vars Window */
if(editor_state.debug_vars_window)
{
static char variant_str[MAX_VARIANT_STR_LEN] = {'\0'};
if(nk_begin_titled(context, "Debug_Variables_Window", "Debug Variables", nk_rect(723, 30, 300, 300), default_window_flags))
{
nk_layout_row_dynamic(context, 245, 1);
if(nk_group_begin(context, "Name", NK_WINDOW_BORDER | NK_WINDOW_SCROLL_AUTO_HIDE))
{
for(int i = 0; i < array_len(debug_vars_list); i++)
{
struct Debug_Variable* debug_var = &debug_vars_list[i];
if(debug_var->data.type == VT_NONE) continue;
nk_layout_row_dynamic(context, 20, 2);
nk_label(context, debug_var->name, NK_TEXT_ALIGN_LEFT);
variant_to_str(&debug_var->data, variant_str, MAX_VARIANT_STR_LEN);
nk_label(context, variant_str, NK_TEXT_ALIGN_RIGHT);
memset(variant_str, '\0', MAX_VARIANT_STR_LEN);
}
nk_group_end(context);
}
}
else
{
editor_state.debug_vars_window = false;
}
nk_end(context);
}
/* Entity List */
if(editor_state.entity_list_window)
{
if(nk_begin_titled(context, "Entites_List_Window", "Entities", nk_rect(0, 30, 250, 300), default_window_flags))
{
nk_layout_row_dynamic(context, 245, 1);
if(nk_group_begin(context, "Entity Name", NK_WINDOW_BORDER | NK_WINDOW_SCROLL_AUTO_HIDE))
{
struct Entity* entity_list = entity_get_all();
for(int i = 0; i < array_len(entity_list); i++)
{
struct Entity* entity = &entity_list[i];
nk_layout_row_dynamic(context, 20, 1);
if(nk_selectable_label(context, entity->name, NK_TEXT_ALIGN_LEFT, &entity->editor_selected))
{
log_message("selected");
if(editor_state.selected_entity_id != -1)
{
struct Entity* currently_selected = entity_get(editor_state.selected_entity_id);
currently_selected->editor_selected = false;
}
editor_state.entity_inspector_window = true;
editor_state.selected_entity_id = entity->id;
}
}
nk_group_end(context);
}
}
else
{
editor_state.entity_list_window = false;
}
nk_end(context);
}
/* Entity Inspector */
if(editor_state.entity_inspector_window && editor_state.selected_entity_id != -1)
{
struct Entity* entity = entity_get(editor_state.selected_entity_id);
if(nk_begin_titled(context, "Entity_Inspector_Window", "Inspector", nk_rect(300, 30, 300, 600), default_window_flags))
{
static const int row_height = 15;
nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "Name", NK_TEXT_ALIGN_LEFT); nk_label(context, entity->name, NK_TEXT_ALIGN_RIGHT);
nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "ID", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%d", entity->id);
}
else
{
editor_state.entity_inspector_window = false;
editor_state.selected_entity_id = -1;
}
nk_end(context);
}
} }
void editor_toggle(void) void editor_toggle(void)

@ -390,7 +390,7 @@ void debug_gui(float dt)
nk_menubar_begin(ctx); nk_menubar_begin(ctx);
nk_layout_row_begin(ctx, NK_STATIC, 25, 4); nk_layout_row_begin(ctx, NK_STATIC, 25, 4);
nk_layout_row_push(ctx, 45); nk_layout_row_push(ctx, 45);
if (nk_menu_begin_label(ctx, "MENU", NK_TEXT_LEFT, nk_vec2(120, 200))) if (nk_menu_begin_label(ctx, "Menu", NK_TEXT_LEFT, nk_vec2(120, 200)))
{ {
static size_t prog = 40; static size_t prog = 40;
static int slider = 10; static int slider = 10;

@ -31,9 +31,9 @@ static void gui_font_set_default(void);
static struct Gui_State* gui_state = NULL; static struct Gui_State* gui_state = NULL;
int gui_init(void) bool gui_init(void)
{ {
int success = 0; bool success = false;
gui_state = malloc(sizeof(*gui_state)); gui_state = malloc(sizeof(*gui_state));
if(!gui_state) if(!gui_state)
{ {
@ -90,10 +90,11 @@ int gui_init(void)
glBindVertexArray(0); glBindVertexArray(0);
platform_textinput_callback_set(&gui_handle_textinput_event); platform_textinput_callback_set(&gui_handle_textinput_event);
gui_font_set("Ubuntu-R.ttf", 14); //gui_font_set("Ubuntu-R.ttf", 14);
/* gui_font_set("FiraSans-Regular.ttf", 14); */ //gui_font_set("FiraSans-Regular.ttf", 14);
gui_font_set("RobotoCondensed-Regular.ttf", 18);
gui_theme_set(GT_RED); gui_theme_set(GT_RED);
success = 1; success = true;
return success; return success;
} }
@ -347,7 +348,7 @@ void gui_handle_textinput_event(const char* text)
void gui_handle_mousewheel_event(int x, int y) void gui_handle_mousewheel_event(int x, int y)
{ {
struct nk_context *ctx = &gui_state->context; struct nk_context *ctx = &gui_state->context;
nk_input_scroll(ctx,(float)y); nk_input_scroll(ctx, nk_vec2(x, y));
} }
struct Gui_State* gui_state_get(void) struct Gui_State* gui_state_get(void)

@ -12,6 +12,7 @@
#include <nuklear.h> #include <nuklear.h>
#include "gl_load.h" #include "gl_load.h"
#include "num_types.h"
struct Gui_State struct Gui_State
{ {
@ -41,7 +42,7 @@ enum Gui_Theme
GT_DARK GT_DARK
}; };
int gui_init(void); bool gui_init(void);
void gui_cleanup(void); void gui_cleanup(void);
void gui_render(enum nk_anti_aliasing AA); void gui_render(enum nk_anti_aliasing AA);
void gui_handle_mousewheel_event(int x, int y); void gui_handle_mousewheel_event(int x, int y);

Loading…
Cancel
Save