From a721af2279c2341561cee8f1d6a51c0bb890e16a Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Fri, 20 Dec 2019 15:35:29 +1100 Subject: [PATCH] Implemented renaming entities from editor --- src/game/editor.c | 30 +++++++++++++++++++++++++++++- todo.txt | 5 +++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/game/editor.c b/src/game/editor.c index f16eb8f..e1f4c3b 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -1493,7 +1493,34 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor* struct Entity* entity = editor->selected_entity; struct Entity* parent_ent = entity->transform.parent; - 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 + 5, 2); + nk_label(context, "Name", NK_TEXT_ALIGN_LEFT); + static char entity_name[MAX_ENTITY_NAME_LEN]; + static bool copy_entity_name = true; + + if(copy_entity_name) + { + memset(entity_name, '\0', MAX_ENTITY_NAME_LEN); + strncpy(entity_name, entity->name, MAX_ENTITY_NAME_LEN); + } + + int rename_edit_flags = NK_EDIT_GOTO_END_ON_ACTIVATE | NK_EDIT_FIELD | NK_EDIT_SIG_ENTER; + int rename_edit_state = nk_edit_string_zero_terminated(context, rename_edit_flags, entity_name, MAX_ENTITY_NAME_LEN, NULL); + if(rename_edit_state & NK_EDIT_COMMITED) + { + entity_rename(entity, entity_name); + nk_edit_unfocus(context); + copy_entity_name = true; + } + else if(rename_edit_state & NK_EDIT_ACTIVATED) + { + copy_entity_name = false; + } + else if(rename_edit_state & NK_EDIT_DEACTIVATED) + { + copy_entity_name = true; + } + 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); nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Selected", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%s", (entity->flags & EF_SELECTED_IN_EDITOR) ? "True" : "False"); nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Entity Type", NK_TEXT_ALIGN_LEFT); nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%s", entity_type_name_get(entity)); @@ -1977,3 +2004,4 @@ void editor_window_settings_editor(struct nk_context* context, struct Editor* ed } nk_end(context); } + diff --git a/todo.txt b/todo.txt index c092279..bf99ef0 100644 --- a/todo.txt +++ b/todo.txt @@ -1,9 +1,9 @@ Todo: + - Implement scene save/load and entity save/load operations via editor - Add editor undo for transformation operations - Decide how to handle scale when checking sphere-ray intersection - Add material export for blender exporter? - Fix crash when exiting from fullscreen mode - - Allow renaming scene objects in editor - Check if we still need to rotate by 90 degrees when exporting from blender - Fire an event when the game mode is changed so that editor camera state and other game related systems know when to update - Add config file reloading and fire event that notifies potential listeners to update values from the new config file @@ -367,4 +367,5 @@ Done: * Shortcut key to toggle debug variable display and cycle locations * Move debug vars display settings to debug_vars struct * Command history in console - * Added button to reset local transformations for selected entity in property inspector \ No newline at end of file + * Added button to reset local transformations for selected entity in property inspector + * Implmented renaming scene objects in editor \ No newline at end of file