Implemented setting/resetting entity's parent in editor

dev
Shariq Shah 6 years ago
parent a721af2279
commit 4849f7d3e4
  1. 41
      src/game/editor.c
  2. 2
      src/game/scene.c
  3. 4
      todo.txt

@ -1524,7 +1524,46 @@ void editor_window_property_inspector(struct nk_context* context, struct Editor*
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, "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, "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)); 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));
nk_layout_row_dynamic(context, row_height, 2); nk_label(context, "Parent Name", NK_TEXT_ALIGN_LEFT); nk_label(context, parent_ent ? parent_ent->name : "NONE", NK_TEXT_ALIGN_RIGHT);
nk_layout_row_dynamic(context, row_height + 5, 2);
nk_label(context, "Parent Name", NK_TEXT_ALIGN_LEFT);
static char parent_name[MAX_ENTITY_NAME_LEN];
static bool copy_parent_name = true;
if(copy_parent_name)
{
memset(parent_name, '\0', MAX_ENTITY_NAME_LEN);
strncpy(parent_name, parent_ent->name, MAX_ENTITY_NAME_LEN);
}
int rename_parent_edit_flags = NK_EDIT_GOTO_END_ON_ACTIVATE | NK_EDIT_FIELD | NK_EDIT_SIG_ENTER;
int rename_parent_edit_state = nk_edit_string_zero_terminated(context, rename_parent_edit_flags, parent_name, MAX_ENTITY_NAME_LEN, NULL);
if(rename_parent_edit_state & NK_EDIT_ACTIVATED)
{
copy_parent_name = false;
}
else if(rename_parent_edit_state & NK_EDIT_DEACTIVATED)
{
copy_parent_name = true;
}
else if(rename_parent_edit_state & NK_EDIT_COMMITED)
{
if(strncmp(parent_name, "NONE", MAX_ENTITY_NAME_LEN) == 0 || strncmp(parent_name, "ROOT", MAX_ENTITY_NAME_LEN) == 0)
{
scene_entity_parent_reset(scene, entity);
}
else
{
struct Entity* new_parent = scene_find(scene, parent_name);
if(new_parent)
scene_entity_parent_set(scene, entity, new_parent);
else
log_warning("Could not find new parent %s for %s", parent_name, entity->name);
}
copy_parent_name = true;
nk_edit_unfocus(context);
}
//nk_label(context, parent_ent ? parent_ent->name : "NONE", NK_TEXT_ALIGN_RIGHT);
/* Transform */ /* Transform */
{ {

@ -788,7 +788,7 @@ void scene_entity_parent_reset(struct Scene* scene, struct Entity* entity)
void scene_entity_parent_set(struct Scene* scene, struct Entity* entity, struct Entity* parent) void scene_entity_parent_set(struct Scene* scene, struct Entity* entity, struct Entity* parent)
{ {
assert(scene && entity && parent); assert(scene && entity && parent && entity != parent);
transform_parent_set(entity, parent, true); transform_parent_set(entity, parent, true);
} }

@ -135,6 +135,7 @@ Bugs:
- Fix weird rotational bug when rotation resets or inverts after 180 degrees - Fix weird rotational bug when rotation resets or inverts after 180 degrees
- Fix crash if player's mesh is deleted in editor - Fix crash if player's mesh is deleted in editor
- Fix camera not rotating if the cursor overlaps any ui element - Fix camera not rotating if the cursor overlaps any ui element
- Fix hierarchichal transformations in the editor when the entity being transformed is a child entity of another entity
Done: Done:
* Input * Input
@ -368,4 +369,5 @@ Done:
* Move debug vars display settings to debug_vars struct * Move debug vars display settings to debug_vars struct
* Command history in console * Command history in console
* Added button to reset local transformations for selected entity in property inspector * Added button to reset local transformations for selected entity in property inspector
* Implmented renaming scene objects in editor * Implmented renaming scene objects in editor
* Implemented setting/resetting parent entity for entity
Loading…
Cancel
Save