From 98140aa7975f65b05f85f2d1a047b035d09f96c6 Mon Sep 17 00:00:00 2001 From: SHAM-DP Date: Wed, 1 Mar 2023 17:06:53 +0800 Subject: [PATCH] Added scripting interface for cursor visible. Fixed collider offset undo/redo Double click object to look at object Display editor cam pitch/yaw/roll --- .../src/Application/SBApplication.cpp | 2 -- .../HierarchyPanel/SHHierarchyPanel.cpp | 21 ++++++++++++++++++- .../Inspector/SHEditorComponentView.hpp | 6 +++--- .../EditorWindow/MenuBar/SHEditorMenuBar.cpp | 20 +++++++++++++++--- .../src/Graphics/Windowing/SHWindow.cpp | 16 ++++++++++++-- .../src/Graphics/Windowing/SHWindow.h | 3 ++- SHADE_Managed/src/Engine/Application.cxx | 9 +++++++- SHADE_Managed/src/Engine/Application.hxx | 6 ++++++ 8 files changed, 70 insertions(+), 13 deletions(-) diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 3ebcc904..5620e258 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -174,7 +174,6 @@ namespace Sandbox SHSceneManager::InitSceneManager(editorConfig.workingSceneID); #else SHSceneManager::InitSceneManager(appConfig.startingSceneID); - window.SetMouseVisible(false); #endif SHFrameRateController::UpdateFRC(); @@ -183,7 +182,6 @@ namespace Sandbox auto clip = SHResourceManager::LoadOrGet(77816045); auto rig = SHResourceManager::LoadOrGet(77816045); - int i = 0; } void SBApplication::Update(void) diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp index 8cc41d56..8f0a8193 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp @@ -31,6 +31,8 @@ #include "../AssetBrowser/SHAssetBrowser.h" #include "Assets/SHAssetManager.h" #include "Assets/Asset Types/SHPrefabAsset.h" +#include "Camera/SHCameraSystem.h" +#include "FRC/SHFramerateController.h" namespace SHADE @@ -442,7 +444,24 @@ namespace SHADE //Handle node selection if (ImGui::IsItemHovered()) { - if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) + if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + { + editor->selectedEntities.clear(); + editor->selectedEntities.push_back(eid); + if(auto camSystem = SHSystemManager::GetSystem()) + { + if(auto editorCam = camSystem->GetEditorCamera()) + { + if(auto entityTransform = SHComponentManager::GetComponent_s(eid)) + { + editorCam->SetPosition(entityTransform->GetWorldPosition() + SHVec3(0.5f)); + camSystem->CameraLookAt(*editorCam, entityTransform->GetWorldPosition()); + camSystem->UpdateEditorCamera(SHFrameRateController::GetRawDeltaTime()); + } + } + } + } + else if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { if (!isSelected) { diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 6aacfbf0..9e86f7bf 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -387,14 +387,14 @@ namespace SHADE } SHEditorWidgets::BeginPanel("Offsets",{ ImGui::GetContentRegionAvail().x, 30.0f }); - SHEditorWidgets::DragVec3("Position", { "X", "Y", "Z" }, [&collisionShape] {return collisionShape->GetPositionOffset(); }, [&collisionShape](SHVec3 const& vec) {collisionShape->SetPositionOffset(vec); }); + SHEditorWidgets::DragVec3("Position", { "X", "Y", "Z" }, [collisionShape] {return collisionShape->GetPositionOffset(); }, [collisionShape](SHVec3 const& vec) {collisionShape->SetPositionOffset(vec); }); SHEditorWidgets::DragVec3("Rotation", { "X", "Y", "Z" }, - [&collisionShape] + [collisionShape] { auto offset = collisionShape->GetRotationOffset(); return offset; }, - [&collisionShape](SHVec3 const& vec) + [collisionShape](SHVec3 const& vec) { collisionShape->SetRotationOffset(vec); }, true); diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index d0c71265..6072c6a8 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -157,16 +157,16 @@ namespace SHADE if (ImGui::BeginViewportSideBar("MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, menuBarHeight, editorMenuBarFlags)) { auto camSystem = SHSystemManager::GetSystem(); - std::string editorCamPosText{}; + std::string editorCamPosText{}, editorRotText{}; 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); - + editorRotText = std::format("[Pitch: {:.3f}, Yaw: {:.3f}, Roll: {:.3f}]", editorCam->GetPitch(), editorCam->GetYaw(), editorCam->GetRoll()); //ImGui::Text(editorCamPosText.data()); } - ImGui::Text("Entity count: %zu %s", SHEntityManager::GetEntityCount(), editorCamPosText.data()); + ImGui::Text("Entity count: %zu | %s | %s", SHEntityManager::GetEntityCount(), editorCamPosText.data(), editorRotText.data()); if(ImGui::BeginPopupContextItem("EditorCamPosContext")) { if(editorCam) @@ -186,6 +186,20 @@ namespace SHADE auto editorCamPos = editorCam->GetPosition(); SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCamPos.z)); } + if (ImGui::Selectable("Copy Editor Cam Pitch")) + { + SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}", editorCam->GetPitch())); + } + if (ImGui::Selectable("Copy Editor Cam Yaw")) + { + auto editorCamPos = editorCam->GetPosition(); + SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}",editorCam->GetYaw())); + } + if (ImGui::Selectable("Copy Editor Cam Roll")) + { + auto editorCamPos = editorCam->GetPosition(); + SHClipboardUtilities::WriteToClipboard(std::format("{:.3f}",editorCam->GetRoll())); + } } ImGui::EndPopup(); } diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp index 13d9c143..078d9fc8 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp @@ -183,10 +183,22 @@ namespace SHADE return WindowSize(screenWidth, screenHeight); } + bool SHWindow::GetMouseVisible() + { + CURSORINFO cursorInfo{}; + cursorInfo.cbSize = sizeof(cursorInfo); + BOOL result = GetCursorInfo(&cursorInfo); + if(!result) + { + auto error = GetLastError(); + SHLOG_ERROR("SHWindow: Failed to get cursor info") + } + return cursorInfo.flags != 0; + } + void SHWindow::SetMouseVisible(bool show) { - if (GetActiveWindow() == wndHWND) - ShowCursor(show); + ShowCursor(show); } void SHWindow::SetMousePosition(int x, int y) diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h index 530f1778..9ad48f28 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h @@ -104,7 +104,8 @@ namespace SHADE //Get size of display the window is in (whichever window contains the window origin) WindowSize GetCurrentDisplaySize() const; - void SetMouseVisible(bool show); + static bool GetMouseVisible(); + static void SetMouseVisible(bool show); void SetMousePosition(int x = -1, int y = -1); diff --git a/SHADE_Managed/src/Engine/Application.cxx b/SHADE_Managed/src/Engine/Application.cxx index 5bde66d2..ba0cb592 100644 --- a/SHADE_Managed/src/Engine/Application.cxx +++ b/SHADE_Managed/src/Engine/Application.cxx @@ -71,7 +71,14 @@ namespace SHADE { return SHGraphicsSystemInterface::SetFullscreen(value); }*/ - + bool Application::IsCursorVisible::get() + { + return SHWindow::GetMouseVisible(); + } + void Application::IsCursorVisible::set(bool value) + { + SHWindow::SetMouseVisible(value); + } /*---------------------------------------------------------------------------------*/ /* Usage Functions */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Engine/Application.hxx b/SHADE_Managed/src/Engine/Application.hxx index 4467ec3b..6e04b725 100644 --- a/SHADE_Managed/src/Engine/Application.hxx +++ b/SHADE_Managed/src/Engine/Application.hxx @@ -73,6 +73,12 @@ namespace SHADE //void set(bool value); } + static property bool IsCursorVisible + { + bool get(); + void set(bool value); + } + /*-----------------------------------------------------------------------------*/ /* Usage Functions */ /*-----------------------------------------------------------------------------*/