@@ -194,7 +194,25 @@ void LRoomDOMNode::RoomResourceManagerHandleType(std::shared_ptr<LDOMNodeBase> s
194194}
195195
196196void BinTreeNodeUI (BIN::Model* model, uint32_t index){
197- if (ImGui::TreeNode (std::format (" Node {}" , model->mGraphNodes [index].Index ).c_str ())){
197+ bool open = ImGui::TreeNodeEx (std::format (" Node {}" , model->mGraphNodes [index].Index ).c_str (), (BinSelectedResource == &model->mGraphNodes [index] ? ImGuiTreeNodeFlags_Selected : 0 ));
198+
199+ if (index != 0 && ImGui::BeginPopupContextItem (std::format (" ##binScenegraphContextMenu{}" , index).c_str ())){
200+ if (ImGui::Selectable (" Delete" )){
201+ if (model->mGraphNodes [index].PreviousSibIndex != -1 ){
202+ model->mGraphNodes [model->mGraphNodes [index].PreviousSibIndex ].NextSibIndex = model->mGraphNodes [index].NextSibIndex ;
203+ }
204+ if (model->mGraphNodes [index].NextSibIndex != -1 ){
205+ model->mGraphNodes [model->mGraphNodes [index].NextSibIndex ].PreviousSibIndex = model->mGraphNodes [index].PreviousSibIndex ;
206+ }
207+ if (model->mGraphNodes [index].ParentIndex != -1 && model->mGraphNodes [model->mGraphNodes [index].ParentIndex ].ChildIndex == index){
208+ model->mGraphNodes [model->mGraphNodes [index].ParentIndex ].ChildIndex = model->mGraphNodes [index].NextSibIndex ;
209+ }
210+ model->mGraphNodes .erase (index);
211+ }
212+ ImGui::EndPopup ();
213+ }
214+
215+ if (open){
198216 if (ImGui::IsItemClicked (0 )){
199217 SelectedType = SelectedResourceType::GraphNode;
200218 BinSelectedResource = &model->mGraphNodes [index];
@@ -226,9 +244,39 @@ void BinTreeNodeUI(BIN::Model* model, uint32_t index){
226244 model->mGraphNodes [index].mDrawElements .erase (model->mGraphNodes [index].mDrawElements .begin () + deleteIdx);
227245 }
228246
229- if (model->mGraphNodes [index].ChildIndex != -1 ){
230- ImGui::Text (ICON_FK_LEAF " Children" );
231- BinTreeNodeUI (model, model->mGraphNodes [index].ChildIndex );
247+ bool childrenOpen = ImGui::TreeNodeEx (ICON_FK_LEAF " Children" , model->mGraphNodes [index].ChildIndex == -1 ? ImGuiTreeNodeFlags_Leaf : 0 );
248+ ImGui::SameLine ();
249+ ImGui::Spacing ();
250+ ImGui::SameLine ();
251+ ImGui::Text (ICON_FK_PLUS_CIRCLE);
252+ if (ImGui::IsItemClicked (0 )){
253+ int id = model->mGraphNodes .size ();
254+ for (int idx = 0 ; idx < model->mGraphNodes .size (); idx++){
255+ if (!model->mGraphNodes .contains (idx)){
256+ id = idx;
257+ break ;
258+ }
259+ }
260+ model->mGraphNodes [id] = {};
261+ model->mGraphNodes [id].Index = id;
262+ model->mGraphNodes [id].ParentIndex = model->mGraphNodes [index].Index ;
263+ if (model->mGraphNodes [index].ChildIndex != -1 ){
264+ for (int idx = model->mGraphNodes [index].ChildIndex ; idx != -1 ;){
265+ int nextIdx = model->mGraphNodes [idx].NextSibIndex ;
266+ if (model->mGraphNodes [idx].NextSibIndex == -1 ){
267+ model->mGraphNodes [idx].NextSibIndex = id;
268+ model->mGraphNodes [id].PreviousSibIndex = idx;
269+ }
270+ idx = nextIdx;
271+ }
272+ } else {
273+ model->mGraphNodes [index].ChildIndex = id;
274+ }
275+
276+ }
277+ if (childrenOpen){
278+ if (model->mGraphNodes [index].ChildIndex != -1 ) BinTreeNodeUI (model, model->mGraphNodes [index].ChildIndex );
279+ ImGui::TreePop ();
232280 }
233281
234282 ImGui::TreePop ();
@@ -323,7 +371,7 @@ void LRoomDOMNode::RenderHierarchyUI(std::shared_ptr<LDOMNodeBase> self, LEditor
323371
324372 if (PreviewWidget::GetFurnitureModel () != nullptr ){
325373 ImGui::SameLine ();
326- ImGui::BeginChild (" ##binEditorPanels" , {180 , 500 });
374+ ImGui::BeginChild (" ##binEditorPanels" , {250 , 500 });
327375 ImGui::Text (" SceneGraph" );
328376 ImGui::SameLine ();
329377 float widthNeeded = ImGui::CalcTextSize (" Save" ).x + ImGui::GetStyle ().FramePadding .x * 2 .f ;
@@ -340,12 +388,12 @@ void LRoomDOMNode::RenderHierarchyUI(std::shared_ptr<LDOMNodeBase> self, LEditor
340388 }
341389 }
342390 ImGui::Separator ();
343- ImGui::BeginChild (" ##binTree" , {180 , 125 });
391+ ImGui::BeginChild (" ##binTree" , {250 , 125 });
344392 BinTreeNodeUI (PreviewWidget::GetFurnitureModel (), 0 );
345393 ImGui::EndChild ();
346394 ImGui::Text (" Resources" );
347395 ImGui::Separator ();
348- ImGui::BeginChild (" ##binResources" , {180 , 125 });
396+ ImGui::BeginChild (" ##binResources" , {250 , 125 });
349397 bool open = ImGui::TreeNode (ICON_FK_CUBE " Batches" );
350398 ImGui::SameLine ();
351399 ImGui::Spacing ();
@@ -497,47 +545,47 @@ void LRoomDOMNode::RenderHierarchyUI(std::shared_ptr<LDOMNodeBase> self, LEditor
497545 ImGui::SameLine ();
498546 ImGui::Text (ICON_FK_PLUS_CIRCLE);
499547 if (ImGui::IsItemClicked (0 )){
500- int id = PreviewWidget::GetFurnitureModel ()->mTexturesHeaders .size ();
501- for (int idx = 0 ; idx < PreviewWidget::GetFurnitureModel ()->mTexturesHeaders .size (); idx++){
502- if (!PreviewWidget::GetFurnitureModel ()->mTexturesHeaders .contains (idx)){
548+ int id = PreviewWidget::GetFurnitureModel ()->mTextureHeaders .size ();
549+ for (int idx = 0 ; idx < PreviewWidget::GetFurnitureModel ()->mTextureHeaders .size (); idx++){
550+ if (!PreviewWidget::GetFurnitureModel ()->mTextureHeaders .contains (idx)){
503551 id = idx;
504552 break ;
505553 }
506554 }
507- PreviewWidget::GetFurnitureModel ()->mTexturesHeaders [id] = {};
555+ PreviewWidget::GetFurnitureModel ()->mTextureHeaders [id] = {};
508556 }
509557 if (open){
510558 uint16_t deleteIdx = UINT16_MAX;
511- for (auto [idx, texture] : PreviewWidget::GetFurnitureModel ()->mTexturesHeaders ){
559+ for (auto [idx, texture] : PreviewWidget::GetFurnitureModel ()->mTextureHeaders ){
512560 ImGui::Image (static_cast <uintptr_t >(texture.TextureID ), {16 , 16 });
513561 ImGui::SameLine ();
514- if (&PreviewWidget::GetFurnitureModel ()->mTexturesHeaders [idx] == BinSelectedResource){
562+ if (&PreviewWidget::GetFurnitureModel ()->mTextureHeaders [idx] == BinSelectedResource){
515563 ImGui::TextColored ({0x00 , 0xFF , 0x00 , 0xFF }, " Texture %d" , idx);
516564 } else {
517565 ImGui::Text (" Texture %d" , idx);
518566 }
519567 if (ImGui::IsItemClicked (0 )){
520568 SelectedType = SelectedResourceType::Texture;
521- BinSelectedResource = &PreviewWidget::GetFurnitureModel ()->mTexturesHeaders [idx];
569+ BinSelectedResource = &PreviewWidget::GetFurnitureModel ()->mTextureHeaders [idx];
522570 }
523571 if (ImGui::BeginPopupContextItem (std::format (" ##textureResourceContextMenu{}" ,idx).c_str ())){
524572 if (ImGui::Selectable (" Delete" )){
525573 deleteIdx = idx;
526574 }
527575 if (ImGui::Selectable (" Replace" )){
528576 ImGuiFileDialog::Instance ()->OpenModal (" replaceTextureImageDialog" , " Replace Texture" , " PNG Image (*.png){.png}" , OPTIONS.mRootPath );
529- BinSelectedResource = &PreviewWidget::GetFurnitureModel ()->mTexturesHeaders [idx];
577+ BinSelectedResource = &PreviewWidget::GetFurnitureModel ()->mTextureHeaders [idx];
530578 }
531579 if (ImGui::Selectable (" Export" )){
532580 ImGuiFileDialog::Instance ()->OpenModal (" exportTextureImageDialog" , " Export Texture" , " PNG Image (*.png){.png}" , OPTIONS.mRootPath );
533- BinSelectedResource = &PreviewWidget::GetFurnitureModel ()->mTexturesHeaders [idx];
581+ BinSelectedResource = &PreviewWidget::GetFurnitureModel ()->mTextureHeaders [idx];
534582 }
535583 ImGui::EndPopup ();
536584 }
537585 }
538586
539587 if (deleteIdx != UINT16_MAX){
540- PreviewWidget::GetFurnitureModel ()->mTexturesHeaders .erase (deleteIdx);
588+ PreviewWidget::GetFurnitureModel ()->mTextureHeaders .erase (deleteIdx);
541589 for (auto [idx, sampler] : PreviewWidget::GetFurnitureModel ()->mSamplers ){
542590 if (PreviewWidget::GetFurnitureModel ()->mSamplers [idx].TextureIndex == deleteIdx){
543591 PreviewWidget::GetFurnitureModel ()->mSamplers [idx].TextureIndex = -1 ;
@@ -658,7 +706,7 @@ void LRoomDOMNode::RenderHierarchyUI(std::shared_ptr<LDOMNodeBase> self, LEditor
658706 }
659707
660708 if (ImGui::BeginCombo (" Texture" , std::format (" Texture {}" , sampler->TextureIndex ).c_str ())){
661- for (auto [idx, texture] : PreviewWidget::GetFurnitureModel ()->mTexturesHeaders ){
709+ for (auto [idx, texture] : PreviewWidget::GetFurnitureModel ()->mTextureHeaders ){
662710 if (ImGui::Selectable (std::format (" Texture {}" , idx).c_str ())){
663711 sampler->TextureIndex = idx;
664712 }
0 commit comments