From b89be05cebf8ee0052c8194c5121a7ae2e33bf18 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sat, 4 Feb 2023 01:20:01 +0800 Subject: [PATCH 1/3] Shortcuts in hierarchy panel cannot be pressed when any widget is focused --- .../HierarchyPanel/SHHierarchyPanel.cpp | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp index a7e85ad4..7aeed173 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp @@ -96,30 +96,32 @@ namespace SHADE } ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal); - if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_A)) + if (!ImGui::IsAnyItemFocused()) { - SelectAllEntities(); - } - if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_C)) - { - CopySelectedEntities(); - } - if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && !ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V)) - { - PasteEntities(); - } - if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V)) - { - if (editor->selectedEntities.size() == 1) + if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_A)) { - PasteEntities(editor->selectedEntities.back()); + SelectAllEntities(); + } + if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_C)) + { + CopySelectedEntities(); + } + if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && !ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V)) + { + PasteEntities(); + } + if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyReleased(ImGuiKey_V)) + { + if (editor->selectedEntities.size() == 1) + { + PasteEntities(editor->selectedEntities.back()); + } + } + if (ImGui::IsKeyReleased(ImGuiKey_Delete)) + { + DeleteSelectedEntities(); } } - if (ImGui::IsKeyReleased(ImGuiKey_Delete)) - { - DeleteSelectedEntities(); - } - } if(ImGui::IsWindowHovered() && !ImGui::IsAnyItemHovered() && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { From 42f4c1c75ebfa6922a88b5aa5341d3aff84811b3 Mon Sep 17 00:00:00 2001 From: SHAM-DP Date: Fri, 24 Feb 2023 20:21:09 +0800 Subject: [PATCH 2/3] Aspect Ratio WIP --- .../ViewportWindow/SHEditorViewport.cpp | 74 ++++++++++++++++++- .../ViewportWindow/SHEditorViewport.h | 13 +++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp index 8c32b1c5..7ea4d799 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp @@ -59,7 +59,7 @@ namespace SHADE camSystem->UpdateEditorArm(SHFrameRateController::GetRawDeltaTime(), shouldUpdateCamArm, targetPos); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - + if (Begin()) { ImGuizmo::SetDrawlist(); @@ -121,12 +121,22 @@ namespace SHADE //auto pos = ImGui::GetCursorPos(); //windowCursorPos = {} + if (beginContentRegionAvailable.x == 0 || beginContentRegionAvailable.y == 0) { beginContentRegionAvailable = windowSize; } - gfxSystem->PrepareResize(static_cast(beginContentRegionAvailable.x), static_cast(beginContentRegionAvailable.y)); + + //beginContentRegionAvailable = CalculateWindowSize(beginContentRegionAvailable); + SHVec2 viewportSize = CalculateWindowSize(beginContentRegionAvailable); + gfxSystem->PrepareResize(static_cast(viewportSize.x), static_cast(viewportSize.y)); shouldUpdateCamera = true; + //if (aspectRatio != AspectRatio::FREE && (ImGui::IsMouseDown(ImGuiMouseButton_Left) || ImGui::IsMouseReleased(ImGuiMouseButton_Left))) + //{ + // windowSize = CalculateWindowSize(windowSize); + // beginContentRegionAvailable = CalculateWindowSize(beginContentRegionAvailable); + // ImGui::SetWindowSize(windowName.data(), CalculateWindowSize(windowSize)); + //} } void SHEditorViewport::OnPosChange() @@ -194,13 +204,73 @@ namespace SHADE ImGui::PopStyleColor(); ImGui::EndDisabled(); + //TODO: Shift to constructor + auto arRTTRtype = rttr::type::get(); + auto enumAlign = arRTTRtype.get_enumeration(); + auto names = enumAlign.get_names(); + std::vector arNames; + for (auto const& name : names) + { + arNames.push_back(name.data()); + } + int currentAR = static_cast(aspectRatio); + ImGui::SetNextItemWidth(80.0f); + if (ImGui::Combo("Aspect Ratio", ¤tAR, arNames.data(), arNames.size())) + { + aspectRatio = static_cast(currentAR); + windowSize = CalculateWindowSize(windowSize); + ImGui::SetWindowSize(windowSize); + //beginContentRegionAvailable = CalculateWindowSize(beginContentRegionAvailable); + //OnResize(); + } + auto camSystem = SHSystemManager::GetSystem(); auto editorCamera = camSystem->GetEditorCamera(); //ImGui::SetNextItemWidth(10.0f); SHEditorWidgets::SliderFloat("CamSpeed", 0.0f, 5.0f, [editorCamera] {return editorCamera->movementSpeed; }, [editorCamera](float const& value) {editorCamera->movementSpeed = value; }); SHEditorWidgets::DragVec3("TurnSpeed", { "X", "Y", "Z" }, [editorCamera] {return editorCamera->turnSpeed; }, [editorCamera](SHVec3 const& value) {editorCamera->turnSpeed = value; }); + //if(ImGui::BeginCombo("Aspect Ratio", arNames[(uint8_t)aspectRatio].data())) + //{ + // auto nameIt = names.begin(); + // auto valueIt = values.end(); + // while(nameIt != names.end() && valueIt != values.end()) + // { + // if ImGui::Beg + // } + //} + ImGui::EndMenuBar(); } } + + SHVec2 SHEditorViewport::CalculateWindowSize(SHVec2 const& rhs) noexcept +{ + switch (aspectRatio) + { + case SHADE::SHEditorViewport::AspectRatio::FREE: + return rhs; + case SHADE::SHEditorViewport::AspectRatio::AR16_9: + return SHVec2(rhs.x, rhs.x * 0.5625f); + case SHADE::SHEditorViewport::AspectRatio::AR21_9: + return SHVec2(rhs.x, rhs.x * 0.42857f); + case SHADE::SHEditorViewport::AspectRatio::AR21_10: + return SHVec2(rhs.x, rhs.x * 0.47619f); + default: + return rhs; + } + } + }//namespace SHADE + +RTTR_REGISTRATION +{ + using namespace rttr; + using namespace SHADE; + registration::enumeration("AspectRatio")( + value("FREE", SHEditorViewport::AspectRatio::FREE), + value("16:9", SHEditorViewport::AspectRatio::AR16_9), + value("21:9", SHEditorViewport::AspectRatio::AR21_9), + value("21:10", SHEditorViewport::AspectRatio::AR21_10) + ); +} diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h index 8f49c514..d7fb0f39 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h @@ -16,7 +16,15 @@ namespace SHADE { class SHEditorViewport final : public SHEditorWindow { + public: + enum class AspectRatio : uint8_t + { + FREE, + AR16_9, + AR21_9, + AR21_10 + }; SHEditorViewport(); void Init() override; void Update() override; @@ -27,9 +35,12 @@ namespace SHADE void OnPosChange() override; private: void DrawMenuBar() noexcept; - SHVec2 beginCursorPos; + SHVec2 CalculateWindowSize(SHVec2 const& rhs) noexcept; + bool shouldUpdateCamera = false; bool shouldUpdateCamArm = false; + AspectRatio aspectRatio {AspectRatio::FREE}; + SHVec2 beginCursorPos; SHVec3 targetPos; };//class SHEditorViewport }//namespace SHADE From dabc94a845407c63a33f5684926db9864abb3580 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sun, 26 Feb 2023 23:26:24 +0800 Subject: [PATCH 3/3] editor cam pos display as requested --- .../EditorWindow/MenuBar/SHEditorMenuBar.cpp | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index e8c943c2..d0c71265 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -26,6 +26,8 @@ #include "Serialization/Configurations/SHConfigurationManager.h" #include "Editor/EditorWindow/SHEditorWindowManager.h" #include "Physics/System/SHPhysicsDebugDrawSystem.h" +#include "Camera/SHCameraSystem.h" +#include "Tools/Utilities/SHClipboardUtilities.h" const std::string LAYOUT_FOLDER_PATH{ std::string(ASSET_ROOT) + "/Editor/Layouts" }; @@ -154,7 +156,39 @@ namespace SHADE ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGui::GetStyle().Colors[ImGuiCol_MenuBarBg]); if (ImGui::BeginViewportSideBar("MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, menuBarHeight, editorMenuBarFlags)) { - ImGui::Text("Entity count: %zu", SHEntityManager::GetEntityCount()); + auto camSystem = SHSystemManager::GetSystem(); + std::string editorCamPosText{}; + auto editorCam = camSystem->GetEditorCamera(); + if(editorCam) + { + auto editorCamPos = editorCam->GetPosition(); + editorCamPosText = std::format("Editor Cam [X: {:.3f}, Y: {:.3f}, Z: {:.3f}]", editorCamPos.x, editorCamPos.y, editorCamPos.z); + + //ImGui::Text(editorCamPosText.data()); + } + ImGui::Text("Entity count: %zu %s", SHEntityManager::GetEntityCount(), editorCamPosText.data()); + if(ImGui::BeginPopupContextItem("EditorCamPosContext")) + { + if(editorCam) + { + if(ImGui::Selectable("Copy Editor Cam Pos X")) + { + auto editorCamPos = editorCam->GetPosition(); + SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.x)); + } + if (ImGui::Selectable("Copy Editor Cam Pos Y")) + { + auto editorCamPos = editorCam->GetPosition(); + SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.y)); + } + if (ImGui::Selectable("Copy Editor Cam Pos Z")) + { + auto editorCamPos = editorCam->GetPosition(); + SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.z)); + } + } + ImGui::EndPopup(); + } } ImGui::End(); ImGui::PopStyleColor();