From 84b2b63ba95bc0d3b5cb2d68f5e542a38fc15282 Mon Sep 17 00:00:00 2001 From: antopilo Date: Thu, 21 Nov 2024 22:14:14 -0500 Subject: [PATCH] Added shortcut to open resource in component widgets --- Editor/src/Windows/EditorInterface.cpp | 5 ++-- Editor/src/Windows/EditorInterface.h | 2 +- Editor/src/Windows/EditorSelectionPanel.cpp | 28 ++++++++++++++++++- Editor/src/Windows/EditorSelectionPanel.h | 3 +- .../PrefabEditor/PrefabEditorWindow.cpp | 2 +- .../Windows/PrefabEditor/PrefabEditorWindow.h | 2 +- Nuake/src/Rendering/Shaders/Shader.cpp | 22 +++++++-------- 7 files changed, 45 insertions(+), 19 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index a36b55fc..756b80dc 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -123,7 +123,8 @@ namespace Nuake { _NewProjectWindow = new NewProjectWindow(this); _audioWindow = new AudioWindow(); m_ProjectSettingsWindow = new ProjectSettingsWindow(); - + SelectionPanel = new EditorSelectionPanel(this->Selection); + Logger::Log("Building fonts", "window", VERBOSE); BuildFonts(); @@ -2623,7 +2624,7 @@ namespace Nuake { //pInterface.DrawEntitySettings(); DrawViewport(); DrawSceneTree(); - SelectionPanel.Draw(Selection); + SelectionPanel->Draw(Selection); DrawLogger(); filesystem->Draw(); filesystem->DrawDirectoryExplorer(); diff --git a/Editor/src/Windows/EditorInterface.h b/Editor/src/Windows/EditorInterface.h index 14dedff6..4b4a7f18 100644 --- a/Editor/src/Windows/EditorInterface.h +++ b/Editor/src/Windows/EditorInterface.h @@ -76,7 +76,7 @@ namespace Nuake FileSystemUI* filesystem; bool isNewProject = false; static EditorSelection Selection; - EditorSelectionPanel SelectionPanel; + EditorSelectionPanel* SelectionPanel; TrenchbroomConfiguratorWindow m_TrenchhbroomConfigurator; MapImporterWindow m_MapImporter; diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index 57ce25f6..4e33df77 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -1,6 +1,7 @@ #define IMGUI_DEFINE_MATH_OPERATORS #include "EditorSelectionPanel.h" +#include "EditorInterface.h" #include "../Misc/ImGuiTextHelper.h" #include #include "src/Scene/Components/FieldTypes.h" @@ -25,8 +26,10 @@ using namespace Nuake; -EditorSelectionPanel::EditorSelectionPanel() +EditorSelectionPanel::EditorSelectionPanel(EditorSelection& inSelection) { + selection = &inSelection; + virtualScene = CreateRef(); virtualScene->SetName("Virtual Scene"); virtualScene->CreateEntity("Camera").AddComponent(); @@ -2075,6 +2078,8 @@ void EditorSelectionPanel::DrawFieldTypeResourceFile(entt::meta_data& field, ent auto fieldValPtr = fieldVal.try_cast(); if (fieldValPtr != nullptr) { + ImGui::SetNextItemAllowOverlap(); + auto fieldValProxy = *fieldValPtr; std::string filePath = fieldValProxy.file == nullptr ? "" : fieldValProxy.file->GetRelativePath(); std::string controlName = filePath + std::string("##") + displayName; @@ -2092,6 +2097,27 @@ void EditorSelectionPanel::DrawFieldTypeResourceFile(entt::meta_data& field, ent } ImGui::EndDragDropTarget(); } + + ImGui::SameLine(); + + bool showShortcutBtn = !filePath.empty(); + const int shortcutBtnWidth = 30; + ImGui::SetCursorPosX(ImGui::GetCursorPosX() - shortcutBtnWidth - ImGui::GetStyle().ItemSpacing.x); + if(ImGui::Button(">", ImVec2(shortcutBtnWidth, 0))) + { + if (FileSystem::FileExists(filePath)) + { + Ref file = FileSystem::GetFile(filePath); + if (file->GetFileType() == FileType::Map) + { + OS::OpenTrenchbroomMap(file->GetAbsolutePath()); + } + else + { + *selection = EditorSelection(FileSystem::GetFile(filePath)); + } + } + } } else { diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index 43e79296..5a097f86 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -33,13 +33,14 @@ class EditorSelectionPanel private: TransformPanel mTransformPanel; MeshPanel meshPanel; + EditorSelection* selection = nullptr; Ref currentFile; Ref selectedResource; Ref virtualScene; public: - EditorSelectionPanel(); + EditorSelectionPanel(EditorSelection& selection); void Draw(EditorSelection selection, const std::string& id = ""); diff --git a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp index b013d488..8e7870ac 100644 --- a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp +++ b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp @@ -305,7 +305,7 @@ void PrefabEditorWindow::Draw() } ImGui::End(); - SelectionPanel.Draw(Selection, prefab->Path); + SelectionPanel->Draw(Selection, prefab->Path); DrawViewportWindow(); } diff --git a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.h b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.h index b08d7458..0340ae14 100644 --- a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.h +++ b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.h @@ -36,7 +36,7 @@ private: bool isRenaming; bool isInitialized = false; - EditorSelectionPanel SelectionPanel; + EditorSelectionPanel* SelectionPanel; EditorSelection Selection; Nuake::Entity QueueDeletion; ImGuizmo::OPERATION CurrentOperation = ImGuizmo::TRANSLATE; diff --git a/Nuake/src/Rendering/Shaders/Shader.cpp b/Nuake/src/Rendering/Shaders/Shader.cpp index dc13c722..2133414a 100644 --- a/Nuake/src/Rendering/Shaders/Shader.cpp +++ b/Nuake/src/Rendering/Shaders/Shader.cpp @@ -237,36 +237,34 @@ namespace Nuake { for (auto& u : uniforms) { - std::string name = u.name; - auto type = u.type; - switch (type) + switch (u.type) { case UniformTypes::Float: - SetUniform(name, u.value.valueFloat); + SetUniform(u.name, u.value.valueFloat); break; case UniformTypes::Int: - SetUniform(name, u.value.valueInt); + SetUniform(u.name, u.value.valueInt); break; case UniformTypes::Uint: - SetUniformUint(name, u.value.valueUInt); + SetUniformUint(u.name, u.value.valueUInt); break; case UniformTypes::Vec2: - SetUniform(name, u.value.valueVec2); + SetUniform(u.name, u.value.valueVec2); break; case UniformTypes::Vec3: - SetUniform(name, u.value.valueVec3); + SetUniform(u.name, u.value.valueVec3); break; case UniformTypes::Vec4: - SetUniform(name, u.value.valueVec4); + SetUniform(u.name, u.value.valueVec4); break; case UniformTypes::Mat3: - SetUniform(name, u.value.valueMat3); + SetUniform(u.name, u.value.valueMat3); break; case UniformTypes::Mat4: - SetUniform(name, u.value.valueMat4); + SetUniform(u.name, u.value.valueMat4); break; case UniformTypes::Sampler2D: - SetUniform(name, u.value.valueInt); + SetUniform(u.name, u.value.valueInt); break; } }