From ef486b7082053f5611b5bad5747b58fdf7b35450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Tue, 25 Jul 2023 19:37:13 +0200 Subject: [PATCH] Basic entity highlighting --- .../src/EditWindows/ComponentEditWindow.bf | 40 ++++++++++++++++--- .../src/EditWindows/EntityHierarchyWindow.bf | 31 ++++++++++++++ 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf index 383da96..560bd9a 100644 --- a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf +++ b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf @@ -716,6 +716,28 @@ namespace GlitchyEditor.EditWindows } } + private static Entity? ShowEntitySelector() + { + static char8[128] entitySearch = .(); + + Entity? result = null; + + if (ImGui.BeginPopup("ENTITY_SELECTOR")) + { + ImGui.TextUnformatted("Search:"); + ImGui.SameLine(); + + if (ImGui.InputText("##entitySearcher", &entitySearch, (uint64)entitySearch.Count)) + { + + } + + ImGui.EndPopup(); + } + + return result; + } + private static void ShowEntityReceiver(ScriptFieldInstance* field, StringView fieldName, ScriptClass scriptClass) { var entityId = field.GetData(); @@ -723,8 +745,10 @@ namespace GlitchyEditor.EditWindows Result fieldEntity = Editor.Instance.CurrentScene.GetEntityByID(entityId); String entityName = scope .(32); - - if (fieldEntity case .Ok(Entity e)) + + if (entityId == UUID(0)) + entityName.Set("None"); + else if (fieldEntity case .Ok(Entity e)) entityName.Set(e.Name); else entityName..Clear().AppendF($"Missing entity ({entityId})"); @@ -734,7 +758,8 @@ namespace GlitchyEditor.EditWindows if (ImGui.Button(entityName)) { - // TODO: Show a selector or something + if (fieldEntity case .Ok) + Editor.Instance.EntityHierarchyWindow.HighlightEntity(fieldEntity); } if (ImGui.BeginDragDropTarget()) @@ -783,6 +808,8 @@ namespace GlitchyEditor.EditWindows } } + //private static Entity? + private static void ShowComponentReceiver(ScriptFieldInstance* field, StringView fieldName, ScriptClass scriptClass) { var entityId = field.GetData(); @@ -791,7 +818,9 @@ namespace GlitchyEditor.EditWindows String entityName = scope .(32); - if (fieldEntity case .Ok(Entity e)) + if (entityId == UUID(0)) + entityName.Set("None"); + else if (fieldEntity case .Ok(Entity e)) entityName.Set(e.Name); else entityName..Clear().AppendF($"Missing reference ({entityId})"); @@ -801,7 +830,8 @@ namespace GlitchyEditor.EditWindows if (ImGui.Button(entityName)) { - // TODO: Show a selector or something + if (fieldEntity case .Ok) + Editor.Instance.EntityHierarchyWindow.HighlightEntity(fieldEntity); } if (ImGui.BeginDragDropTarget()) diff --git a/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf b/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf index 9cad41a..be2e65a 100644 --- a/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf +++ b/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf @@ -21,8 +21,26 @@ namespace GlitchyEditor.EditWindows private List _selectedEntities = new .() ~ delete _; + private Entity _entityToHighlight; + public List SelectedEntities => _selectedEntities; + private List _entitiesToUnfold = new .() ~ delete _; + + public void HighlightEntity(Entity e) + { + _entityToHighlight = e; + + Entity walker = _entityToHighlight; + + while (walker.Parent != null) + { + walker = walker.Parent.Value; + + _entitiesToUnfold.Add(walker); + } + } + public this(Editor editor, Scene scene) { _editor = editor; @@ -322,8 +340,21 @@ namespace GlitchyEditor.EditWindows if(inSelectedList) flags |= .Selected; + if (_entitiesToUnfold.Contains(tree.Value)) + { + _entitiesToUnfold.Remove(tree.Value); + + ImGui.SetNextItemOpen(true, .None); + } + bool isOpen = ImGui.TreeNodeEx((void*)(uint)tree.Value.Handle.[Friend]Index, flags, $"{name}"); + if (_entityToHighlight == tree.Value) + { + ImGui.SetScrollHereY(0); + _entityToHighlight = .(); + } + ImGui.PushID((void*)(uint)tree.Value.Handle.[Friend]Index); bool deleted = false;