From 27488ae5bf9858bcef679e75becb4d55af0a055c Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Fri, 16 Aug 2024 17:59:06 -0400 Subject: [PATCH] Can now rename entities pressing f2 or double clicking and selecting an entity should unfold the tree --- Editor/src/Windows/EditorInterface.cpp | 49 ++++++++++++++++++++-- Editor/src/Windows/EditorInterface.h | 5 +++ Nuake/src/Scene/Scene.cpp | 25 +++++++++++ Nuake/src/Scene/Scene.h | 2 + Nuake/src/Scripting/ScriptingEngineNet.cpp | 1 + Nuake/src/Scripting/ScriptingEngineNet.h | 11 ++++- 6 files changed, 89 insertions(+), 4 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 24ba3425..8299aff9 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -51,7 +51,6 @@ #include #include "src/Core/FileSystem.h" #include -#include #include #include "../Commands/Commands/Commands.h" #include @@ -345,6 +344,7 @@ namespace Nuake { if (ent.IsValid()) { Selection = EditorSelection(ent); + foundSomethingToSelect = true; } } else @@ -354,6 +354,11 @@ namespace Nuake { gbuffer.Unbind(); } + + if (foundSomethingToSelect = true) + { + m_ShouldUnfoldEntityTree = true; + } } } else @@ -701,15 +706,40 @@ namespace Nuake { { ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255)); } - + + if (!m_IsRenaming && m_ShouldUnfoldEntityTree && Selection.Type == EditorSelectionType::Entity && e.GetScene()->EntityIsParent(Selection.Entity, e)) + { + ImGui::SetNextItemOpen(true); + } + + auto cursorPos = ImGui::GetCursorPos(); + + ImGui::SetNextItemAllowOverlap(); + bool open = ImGui::TreeNodeEx(name.c_str(), base_flags); + if (m_IsRenaming) + { + if (Selection.Type == EditorSelectionType::Entity && Selection.Entity == e) + { + ImGui::SetCursorPosY(cursorPos.y); + ImGui::Indent(); + ImGui::InputText("##renamingEntity", &name); + ImGui::Unindent(); + if (Input::IsKeyDown(Key::ENTER)) + { + nameComponent.Name = name; + m_IsRenaming = false; + } + } + } + bool isDragging = false; if (nameComponent.IsPrefab && e.HasComponent()) { ImGui::PopStyleColor(); } - else if (ImGui::BeginDragDropSource()) + else if (!m_IsRenaming && ImGui::BeginDragDropSource()) { ImGui::SetDragDropPayload("ENTITY", (void*)&e, sizeof(Entity)); ImGui::Text(name.c_str()); @@ -742,7 +772,20 @@ namespace Nuake { } if (!isDragging && ImGui::IsItemHovered() && ImGui::IsMouseReleased(0)) + { + // We selected another another that we werent renaming + if (Selection.Entity != e) + { + m_IsRenaming = false; + } + Selection = EditorSelection(e); + } + + if (!isDragging && (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) || Input::IsKeyPressed(Key::F2)) + { + m_IsRenaming = true; + } if (ImGui::BeginPopupContextItem()) { diff --git a/Editor/src/Windows/EditorInterface.h b/Editor/src/Windows/EditorInterface.h index 07e81cd0..6762ffef 100644 --- a/Editor/src/Windows/EditorInterface.h +++ b/Editor/src/Windows/EditorInterface.h @@ -15,6 +15,8 @@ #include "../Commands/ICommand.h" #include "MapImporterWindow.h" +#include + using namespace NuakeEditor; namespace Nuake @@ -25,6 +27,7 @@ namespace Nuake class EditorInterface { private: + std::vector errors; Ref SceneSnapshot; NuakeEditor::CommandBuffer* mCommandBuffer; @@ -36,6 +39,8 @@ namespace Nuake bool m_ShowOverlay = true; bool m_IsHoveringViewport = false; bool m_IsViewportFocused = false; + bool m_IsRenaming = false; + bool m_ShouldUnfoldEntityTree = false; bool m_ShowTrenchbroomConfigurator = false; bool m_ShowMapImporter = false; diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 61727352..7639bcdc 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -213,6 +213,31 @@ namespace Nuake return currentEntity; } + bool Scene::EntityIsParent(Entity entity, Entity parent) + { + if (!entity.IsValid()) + return false; + + if (entity.GetComponent().HasParent && entity.GetComponent().Parent == parent) + { + return true; + } + + Entity current = entity; + while (current.GetComponent().HasParent && current != parent) + { + current = current.GetComponent().Parent; + + if (current == parent) + { + return true; + } + } + + + return false; + } + bool Scene::OnInit() { for (auto& system : m_Systems) diff --git a/Nuake/src/Scene/Scene.h b/Nuake/src/Scene/Scene.h index 5955f27e..aad130a2 100644 --- a/Nuake/src/Scene/Scene.h +++ b/Nuake/src/Scene/Scene.h @@ -74,6 +74,8 @@ namespace Nuake Entity GetEntityFromPath(const std::string& path); Entity GetRelativeEntityFromPath(Entity entity, const std::string& path); + bool EntityIsParent(Entity entity, Entity parent); + template static void CopyComponent(entt::registry& dst, entt::registry& src); diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index f46e46cf..f0fbaafd 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -16,6 +16,7 @@ #include #include #include +#include void ExceptionCallback(std::string_view InMessage) diff --git a/Nuake/src/Scripting/ScriptingEngineNet.h b/Nuake/src/Scripting/ScriptingEngineNet.h index e5f6241e..50cd29a9 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.h +++ b/Nuake/src/Scripting/ScriptingEngineNet.h @@ -44,6 +44,13 @@ namespace Nuake { std::vector exposedVars; }; + struct CompilationError + { + std::string file; + int line; + std::string message; + }; + class ScriptingEngineNet { private: @@ -75,6 +82,8 @@ namespace Nuake { ScriptingEngineNet(); ~ScriptingEngineNet(); + std::vector ExtractErrors(const std::string& input); + public: static ScriptingEngineNet& Get(); @@ -85,7 +94,7 @@ namespace Nuake { std::vector GetExposedVarForTypes(Entity entity); - void BuildProjectAssembly(Ref project); + std::vector BuildProjectAssembly(Ref project); void LoadProjectAssembly(Ref project); void RegisterEntityScript(Entity& entity);