Can now rename entities pressing f2 or double clicking and selecting an entity should unfold the tree

This commit is contained in:
Antoine Pilote
2024-08-16 17:59:06 -04:00
parent 9c2a6f9019
commit 27488ae5bf
6 changed files with 89 additions and 4 deletions

View File

@@ -51,7 +51,6 @@
#include <src/UI/ImUI.h>
#include "src/Core/FileSystem.h"
#include <src/Resource/StaticResources.h>
#include <src/Scripting/ScriptingEngineNet.h>
#include <src/Threading/JobSystem.h>
#include "../Commands/Commands/Commands.h"
#include <src/Resource/ModelLoader.h>
@@ -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<PrefabComponent>())
{
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())
{

View File

@@ -15,6 +15,8 @@
#include "../Commands/ICommand.h"
#include "MapImporterWindow.h"
#include <src/Scripting/ScriptingEngineNet.h>
using namespace NuakeEditor;
namespace Nuake
@@ -25,6 +27,7 @@ namespace Nuake
class EditorInterface
{
private:
std::vector<CompilationError> errors;
Ref<Scene> 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;

View File

@@ -213,6 +213,31 @@ namespace Nuake
return currentEntity;
}
bool Scene::EntityIsParent(Entity entity, Entity parent)
{
if (!entity.IsValid())
return false;
if (entity.GetComponent<ParentComponent>().HasParent && entity.GetComponent<ParentComponent>().Parent == parent)
{
return true;
}
Entity current = entity;
while (current.GetComponent<ParentComponent>().HasParent && current != parent)
{
current = current.GetComponent<ParentComponent>().Parent;
if (current == parent)
{
return true;
}
}
return false;
}
bool Scene::OnInit()
{
for (auto& system : m_Systems)

View File

@@ -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<typename Component>
static void CopyComponent(entt::registry& dst, entt::registry& src);

View File

@@ -16,6 +16,7 @@
#include <Coral/Array.hpp>
#include <Coral/Attribute.hpp>
#include <random>
#include <regex>
void ExceptionCallback(std::string_view InMessage)

View File

@@ -44,6 +44,13 @@ namespace Nuake {
std::vector<ExposedVar> exposedVars;
};
struct CompilationError
{
std::string file;
int line;
std::string message;
};
class ScriptingEngineNet
{
private:
@@ -75,6 +82,8 @@ namespace Nuake {
ScriptingEngineNet();
~ScriptingEngineNet();
std::vector<CompilationError> ExtractErrors(const std::string& input);
public:
static ScriptingEngineNet& Get();
@@ -85,7 +94,7 @@ namespace Nuake {
std::vector<ExposedVar> GetExposedVarForTypes(Entity entity);
void BuildProjectAssembly(Ref<Project> project);
std::vector<CompilationError> BuildProjectAssembly(Ref<Project> project);
void LoadProjectAssembly(Ref<Project> project);
void RegisterEntityScript(Entity& entity);