@@ -16,6 +16,11 @@ const float icon_size = 64.0f;
1616const float padding = 10 .0f ;
1717const float cell_size = icon_size + padding;
1818
19+ static void assign_entity_name (Entity& entity, const char * new_name) {
20+ if (!new_name || new_name[0 ] == ' \0 ' ) return ;
21+ entity.name = new_name;
22+ }
23+
1924void Editor::handle_input () {
2025 float speed = 0 .1f ;
2126 Entity* e = scene.get_selected ();
@@ -113,8 +118,8 @@ void Editor::draw_ui(Shader shader) {
113118
114119 if (ImGui::MenuItem (" Dublicate" )) {
115120 Entity ent_copy = ent;
116- ent_copy.name = ent.name + " copy" ;
117121 ent_copy.id = static_cast <int >(scene.entities .size ());
122+ ent_copy.name = scene.make_default_name_for (ent_copy);
118123 scene.entities .push_back (ent_copy);
119124 }
120125
@@ -130,10 +135,10 @@ void Editor::draw_ui(Shader shader) {
130135 if (ImGui::MenuItem (a.name .c_str ())) {
131136 Entity e;
132137 e.id = static_cast <int >(scene.entities .size ());
133- e.name = " Object " + std::to_string (e.id );
134138 e.type = a.type ;
135139 e.asset = &a;
136140 e.segments = 16 ;
141+ e.name = scene.make_default_name_for (e);
137142
138143 if (a.isProcedural ) {
139144 e.model = a.generator (e.segments );
@@ -153,14 +158,13 @@ void Editor::draw_ui(Shader shader) {
153158
154159 if (renaming_index != -1 ) {
155160 ImGui::OpenPopup (" Rename" );
156- renaming_index = -2 ;
157161 }
158162
159163 if (ImGui::BeginPopupModal (" Rename" , nullptr , ImGuiWindowFlags_AlwaysAutoResize)) {
160164 ImGui::InputText (" ##rename" , rename_buf, IM_ARRAYSIZE (rename_buf));
161165 if (ImGui::Button (" OK" )) {
162- if (renaming_index == - 2 ) {
163- scene.entities [scene. selected ]. name = rename_buf;
166+ if (renaming_index >= 0 && renaming_index < static_cast < int >(scene. entities . size ()) ) {
167+ assign_entity_name ( scene.entities [renaming_index], rename_buf) ;
164168 }
165169 renaming_index = -1 ;
166170 ImGui::CloseCurrentPopup ();
@@ -187,6 +191,14 @@ void Editor::draw_ui(Shader shader) {
187191
188192 Entity* e = scene.get_selected ();
189193 if (e) {
194+ ImGui::Separator ();
195+ char inspector_name[128 ] = {};
196+ const size_t copied = e->name .copy (inspector_name, sizeof (inspector_name) - 1 );
197+ inspector_name[copied] = ' \0 ' ;
198+ if (ImGui::InputText (" Name" , inspector_name, IM_ARRAYSIZE (inspector_name))) {
199+ assign_entity_name (*e, inspector_name);
200+ }
201+
190202 ImGui::Separator ();
191203 ImGui::Text (" Transform" );
192204 float pos[3 ] = { e->position .x , e->position .y , e->position .z };
@@ -334,13 +346,11 @@ void Editor::draw_ui(Shader shader) {
334346 ImGui::InputFloat (" Intensity" , &e->light .intensity , 0 .1f , 1 .0f , " %.2f" );
335347 ImGui::InputFloat (" Range" , &e->light .range , 0 .1f , 1 .0f , " %.2f" );
336348
337- static int light_counter = 0 ;
338-
339349 if (!e->light_created )
340350 {
341351 e->light = create_lighting (e->position , e->light .color );
342352
343- e->light .id = light_counter++ ;
353+ e->light .id = allocate_light_id () ;
344354 e->light .light = CreateLight (LIGHT_POINT , e->position , Vector3Zero (), e->light .color , shader);
345355
346356 e->light_created = true ;
@@ -520,4 +530,4 @@ void Editor::draw_assets_ui() {
520530 }
521531
522532 ImGui::End ();
523- }
533+ }
0 commit comments