From 55abc9d63a8b9f5a6071964c330cbb8d0afe24a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A9meryc?= Date: Thu, 20 Jul 2023 22:13:10 -0400 Subject: [PATCH 01/11] NK-126 - Click Empty Component Script --- Editor/src/ComponentsPanel/ScriptPanel.h | 69 +++++++++++++++++++++++- Editor/src/Windows/FileSystemUI.cpp | 31 ----------- 2 files changed, 68 insertions(+), 32 deletions(-) diff --git a/Editor/src/ComponentsPanel/ScriptPanel.h b/Editor/src/ComponentsPanel/ScriptPanel.h index 2a51065d..53cda8e9 100644 --- a/Editor/src/ComponentsPanel/ScriptPanel.h +++ b/Editor/src/ComponentsPanel/ScriptPanel.h @@ -3,6 +3,38 @@ #include #include +const std::string TEMPLATE_SCRIPT_FIRST = R"(import "Nuake:Engine" for Engine +import "Nuake:ScriptableEntity" for ScriptableEntity +import "Nuake:Input" for Input +import "Nuake:Math" for Vector3, Math +import "Nuake:Scene" for Scene + +class )"; + +const std::string TEMPLATE_SCRIPT_SECOND = R"( is ScriptableEntity { + construct new() { + } + + // Called when the scene gets initialized + init() { + // Engine.Log("Hello World!") + } + + // Called every update + update(ts) { + } + + // Called 90 times per second + fixedUpdate(ts) { + } + + // Called on shutdown + exit() { + } +} +)"; + + class ScriptPanel : ComponentPanel { public: @@ -21,7 +53,7 @@ public: ImGui::TableNextColumn(); std::string path = component.Script; - ImGui::Button(component.Script.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); + ImGui::Button( path.empty() ? "Create New" : component.Script.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script")) @@ -45,6 +77,41 @@ public: { Nuake::OS::OpenIn(component.mWrenScript->GetFile()->GetAbsolutePath()); } + else + { + // TODO: Turn into command (Undo/Redo) + + std::string pathCreation = Nuake::FileDialog::SaveFile("*.wren"); + + if (!pathCreation.empty()) + { + if (!Nuake::String::EndsWith(pathCreation, ".wren")) + { + pathCreation += ".wren"; + } + + std::string fileName = Nuake::String::ToUpper(Nuake::FileSystem::GetFileNameFromPath(pathCreation)); + fileName = Nuake::String::RemoveWhiteSpace(fileName); + + if(!Nuake::String::IsDigit(fileName[0])) + { + Nuake::FileSystem::BeginWriteFile(pathCreation); + Nuake::FileSystem::WriteLine(TEMPLATE_SCRIPT_FIRST + fileName + TEMPLATE_SCRIPT_SECOND); + Nuake::FileSystem::EndWriteFile(); + + path = Nuake::FileSystem::AbsoluteToRelative(pathCreation); + Nuake::FileSystem::Scan(); + + component.LoadScript(path); + component.Script = path; + } + else + { + Nuake::Logger::Log("[FileSystem] Cannot create script files that starts with a number.", Nuake::CRITICAL); + } + } + + } } ImGui::TableNextColumn(); diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 1a07bf03..91901b93 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -9,37 +9,6 @@ #include "src/Rendering/Textures/TextureManager.h" #include "EditorInterface.h" -const std::string TEMPLATE_SCRIPT_FIRST = R"(import "Nuake:Engine" for Engine -import "Nuake:ScriptableEntity" for ScriptableEntity -import "Nuake:Input" for Input -import "Nuake:Math" for Vector3, Math -import "Nuake:Scene" for Scene - -class )"; - -const std::string TEMPLATE_SCRIPT_SECOND = R"( is ScriptableEntity { - construct new() { - } - - // Called when the scene gets initialized - init() { - // Engine.Log("Hello World!") - } - - // Called every update - update(ts) { - } - - // Called 90 times per second - fixedUpdate(ts) { - } - - // Called on shutdown - exit() { - } -} -)"; - #include namespace Nuake From 24f9d092c1074583d099beffba18700b6dfad833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89meryc?= Date: Fri, 21 Jul 2023 19:19:29 -0400 Subject: [PATCH 02/11] NK-126 - Fixed File Browser Refresh --- Editor/src/ComponentsPanel/ScriptPanel.cpp | 111 ++++++++++++++++++++ Editor/src/ComponentsPanel/ScriptPanel.h | 110 +------------------ Editor/src/Windows/EditorInterface.cpp | 2 +- Editor/src/Windows/EditorSelectionPanel.cpp | 2 + Editor/src/Windows/FileSystemUI.cpp | 1 + Editor/src/Windows/FileSystemUI.h | 2 +- 6 files changed, 118 insertions(+), 110 deletions(-) create mode 100644 Editor/src/ComponentsPanel/ScriptPanel.cpp diff --git a/Editor/src/ComponentsPanel/ScriptPanel.cpp b/Editor/src/ComponentsPanel/ScriptPanel.cpp new file mode 100644 index 00000000..3c27ae3e --- /dev/null +++ b/Editor/src/ComponentsPanel/ScriptPanel.cpp @@ -0,0 +1,111 @@ +#include "ScriptPanel.h" +#include "../Windows/FileSystemUI.h" +#include +#include + +void ScriptPanel::Draw(Nuake::Entity entity) +{ + if (!entity.HasComponent()) + return; + + Nuake::WrenScriptComponent& component = entity.GetComponent(); + BeginComponentTable(SCRIPT, Nuake::WrenScriptComponent); + { + { + ImGui::Text("Script"); + ImGui::TableNextColumn(); + + std::string path = component.Script; + ImGui::Button( path.empty() ? "Create New" : component.Script.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); + if (ImGui::BeginDragDropTarget()) + { + if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script")) + { + char* file = (char*)payload->Data; + + std::string fullPath = std::string(file, 512); + path = Nuake::FileSystem::AbsoluteToRelative(std::move(fullPath)); + + component.LoadScript(path); + } + ImGui::EndDragDropTarget(); + } + + component.Script = path; + + // Double click on file + if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) + { + if(!component.Script.empty()) + { + Nuake::OS::OpenIn(component.mWrenScript->GetFile()->GetAbsolutePath()); + } + else + { + // TODO: Turn into command (Undo/Redo) + + std::string pathCreation = Nuake::FileDialog::SaveFile("*.wren"); + + if (!pathCreation.empty()) + { + if (!Nuake::String::EndsWith(pathCreation, ".wren")) + { + pathCreation += ".wren"; + } + + std::string fileName = Nuake::String::ToUpper(Nuake::FileSystem::GetFileNameFromPath(pathCreation)); + fileName = Nuake::String::RemoveWhiteSpace(fileName); + + if(!Nuake::String::IsDigit(fileName[0])) + { + Nuake::FileSystem::BeginWriteFile(pathCreation); + Nuake::FileSystem::WriteLine(TEMPLATE_SCRIPT_FIRST + fileName + TEMPLATE_SCRIPT_SECOND); + Nuake::FileSystem::EndWriteFile(); + + path = Nuake::FileSystem::AbsoluteToRelative(pathCreation); + Nuake::FileSystem::Scan(); + Nuake::FileSystemUI::m_CurrentDirectory = Nuake::FileSystem::RootDirectory; + component.LoadScript(path); + component.Script = path; + } + else + { + Nuake::Logger::Log("[FileSystem] Cannot create script files that starts with a number.", Nuake::CRITICAL); + } + } + + } + } + + ImGui::TableNextColumn(); + + ComponentTableReset(component.Script, ""); + } + ImGui::TableNextColumn(); + { + ImGui::Text("Module"); + ImGui::TableNextColumn(); + + // Here we create a dropdown for every modules + auto& wrenScript = component.mWrenScript; + if (wrenScript) + { + auto modules = wrenScript->GetModules(); + + std::vector modulesC; + + for (auto& m : modules) + { + modulesC.push_back(m.c_str()); + } + static int currentModule = (int)component.mModule; + ImGui::Combo("##WrenModule", ¤tModule, &modulesC[0], modules.size()); + component.mModule = currentModule; + } + + ImGui::TableNextColumn(); + //ComponentTableReset(component.Class, ""); + } + } + EndComponentTable(); +} \ No newline at end of file diff --git a/Editor/src/ComponentsPanel/ScriptPanel.h b/Editor/src/ComponentsPanel/ScriptPanel.h index 53cda8e9..dac4c0c2 100644 --- a/Editor/src/ComponentsPanel/ScriptPanel.h +++ b/Editor/src/ComponentsPanel/ScriptPanel.h @@ -1,7 +1,6 @@ #pragma once #include "ComponentPanel.h" -#include -#include + const std::string TEMPLATE_SCRIPT_FIRST = R"(import "Nuake:Engine" for Engine import "Nuake:ScriptableEntity" for ScriptableEntity @@ -40,110 +39,5 @@ class ScriptPanel : ComponentPanel { public: ScriptPanel() {} - void Draw(Nuake::Entity entity) override - { - if (!entity.HasComponent()) - return; - - Nuake::WrenScriptComponent& component = entity.GetComponent(); - BeginComponentTable(SCRIPT, Nuake::WrenScriptComponent); - { - { - ImGui::Text("Script"); - ImGui::TableNextColumn(); - - std::string path = component.Script; - ImGui::Button( path.empty() ? "Create New" : component.Script.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script")) - { - char* file = (char*)payload->Data; - - std::string fullPath = std::string(file, 512); - path = Nuake::FileSystem::AbsoluteToRelative(std::move(fullPath)); - - component.LoadScript(path); - } - ImGui::EndDragDropTarget(); - } - - component.Script = path; - - // Double click on file - if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) - { - if(!component.Script.empty()) - { - Nuake::OS::OpenIn(component.mWrenScript->GetFile()->GetAbsolutePath()); - } - else - { - // TODO: Turn into command (Undo/Redo) - - std::string pathCreation = Nuake::FileDialog::SaveFile("*.wren"); - - if (!pathCreation.empty()) - { - if (!Nuake::String::EndsWith(pathCreation, ".wren")) - { - pathCreation += ".wren"; - } - - std::string fileName = Nuake::String::ToUpper(Nuake::FileSystem::GetFileNameFromPath(pathCreation)); - fileName = Nuake::String::RemoveWhiteSpace(fileName); - - if(!Nuake::String::IsDigit(fileName[0])) - { - Nuake::FileSystem::BeginWriteFile(pathCreation); - Nuake::FileSystem::WriteLine(TEMPLATE_SCRIPT_FIRST + fileName + TEMPLATE_SCRIPT_SECOND); - Nuake::FileSystem::EndWriteFile(); - - path = Nuake::FileSystem::AbsoluteToRelative(pathCreation); - Nuake::FileSystem::Scan(); - - component.LoadScript(path); - component.Script = path; - } - else - { - Nuake::Logger::Log("[FileSystem] Cannot create script files that starts with a number.", Nuake::CRITICAL); - } - } - - } - } - - ImGui::TableNextColumn(); - - ComponentTableReset(component.Script, ""); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Module"); - ImGui::TableNextColumn(); - - // Here we create a dropdown for every modules - auto& wrenScript = component.mWrenScript; - if (wrenScript) - { - auto modules = wrenScript->GetModules(); - - std::vector modulesC; - - for (auto& m : modules) - { - modulesC.push_back(m.c_str()); - } - static int currentModule = (int)component.mModule; - ImGui::Combo("##WrenModule", ¤tModule, &modulesC[0], modules.size()); - component.mModule = currentModule; - } - - ImGui::TableNextColumn(); - //ComponentTableReset(component.Class, ""); - } - } - EndComponentTable(); - } + void Draw(Nuake::Entity entity) override; }; \ No newline at end of file diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 81af2da4..7c993e65 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -50,7 +50,7 @@ namespace Nuake { ImFont* normalFont; ImFont* boldFont; ImFont* EditorInterface::bigIconFont; - + EditorInterface::EditorInterface() { filesystem = new FileSystemUI(this); diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index 639a8948..82699732 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -8,6 +8,8 @@ #include #include +#include "src/Scene/Components/WrenScriptComponent.h" + EditorSelectionPanel::EditorSelectionPanel() { mTransformPanel = TransformPanel(); diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 91901b93..b6847006 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -13,6 +13,7 @@ namespace Nuake { + Ref FileSystemUI::m_CurrentDirectory; // TODO: add filetree in same panel void FileSystemUI::Draw() diff --git a/Editor/src/Windows/FileSystemUI.h b/Editor/src/Windows/FileSystemUI.h index 2ab62141..edad2cee 100644 --- a/Editor/src/Windows/FileSystemUI.h +++ b/Editor/src/Windows/FileSystemUI.h @@ -10,7 +10,7 @@ namespace Nuake { EditorInterface* Editor; public: - Ref m_CurrentDirectory; + static Ref m_CurrentDirectory; bool m_hasClickedOnFile; FileSystemUI(EditorInterface* editor) From 8c5ce77449a5a64aaba7764a43e6262ae0d76d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89meryc?= Date: Fri, 21 Jul 2023 19:23:03 -0400 Subject: [PATCH 03/11] NK-126 - Added Overwrite Prompt --- Nuake/src/Core/FileSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index 3c5e9661..8b943af5 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -45,7 +45,7 @@ namespace Nuake ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = filter; ofn.nFilterIndex = 1; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT; if (GetSaveFileNameA(&ofn) == TRUE) { return ofn.lpstrFile; From 8a931c768bf9ddda07179f454b952e3aea8a9106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89meryc?= Date: Fri, 21 Jul 2023 19:29:50 -0400 Subject: [PATCH 04/11] NK-126 - Fix Indent --- Editor/src/ComponentsPanel/ScriptPanel.cpp | 166 ++++++++++----------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/Editor/src/ComponentsPanel/ScriptPanel.cpp b/Editor/src/ComponentsPanel/ScriptPanel.cpp index 3c27ae3e..b9e7b512 100644 --- a/Editor/src/ComponentsPanel/ScriptPanel.cpp +++ b/Editor/src/ComponentsPanel/ScriptPanel.cpp @@ -6,106 +6,106 @@ void ScriptPanel::Draw(Nuake::Entity entity) { if (!entity.HasComponent()) - return; + return; - Nuake::WrenScriptComponent& component = entity.GetComponent(); - BeginComponentTable(SCRIPT, Nuake::WrenScriptComponent); + Nuake::WrenScriptComponent& component = entity.GetComponent(); + BeginComponentTable(SCRIPT, Nuake::WrenScriptComponent); + { { + ImGui::Text("Script"); + ImGui::TableNextColumn(); + + std::string path = component.Script; + ImGui::Button( path.empty() ? "Create New" : component.Script.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); + if (ImGui::BeginDragDropTarget()) { - ImGui::Text("Script"); - ImGui::TableNextColumn(); - - std::string path = component.Script; - ImGui::Button( path.empty() ? "Create New" : component.Script.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0)); - if (ImGui::BeginDragDropTarget()) + if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script")) { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script")) - { - char* file = (char*)payload->Data; + char* file = (char*)payload->Data; - std::string fullPath = std::string(file, 512); - path = Nuake::FileSystem::AbsoluteToRelative(std::move(fullPath)); + std::string fullPath = std::string(file, 512); + path = Nuake::FileSystem::AbsoluteToRelative(std::move(fullPath)); - component.LoadScript(path); - } - ImGui::EndDragDropTarget(); + component.LoadScript(path); } + ImGui::EndDragDropTarget(); + } - component.Script = path; + component.Script = path; - // Double click on file - if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) + // Double click on file + if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) + { + if(!component.Script.empty()) { - if(!component.Script.empty()) + Nuake::OS::OpenIn(component.mWrenScript->GetFile()->GetAbsolutePath()); + } + else + { + // TODO: Turn into command (Undo/Redo) + + std::string pathCreation = Nuake::FileDialog::SaveFile("*.wren"); + + if (!pathCreation.empty()) { - Nuake::OS::OpenIn(component.mWrenScript->GetFile()->GetAbsolutePath()); - } - else - { - // TODO: Turn into command (Undo/Redo) - - std::string pathCreation = Nuake::FileDialog::SaveFile("*.wren"); - - if (!pathCreation.empty()) + if (!Nuake::String::EndsWith(pathCreation, ".wren")) { - if (!Nuake::String::EndsWith(pathCreation, ".wren")) - { - pathCreation += ".wren"; - } - - std::string fileName = Nuake::String::ToUpper(Nuake::FileSystem::GetFileNameFromPath(pathCreation)); - fileName = Nuake::String::RemoveWhiteSpace(fileName); - - if(!Nuake::String::IsDigit(fileName[0])) - { - Nuake::FileSystem::BeginWriteFile(pathCreation); - Nuake::FileSystem::WriteLine(TEMPLATE_SCRIPT_FIRST + fileName + TEMPLATE_SCRIPT_SECOND); - Nuake::FileSystem::EndWriteFile(); - - path = Nuake::FileSystem::AbsoluteToRelative(pathCreation); - Nuake::FileSystem::Scan(); - Nuake::FileSystemUI::m_CurrentDirectory = Nuake::FileSystem::RootDirectory; - component.LoadScript(path); - component.Script = path; - } - else - { - Nuake::Logger::Log("[FileSystem] Cannot create script files that starts with a number.", Nuake::CRITICAL); - } + pathCreation += ".wren"; } - } - } - - ImGui::TableNextColumn(); + std::string fileName = Nuake::String::ToUpper(Nuake::FileSystem::GetFileNameFromPath(pathCreation)); + fileName = Nuake::String::RemoveWhiteSpace(fileName); + + if(!Nuake::String::IsDigit(fileName[0])) + { + Nuake::FileSystem::BeginWriteFile(pathCreation); + Nuake::FileSystem::WriteLine(TEMPLATE_SCRIPT_FIRST + fileName + TEMPLATE_SCRIPT_SECOND); + Nuake::FileSystem::EndWriteFile(); - ComponentTableReset(component.Script, ""); + path = Nuake::FileSystem::AbsoluteToRelative(pathCreation); + Nuake::FileSystem::Scan(); + Nuake::FileSystemUI::m_CurrentDirectory = Nuake::FileSystem::RootDirectory; + component.LoadScript(path); + component.Script = path; + } + else + { + Nuake::Logger::Log("[FileSystem] Cannot create script files that starts with a number.", Nuake::CRITICAL); + } + } + + } } + ImGui::TableNextColumn(); - { - ImGui::Text("Module"); - ImGui::TableNextColumn(); - // Here we create a dropdown for every modules - auto& wrenScript = component.mWrenScript; - if (wrenScript) - { - auto modules = wrenScript->GetModules(); - - std::vector modulesC; - - for (auto& m : modules) - { - modulesC.push_back(m.c_str()); - } - static int currentModule = (int)component.mModule; - ImGui::Combo("##WrenModule", ¤tModule, &modulesC[0], modules.size()); - component.mModule = currentModule; - } - - ImGui::TableNextColumn(); - //ComponentTableReset(component.Class, ""); - } + ComponentTableReset(component.Script, ""); } - EndComponentTable(); + ImGui::TableNextColumn(); + { + ImGui::Text("Module"); + ImGui::TableNextColumn(); + + // Here we create a dropdown for every modules + auto& wrenScript = component.mWrenScript; + if (wrenScript) + { + auto modules = wrenScript->GetModules(); + + std::vector modulesC; + + for (auto& m : modules) + { + modulesC.push_back(m.c_str()); + } + static int currentModule = (int)component.mModule; + ImGui::Combo("##WrenModule", ¤tModule, &modulesC[0], modules.size()); + component.mModule = currentModule; + } + + ImGui::TableNextColumn(); + //ComponentTableReset(component.Class, ""); + } + } + EndComponentTable(); } \ No newline at end of file From 04d6241b63f72af7d196e0e14d72b0450f70a3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89meryc?= Date: Fri, 21 Jul 2023 21:03:35 -0400 Subject: [PATCH 05/11] NK-102 - Generic Confirmation Popup --- Editor/src/Misc/PopupHelper.cpp | 32 ++++++++++++++++++++++++++++++++ Editor/src/Misc/PopupHelper.h | 9 +++++++++ 2 files changed, 41 insertions(+) create mode 100644 Editor/src/Misc/PopupHelper.cpp create mode 100644 Editor/src/Misc/PopupHelper.h diff --git a/Editor/src/Misc/PopupHelper.cpp b/Editor/src/Misc/PopupHelper.cpp new file mode 100644 index 00000000..f1a28fd1 --- /dev/null +++ b/Editor/src/Misc/PopupHelper.cpp @@ -0,0 +1,32 @@ +#include "PopupHelper.h" +#include "imgui/imgui.h" + + +void PopupHelper::Confirmation(const std::string& id) +{ + ImGui::TextWrapped("Test"); + + ImGui::OpenPopup(id.c_str()); +} + +bool PopupHelper::DefineDialog(std::string id, std::string text) +{ + bool result = false; + + ImVec2 center = ImGui::GetMainViewport()->GetCenter(); + ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); + + if (ImGui::BeginPopupModal(id.c_str(), NULL, ImGuiWindowFlags_AlwaysAutoResize)) + { + ImGui::Text((text + "\n\n").c_str()); + ImGui::Separator(); + + if (ImGui::Button("OK", ImVec2(120, 0))) { result = true; ImGui::CloseCurrentPopup(); } + ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); + if (ImGui::Button("Cancel", ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); } + ImGui::EndPopup(); + } + + return result; +} diff --git a/Editor/src/Misc/PopupHelper.h b/Editor/src/Misc/PopupHelper.h new file mode 100644 index 00000000..a4550c61 --- /dev/null +++ b/Editor/src/Misc/PopupHelper.h @@ -0,0 +1,9 @@ +#pragma once +#include + +class PopupHelper +{ +public: + static void Confirmation(const std::string& id); + static bool DefineDialog(std::string id, std::string text); +}; From 5ef8cb80615321996928c83df4fd3c3a18d34bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89meryc?= Date: Fri, 21 Jul 2023 21:04:04 -0400 Subject: [PATCH 06/11] NK-102 - I forgor --- Editor/src/Misc/PopupHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Editor/src/Misc/PopupHelper.cpp b/Editor/src/Misc/PopupHelper.cpp index f1a28fd1..49f81a3e 100644 --- a/Editor/src/Misc/PopupHelper.cpp +++ b/Editor/src/Misc/PopupHelper.cpp @@ -4,7 +4,7 @@ void PopupHelper::Confirmation(const std::string& id) { - ImGui::TextWrapped("Test"); + ImGui::TextWrapped(id.c_str()); ImGui::OpenPopup(id.c_str()); } From 63b5958a640cc924d02dbeb6bb3dc8d021e92f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89meryc?= Date: Fri, 21 Jul 2023 21:07:11 -0400 Subject: [PATCH 07/11] NK-102 - PR Comments --- Editor/src/Misc/PopupHelper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Editor/src/Misc/PopupHelper.h b/Editor/src/Misc/PopupHelper.h index a4550c61..e8613bae 100644 --- a/Editor/src/Misc/PopupHelper.h +++ b/Editor/src/Misc/PopupHelper.h @@ -5,5 +5,5 @@ class PopupHelper { public: static void Confirmation(const std::string& id); - static bool DefineDialog(std::string id, std::string text); + static bool DefineDialog(std::string& id, std::string& text); }; From 4c0d1ffc43eaa2d032f96fd6bf6c648e48562df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89meryc?= Date: Fri, 21 Jul 2023 21:08:02 -0400 Subject: [PATCH 08/11] NK-102 - ... --- Editor/src/Misc/PopupHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Editor/src/Misc/PopupHelper.cpp b/Editor/src/Misc/PopupHelper.cpp index 49f81a3e..e117054d 100644 --- a/Editor/src/Misc/PopupHelper.cpp +++ b/Editor/src/Misc/PopupHelper.cpp @@ -9,7 +9,7 @@ void PopupHelper::Confirmation(const std::string& id) ImGui::OpenPopup(id.c_str()); } -bool PopupHelper::DefineDialog(std::string id, std::string text) +bool PopupHelper::DefineDialog(std::string& id, std::string& text) { bool result = false; From f95f4ad8cbf8a3bd6271ddc6d99e1bd7da40b1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89meryc?= Date: Fri, 21 Jul 2023 21:11:52 -0400 Subject: [PATCH 09/11] NK-102 - Added 'const' --- Editor/src/Misc/PopupHelper.cpp | 2 +- Editor/src/Misc/PopupHelper.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/src/Misc/PopupHelper.cpp b/Editor/src/Misc/PopupHelper.cpp index e117054d..6159234a 100644 --- a/Editor/src/Misc/PopupHelper.cpp +++ b/Editor/src/Misc/PopupHelper.cpp @@ -9,7 +9,7 @@ void PopupHelper::Confirmation(const std::string& id) ImGui::OpenPopup(id.c_str()); } -bool PopupHelper::DefineDialog(std::string& id, std::string& text) +bool PopupHelper::DefineDialog(const std::string& id, const std::string& text) { bool result = false; diff --git a/Editor/src/Misc/PopupHelper.h b/Editor/src/Misc/PopupHelper.h index e8613bae..74304103 100644 --- a/Editor/src/Misc/PopupHelper.h +++ b/Editor/src/Misc/PopupHelper.h @@ -5,5 +5,5 @@ class PopupHelper { public: static void Confirmation(const std::string& id); - static bool DefineDialog(std::string& id, std::string& text); + static bool DefineDialog(const std::string& id, const std::string& text); }; From bf0aa78d4de2991aa6486ed706e163d6f67b9a8a Mon Sep 17 00:00:00 2001 From: emerycp Date: Fri, 21 Jul 2023 22:04:58 -0400 Subject: [PATCH 10/11] NK-74 - Double click to open scene --- Editor/src/Windows/FileSystemUI.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 934f94c7..2056ed0b 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -10,6 +10,7 @@ #include "EditorInterface.h" #include +#include "../Misc/PopupHelper.h" namespace Nuake { @@ -178,6 +179,30 @@ namespace Nuake ImGui::EndPopup(); } + std::string openScene = "Open Scene" + std::string("##") + hoverMenuId; + + if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) + { + if (file->GetExtension() == ".scene") + { + PopupHelper::Confirmation(openScene); + } + } + + if (PopupHelper::DefineDialog(openScene, "Open the scene? \n Changes will not be saved.")) + { + Ref scene = Scene::New(); + std::string projectPath = file->GetAbsolutePath(); + if (!scene->Deserialize(FileSystem::ReadFile(projectPath, true))) + { + Logger::Log("Error failed loading scene: " + projectPath, CRITICAL); + return; + } + + scene->Path = FileSystem::AbsoluteToRelative(projectPath); + Engine::LoadScene(scene); + } + ImGui::Text(file->GetName().c_str()); ImGui::PopFont(); } From 01db1970a8ea71fb67676896e0b8b53eb5a96647 Mon Sep 17 00:00:00 2001 From: emerycp Date: Fri, 21 Jul 2023 22:15:31 -0400 Subject: [PATCH 11/11] NK-74 - PR Comments --- Editor/src/Windows/FileSystemUI.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 2056ed0b..55d690ef 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -179,7 +179,7 @@ namespace Nuake ImGui::EndPopup(); } - std::string openScene = "Open Scene" + std::string("##") + hoverMenuId; + const std::string openScene = "Open Scene" + std::string("##") + hoverMenuId; if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) { @@ -192,7 +192,7 @@ namespace Nuake if (PopupHelper::DefineDialog(openScene, "Open the scene? \n Changes will not be saved.")) { Ref scene = Scene::New(); - std::string projectPath = file->GetAbsolutePath(); + const std::string projectPath = file->GetAbsolutePath(); if (!scene->Deserialize(FileSystem::ReadFile(projectPath, true))) { Logger::Log("Error failed loading scene: " + projectPath, CRITICAL);