Added Editor settings window and added grid configuration to editor settings

dev
Shariq Shah 6 years ago
parent 76509ec018
commit f7a1223d98
  1. 48
      src/game/editor.c
  2. 4
      src/game/editor.h
  3. 2
      todo.txt

@ -88,10 +88,12 @@ static void editor_window_scene_heirarchy(struct nk_context* context, struct Edi
static void editor_window_debug_variables(struct nk_context* context, struct Editor* editor);
static void editor_window_property_inspector(struct nk_context* context, struct Editor* editor, struct Game_State* game_state);
static void editor_window_renderer_settings(struct nk_context* context, struct Editor* editor, struct Game_State* game_state);
static void editor_window_settings_editor(struct nk_context* context, struct Editor* editor, struct Game_State* game_state);
void editor_init(struct Editor* editor)
{
editor->renderer_settings_window = 0;
editor->window_settings_renderer = 0;
editor->window_settings_editor = 0;
editor->window_debug_variables = 0;
editor->window_property_inspector = 0;
editor->window_scene_heirarchy = 0;
@ -103,6 +105,7 @@ void editor_init(struct Editor* editor)
editor->camera_sprint_multiplier = 2.f;
editor->current_mode = EDITOR_MODE_NORMAL;
editor->current_axis = EDITOR_AXIS_XY;
editor->grid_enabled = 1;
editor->grid_num_lines = 50;
editor->grid_scale = 2.f;
vec4_fill(&editor->selected_entity_colour, 0.f, 1.f, 0.f, 1.f);
@ -155,6 +158,8 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
//Draw Grid
if(editor->grid_enabled)
{
vec3 position = { 0.f, 0.f, 0.f };
quat rotation = { 0.f, 0.f, 0.f, 1.f };
vec3 scale = { 1.f, 1.f, 1.f };
@ -168,7 +173,7 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
im_begin(position, rotation, scale, editor->grid_color, GDM_LINES);
float half_grid = editor->grid_num_lines * editor->grid_scale / 2.f;
for(int i = 0; i <= editor->grid_num_lines * editor->grid_scale; i+= editor->grid_scale)
for(float i = 0; i <= editor->grid_num_lines * editor->grid_scale; i += editor->grid_scale)
{
im_pos(-half_grid, 0.f, -half_grid + i); im_pos(half_grid, 0.f, -half_grid + i); // X
im_pos(-half_grid + i, 0.f, -half_grid); im_pos(-half_grid + i, 0.f, half_grid); // Z
@ -176,6 +181,7 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
im_end();
}
}
int editor_debugvar_slot_create(const char* name, int value_type)
{
@ -297,7 +303,8 @@ void editor_update(struct Editor* editor, float dt)
if(nk_menu_begin_label(context, "Settings", NK_TEXT_CENTERED | NK_TEXT_ALIGN_MIDDLE, nk_vec2(150, 100)))
{
nk_layout_row_dynamic(context, 25, 1);
if(nk_menu_item_label(context, "Render Settings", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE)) editor->renderer_settings_window = !editor->renderer_settings_window;
if(nk_menu_item_label(context, "Editor Settings", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE)) editor->window_settings_editor = !editor->window_settings_editor;
if(nk_menu_item_label(context, "Render Settings", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE)) editor->window_settings_renderer = !editor->window_settings_renderer;
nk_menu_end(context);
}
@ -324,7 +331,8 @@ void editor_update(struct Editor* editor, float dt)
if(editor->window_scene_heirarchy) editor_window_scene_heirarchy(context, editor, game_state);
if(editor->window_debug_variables) editor_window_debug_variables(context, editor);
if(editor->window_property_inspector) editor_window_property_inspector(context, editor, game_state);
if(editor->renderer_settings_window) editor_window_renderer_settings(context, editor, game_state);
if(editor->window_settings_renderer) editor_window_renderer_settings(context, editor, game_state);
if(editor->window_settings_editor) editor_window_settings_editor(context, editor, game_state);
}
@ -908,7 +916,37 @@ void editor_window_renderer_settings(struct nk_context* context, struct Editor*
}
else
{
editor->renderer_settings_window = 0;
editor->window_settings_renderer = 0;
}
nk_end(context);
}
void editor_window_settings_editor(struct nk_context* context, struct Editor* editor, struct Game_State* game_state)
{
int win_width = 0, win_height = 0;
window_get_drawable_size(game_state->window, &win_width, &win_height);
int half_width = win_width / 2, half_height = win_height / 2;
const int row_height = 25;
if(nk_begin_titled(context, "Window_Settings_Editor", "Editor Settings", nk_rect(half_width, half_height, 300, 350), window_flags))
{
nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "Grid Enabled", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
nk_checkbox_label(context, "", &editor->grid_enabled);
nk_layout_row_dynamic(context, row_height, 2);
nk_label(context, "Grid Color", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
editor_widget_color_combov4(context, &editor->grid_color, 200, 400);
nk_layout_row_dynamic(context, row_height, 1);
nk_property_int(context, "Grid Lines", 10, &editor->grid_num_lines, 100, 1, 1);
nk_layout_row_dynamic(context, row_height, 1);
nk_property_float(context, "Grid Scale", 0.25f, &editor->grid_scale, 10.f, 1, 0.25f);
}
else
{
editor->window_settings_editor = 0;
}
nk_end(context);
}

@ -10,7 +10,8 @@ struct Hashmap;
struct Editor
{
int renderer_settings_window;
int window_settings_renderer;
int window_settings_editor;
int window_scene_heirarchy;
int window_property_inspector;
int window_debug_variables;
@ -23,6 +24,7 @@ struct Editor
vec4 selected_entity_colour;
int current_mode;
int current_axis;
int grid_enabled;
vec4 grid_color;
int grid_num_lines;
float grid_scale;

@ -64,6 +64,7 @@ Improvements:
- Better naming semantics for examples, init/deinit for initialization and cleanup and create/destroy when memory is allocated or deallocated
- Reset mouse cursor position to the center of the screen in editor mode after the right click is released
- Categorized entity list in editor for example different subtree for lights and static meshes
- Depth testing for editor grid
- Remove fixed editor windows locations and bring back floating windows
Bugs:
@ -212,4 +213,5 @@ Done:
* Changed config vars are used.
* Changed all usages of bool types and nuklear causing buggy behaviour in editor code by using int instead of bool or by using variants of the functions that do take int as parameter instead of int*
* Added Grid to editor
* Added Editor settings window and grid configuration to editor settings window

Loading…
Cancel
Save