Added entity list viewer to editor which shows all entities currently in the scene

dev
shariq 8 years ago
parent 908181fac1
commit 6a1132fa91
  1. 79
      src/editor.c
  2. 5
      src/entity.c
  3. 1
      src/entity.h

@ -29,8 +29,11 @@
struct Editor_State struct Editor_State
{ {
bool enabled; bool enabled;
int renderer_settings_window; bool renderer_settings_window;
int debug_vars_window; bool debug_vars_window;
bool entity_list_window;
bool entity_inspector_window;
int selected_entity_id;
int top_panel_height; int top_panel_height;
}; };
@ -49,8 +52,11 @@ static void editor_color_combo(struct nk_context* context, vec4* color, int widt
void editor_init(void) void editor_init(void)
{ {
editor_state.enabled = true; editor_state.enabled = true;
editor_state.renderer_settings_window = 0; editor_state.renderer_settings_window = false;
editor_state.debug_vars_window = 1; 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.top_panel_height = 30; editor_state.top_panel_height = 30;
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);
@ -149,7 +155,7 @@ void editor_update(float dt)
if(nk_begin(context, "Top_Panel", nk_recti(0, 0, win_width, win_height - (win_height - editor_state.top_panel_height)), if(nk_begin(context, "Top_Panel", nk_recti(0, 0, win_width, win_height - (win_height - editor_state.top_panel_height)),
NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR)) NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR))
{ {
float ratios[] = {0.1f, 0.1f, 0.1f, 0.6f, 0.1f}; float ratios[] = {0.1f, 0.1f, 0.1f, 0.1f, 0.5f, 0.1f};
static int frames = 0; static int frames = 0;
static int fps = 0; static int fps = 0;
static float seconds = 0.f; static float seconds = 0.f;
@ -166,6 +172,8 @@ void editor_update(float dt)
editor_state.renderer_settings_window = !editor_state.renderer_settings_window; editor_state.renderer_settings_window = !editor_state.renderer_settings_window;
if(nk_button_label(context, "Debug Variables")) if(nk_button_label(context, "Debug Variables"))
editor_state.debug_vars_window = !editor_state.debug_vars_window; editor_state.debug_vars_window = !editor_state.debug_vars_window;
if(nk_button_label(context, "Entities List"))
editor_state.entity_list_window = !editor_state.entity_list_window;
if(nk_button_label(context, "Save config")) if(nk_button_label(context, "Save config"))
config_vars_save("config.cfg", DT_USER); config_vars_save("config.cfg", DT_USER);
nk_spacing(context, 1); nk_spacing(context, 1);
@ -259,9 +267,9 @@ void editor_update(float dt)
if(editor_state.debug_vars_window) if(editor_state.debug_vars_window)
{ {
static char variant_str[MAX_VARIANT_STR_LEN] = {'\0'}; static char variant_str[MAX_VARIANT_STR_LEN] = {'\0'};
if(nk_begin_titled(context, "Debug_Variables_Window", "Debug Variables", nk_rect(725, 30, 300, 300), default_window_flags)) if(nk_begin_titled(context, "Debug_Variables_Window", "Debug Variables", nk_rect(723, 30, 300, 300), default_window_flags))
{ {
nk_layout_row_static(context, 250, 250, 2); nk_layout_row_dynamic(context, 245, 1);
if(nk_group_begin(context, "Name", NK_WINDOW_BORDER | NK_WINDOW_SCROLL_AUTO_HIDE)) 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++) for(int i = 0; i < array_len(debug_vars_list); i++)
@ -279,7 +287,62 @@ void editor_update(float dt)
} }
else else
{ {
editor_state.debug_vars_window = 0; 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); nk_end(context);
} }

@ -59,6 +59,7 @@ void entity_remove(int index)
entity->id = -1; entity->id = -1;
entity->is_listener = false; entity->is_listener = false;
entity->marked_for_deletion = false; entity->marked_for_deletion = false;
entity->editor_selected = 0;
entity->renderable = false; entity->renderable = false;
entity->name = NULL; entity->name = NULL;
free(entity->name); free(entity->name);
@ -90,6 +91,7 @@ struct Entity* entity_create(const char* name, const int type, int parent_id)
new_entity->type = type; new_entity->type = type;
new_entity->marked_for_deletion = false; new_entity->marked_for_deletion = false;
new_entity->renderable = false; new_entity->renderable = false;
new_entity->editor_selected = 0;
transform_create(new_entity, parent_id); transform_create(new_entity, parent_id);
return new_entity; return new_entity;
} }
@ -268,7 +270,8 @@ struct Entity* entity_load(const char* filename, int directory_type)
.is_listener = false, .is_listener = false,
.renderable = false, .renderable = false,
.marked_for_deletion = false, .marked_for_deletion = false,
.name = NULL .name = NULL,
.editor_selected = 0
}; };
char* material_name = NULL; char* material_name = NULL;

@ -95,6 +95,7 @@ struct Entity
bool is_listener; /* TODO: Replace all booleans with flags */ bool is_listener; /* TODO: Replace all booleans with flags */
bool marked_for_deletion; bool marked_for_deletion;
bool renderable; bool renderable;
int editor_selected;
struct Transform transform; struct Transform transform;
union union

Loading…
Cancel
Save