From 752efaa522ce605d5bdeef2c0aa4587b5aa8ded5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Fri, 20 Jan 2023 21:02:46 +0100 Subject: [PATCH] editor: entity name filtering --- Editor/Editor.cpp | 5 +++ Editor/OptionsWindow.cpp | 77 ++++++++++++++++++++++++-------------- Editor/OptionsWindow.h | 1 + WickedEngine/wiBacklog.cpp | 1 + WickedEngine/wiGUI.cpp | 14 +++++++ WickedEngine/wiGUI.h | 6 +++ WickedEngine/wiVersion.cpp | 2 +- 7 files changed, 77 insertions(+), 29 deletions(-) diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index b3911423a..71ac80914 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -1695,6 +1695,11 @@ void EditorComponent::Update(float dt) { wi::renderer::SetToDrawDebugColliders(optionsWnd.generalWnd.colliderVisCheckBox.GetCheck()); } + + if (optionsWnd.filterInput.GetState() == wi::gui::WIDGETSTATE::ACTIVE) + { + optionsWnd.RefreshEntityTree(); + } } void EditorComponent::PostUpdate() { diff --git a/Editor/OptionsWindow.cpp b/Editor/OptionsWindow.cpp index 49a55a8b0..34cc628a9 100644 --- a/Editor/OptionsWindow.cpp +++ b/Editor/OptionsWindow.cpp @@ -178,31 +178,31 @@ void OptionsWindow::Create(EditorComponent* _editor) - filterCombo.Create("Filter: "); - filterCombo.AddItem("All " ICON_FILTER, (uint64_t)Filter::All); - filterCombo.AddItem("Transform " ICON_TRANSFORM, (uint64_t)Filter::Transform); - filterCombo.AddItem("Material " ICON_MATERIAL, (uint64_t)Filter::Material); - filterCombo.AddItem("Mesh " ICON_MESH, (uint64_t)Filter::Mesh); - filterCombo.AddItem("Object " ICON_OBJECT, (uint64_t)Filter::Object); - filterCombo.AddItem("Environment Probe " ICON_ENVIRONMENTPROBE, (uint64_t)Filter::EnvironmentProbe); - filterCombo.AddItem("Decal " ICON_DECAL, (uint64_t)Filter::Decal); - filterCombo.AddItem("Sound " ICON_SOUND, (uint64_t)Filter::Sound); - filterCombo.AddItem("Weather " ICON_WEATHER, (uint64_t)Filter::Weather); - filterCombo.AddItem("Light " ICON_POINTLIGHT, (uint64_t)Filter::Light); - filterCombo.AddItem("Animation " ICON_ANIMATION, (uint64_t)Filter::Animation); - filterCombo.AddItem("Force " ICON_FORCE, (uint64_t)Filter::Force); - filterCombo.AddItem("Emitter " ICON_EMITTER, (uint64_t)Filter::Emitter); - filterCombo.AddItem("Hairparticle " ICON_HAIR, (uint64_t)Filter::Hairparticle); - filterCombo.AddItem("Inverse Kinematics " ICON_IK, (uint64_t)Filter::IK); - filterCombo.AddItem("Camera " ICON_CAMERA, (uint64_t)Filter::Camera); - filterCombo.AddItem("Armature " ICON_ARMATURE, (uint64_t)Filter::Armature); - filterCombo.AddItem("Spring " ICON_SPRING, (uint64_t)Filter::Spring); - filterCombo.AddItem("Collider " ICON_COLLIDER, (uint64_t)Filter::Collider); - filterCombo.AddItem("Script " ICON_SCRIPT, (uint64_t)Filter::Script); - filterCombo.AddItem("Expression " ICON_EXPRESSION, (uint64_t)Filter::Expression); - filterCombo.AddItem("Humanoid " ICON_HUMANOID, (uint64_t)Filter::Humanoid); - filterCombo.AddItem("Terrain " ICON_TERRAIN, (uint64_t)Filter::Terrain); - filterCombo.SetTooltip("Apply filtering to the Entities"); + filterCombo.Create(""); + filterCombo.AddItem("", (uint64_t)Filter::All); + filterCombo.AddItem(ICON_TRANSFORM, (uint64_t)Filter::Transform); + filterCombo.AddItem(ICON_MATERIAL, (uint64_t)Filter::Material); + filterCombo.AddItem(ICON_MESH, (uint64_t)Filter::Mesh); + filterCombo.AddItem(ICON_OBJECT, (uint64_t)Filter::Object); + filterCombo.AddItem(ICON_ENVIRONMENTPROBE, (uint64_t)Filter::EnvironmentProbe); + filterCombo.AddItem(ICON_DECAL, (uint64_t)Filter::Decal); + filterCombo.AddItem(ICON_SOUND, (uint64_t)Filter::Sound); + filterCombo.AddItem(ICON_WEATHER, (uint64_t)Filter::Weather); + filterCombo.AddItem(ICON_POINTLIGHT, (uint64_t)Filter::Light); + filterCombo.AddItem(ICON_ANIMATION, (uint64_t)Filter::Animation); + filterCombo.AddItem(ICON_FORCE, (uint64_t)Filter::Force); + filterCombo.AddItem(ICON_EMITTER, (uint64_t)Filter::Emitter); + filterCombo.AddItem(ICON_HAIR, (uint64_t)Filter::Hairparticle); + filterCombo.AddItem(ICON_IK, (uint64_t)Filter::IK); + filterCombo.AddItem(ICON_CAMERA, (uint64_t)Filter::Camera); + filterCombo.AddItem(ICON_ARMATURE, (uint64_t)Filter::Armature); + filterCombo.AddItem(ICON_SPRING, (uint64_t)Filter::Spring); + filterCombo.AddItem(ICON_COLLIDER, (uint64_t)Filter::Collider); + filterCombo.AddItem(ICON_SCRIPT, (uint64_t)Filter::Script); + filterCombo.AddItem(ICON_EXPRESSION, (uint64_t)Filter::Expression); + filterCombo.AddItem(ICON_HUMANOID, (uint64_t)Filter::Humanoid); + filterCombo.AddItem(ICON_TERRAIN, (uint64_t)Filter::Terrain); + filterCombo.SetTooltip("Apply filtering to the Entities by components"); filterCombo.OnSelect([&](wi::gui::EventArgs args) { filter = (Filter)args.userdata; RefreshEntityTree(); @@ -210,6 +210,13 @@ void OptionsWindow::Create(EditorComponent* _editor) AddWidget(&filterCombo); + filterInput.Create(""); + filterInput.SetTooltip("Apply filtering to the Entities by name"); + filterInput.SetDescription(ICON_FILTER ": "); + filterInput.SetCancelInputEnabled(false); + AddWidget(&filterInput); + + entityTree.Create("Entities"); entityTree.SetSize(XMFLOAT2(300, 300)); entityTree.OnSelect([this](wi::gui::EventArgs args) { @@ -327,11 +334,20 @@ void OptionsWindow::ResizeLayout() pos.y += newCombo.GetSize().y; pos.y += padding; - filterCombo.SetPos(XMFLOAT2(pos.x + x_off, pos.y)); - filterCombo.SetSize(XMFLOAT2(width - x_off - filterCombo.GetScale().y - 1, filterCombo.GetScale().y)); + + + float filterComboWidth = 30; + + filterInput.SetPos(XMFLOAT2(pos.x + x_off, pos.y)); + filterInput.SetSize(XMFLOAT2(width - x_off - filterInput.GetScale().y - 3 - filterComboWidth, filterCombo.GetScale().y)); + + filterCombo.SetPos(XMFLOAT2(filterInput.GetPos().x + filterInput.GetSize().x + 2, pos.y)); + filterCombo.SetSize(XMFLOAT2(filterComboWidth, filterCombo.GetScale().y)); pos.y += filterCombo.GetSize().y; pos.y += padding; + + entityTree.SetPos(pos); entityTree.SetSize(XMFLOAT2(width, std::max(editor->GetLogicalHeight() * 0.75f, editor->GetLogicalHeight() - pos.y))); pos.y += entityTree.GetSize().y; @@ -353,6 +369,12 @@ void OptionsWindow::PushToEntityTree(wi::ecs::Entity entity, int level) item.selected = editor->IsSelected(entity); item.open = entitytree_opened_items.count(entity) != 0; + const NameComponent* name = scene.names.GetComponent(entity); + if (name == nullptr || name->name.find(filterInput.GetCurrentInputValue()) == std::string::npos) + { + return; + } + // Icons: if (scene.layers.Contains(entity)) { @@ -482,7 +504,6 @@ void OptionsWindow::PushToEntityTree(wi::ecs::Entity entity, int level) } } - const NameComponent* name = scene.names.GetComponent(entity); if (name == nullptr) { item.name += "[no_name] " + std::to_string(entity); diff --git a/Editor/OptionsWindow.h b/Editor/OptionsWindow.h index eb44977ba..5b38766e3 100644 --- a/Editor/OptionsWindow.h +++ b/Editor/OptionsWindow.h @@ -52,6 +52,7 @@ public: } filter = Filter::All; wi::gui::ComboBox newCombo; wi::gui::ComboBox filterCombo; + wi::gui::TextInputField filterInput; wi::gui::TreeList entityTree; wi::unordered_set entitytree_added_items; wi::unordered_set entitytree_opened_items; diff --git a/WickedEngine/wiBacklog.cpp b/WickedEngine/wiBacklog.cpp index 35debbf06..3f37aa27a 100644 --- a/WickedEngine/wiBacklog.cpp +++ b/WickedEngine/wiBacklog.cpp @@ -115,6 +115,7 @@ namespace wi::backlog { created = true; inputField.Create(""); + inputField.SetCancelInputEnabled(false); inputField.OnInputAccepted([](wi::gui::EventArgs args) { historyPos = 0; post(args.sValue); diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index 5b5f0efe9..a08bdfb1e 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -1280,6 +1280,14 @@ namespace wi::gui { return font.GetTextA(); } + const std::string TextInputField::GetCurrentInputValue() + { + if (state == ACTIVE) + { + return font_input.GetTextA(); + } + return ""; + } void TextInputField::Update(const wi::Canvas& canvas, float dt) { if (!IsVisible()) @@ -1452,7 +1460,13 @@ namespace wi::gui if (state == ACTIVE) { font_input.params = font.params; + + if (!cancel_input_enabled) + { + SetValue(font_input.GetTextA()); + } } + } void TextInputField::Render(const wi::Canvas& canvas, CommandList cmd) const { diff --git a/WickedEngine/wiGUI.h b/WickedEngine/wiGUI.h index 09e91fd1a..340f21fba 100644 --- a/WickedEngine/wiGUI.h +++ b/WickedEngine/wiGUI.h @@ -409,6 +409,7 @@ namespace wi::gui protected: std::function onInputAccepted; static wi::SpriteFont font_input; + bool cancel_input_enabled = true; public: void Create(const std::string& name); @@ -419,9 +420,14 @@ namespace wi::gui void SetValue(int newValue); void SetValue(float newValue); const std::string GetValue(); + const std::string GetCurrentInputValue(); void SetDescription(const std::string& desc) { font_description.SetText(desc); } const std::string GetDescription() const { return font_description.GetTextA(); } + // Set whether incomplete input will be removed on lost activation state (default: true) + void SetCancelInputEnabled(bool value) { cancel_input_enabled = value; } + bool IsCancelInputEnabled() const { return cancel_input_enabled; } + // There can only be ONE active text input field, so these methods modify the active one static void AddInput(const wchar_t inputChar); static void AddInput(const char inputChar); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 4e280409e..df7480781 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 139; + const int revision = 140; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);