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;