From fe41245008cb775777e888989ebcdb2bff883a67 Mon Sep 17 00:00:00 2001 From: SHAM-DP Date: Thu, 9 Mar 2023 15:28:32 +0800 Subject: [PATCH] Bug Fixes & Tweaks for editor fixed window width for physics settings drop down fixed double click to look at fix crash when some fields in collider and rigidbody are set to 0.0f --- .../HierarchyPanel/SHHierarchyPanel.cpp | 3 +- .../Inspector/SHEditorComponentView.hpp | 13 ++++--- .../Inspector/SHEditorInspector.cpp | 36 +++++++++++++++++++ .../Inspector/SHEditorInspector.h | 2 +- .../EditorWindow/MenuBar/SHEditorMenuBar.cpp | 1 + SHADE_Engine/src/Editor/SHEditor.cpp | 6 ++++ 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp index 8f0a8193..311b1cd0 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/HierarchyPanel/SHHierarchyPanel.cpp @@ -454,7 +454,8 @@ namespace SHADE { if(auto entityTransform = SHComponentManager::GetComponent_s(eid)) { - editorCam->SetPosition(entityTransform->GetWorldPosition() + SHVec3(0.5f)); + SHVec3 scale = entityTransform->GetLocalScale(); + editorCam->SetPosition(entityTransform->GetWorldPosition() + scale * 0.5f); camSystem->CameraLookAt(*editorCam, entityTransform->GetWorldPosition()); camSystem->UpdateEditorCamera(SHFrameRateController::GetRawDeltaTime()); } diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index c655ff60..3f468d64 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -273,8 +273,8 @@ namespace SHADE } if (rbType == SHRigidBodyComponent::Type::DYNAMIC || rbType == SHRigidBodyComponent::Type::KINEMATIC) //Dynamic or Kinematic only fields { - SHEditorWidgets::DragFloat("Drag", [component] {return component->GetDrag(); }, [component](float const& value) {component->SetDrag(value); }, "Drag"); - SHEditorWidgets::DragFloat("Angular Drag", [component] {return component->GetAngularDrag(); }, [component](float const& value) {component->SetAngularDrag(value); }, "Angular Drag"); + SHEditorWidgets::DragFloat("Drag", [component] {return component->GetDrag(); }, [component](float const& value) {component->SetDrag(value); }, "Drag", 0.1f, 0.0001f, std::numeric_limits::infinity()); + SHEditorWidgets::DragFloat("Angular Drag", [component] {return component->GetAngularDrag(); }, [component](float const& value) {component->SetAngularDrag(value); }, "Angular Drag", 0.1f, 0.0001f, std::numeric_limits::infinity()); SHEditorWidgets::CheckBox("Interpolate", [component] {return component->IsInterpolating(); }, [component](bool const& value) {component->SetInterpolate(value); }, "Interpolate"); @@ -377,7 +377,8 @@ namespace SHADE ( "Radius", [sphereShape] { return sphereShape->GetRelativeRadius(); }, - [sphereShape](float const& value) { sphereShape->SetRelativeRadius(value); } + [sphereShape](float const& value) { sphereShape->SetRelativeRadius(value); }, "Collider Radius", 0.1f, + 0.0001f, std::numeric_limits::infinity() ); } else if (collisionShape->GetType() == SHCollisionShape::Type::CAPSULE) @@ -388,13 +389,15 @@ namespace SHADE ( "Radius", [capsuleShape] { return capsuleShape->GetRelativeRadius(); }, - [capsuleShape](float const& value) { capsuleShape->SetRelativeRadius(value); } + [capsuleShape](float const& value) { capsuleShape->SetRelativeRadius(value); }, "Collider Radius", 0.1f, + 0.0001f, std::numeric_limits::infinity() ); SHEditorWidgets::DragFloat ( "Height", [capsuleShape] { return capsuleShape->GetRelativeHeight(); }, - [capsuleShape](float const& value) { capsuleShape->SetRelativeHeight(value); } + [capsuleShape](float const& value) { capsuleShape->SetRelativeHeight(value); }, "Collider Height", 0.1f, + 0.0001f, std::numeric_limits::infinity() ); } diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index faede2bd..f331f499 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -26,6 +26,8 @@ #include "SHEditorComponentView.h" #include "AudioSystem/SHAudioListenerComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" +#include "Camera/SHCameraSystem.h" +#include "FRC/SHFramerateController.h" namespace SHADE { @@ -106,6 +108,7 @@ namespace SHADE { if (editor && !editor->selectedEntities.empty()) { + DrawMenuBar(); EntityID const& eid = editor->selectedEntities[0]; SHEntity* entity = SHEntityManager::GetEntityByID(eid); SHSceneNode* entityNode = SHSceneManager::GetCurrentSceneGraph().GetNode(eid); @@ -114,6 +117,7 @@ namespace SHADE ImGui::End(); return; } + ImGui::TextColored(ImGuiColors::green, "EID: %zu", eid); SHEditorWidgets::CheckBox("##IsActive", [entityNode]()->bool {return entityNode->IsActive(); }, [entityNode](bool const& active) {entityNode->SetActive(active); }); ImGui::SameLine(); @@ -222,4 +226,36 @@ namespace SHADE { SHEditorWindow::Exit(); } + void SHEditorInspector::DrawMenuBar() + { + if(ImGui::BeginMenuBar()) + { + EntityID const& eid = editor->selectedEntities[0]; + SHEntity* entity = SHEntityManager::GetEntityByID(eid); + SHSceneNode* entityNode = SHSceneManager::GetCurrentSceneGraph().GetNode(eid); + if (!entity || !entityNode) + { + ImGui::EndMenuBar(); + return; + } + if (ImGui::SmallButton("Look At")) + { + 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()); + } + } + } + } + ImGui::EndMenuBar(); + } + } } diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.h b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.h index 06676beb..431f3239 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.h +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.h @@ -25,6 +25,6 @@ namespace SHADE void Exit() override; private: - + void DrawMenuBar(); }; } diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index 21cc85f4..65e497aa 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -358,6 +358,7 @@ namespace SHADE void SHEditorMenuBar::DrawPhysicsSettings() noexcept { + ImGui::SetNextWindowSize({400.0f, 0.0f}); if (ImGui::BeginMenu("Physics Settings")) { if (auto* physicsSystem = SHSystemManager::GetSystem()) diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index 4c7db57c..4129cc15 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -669,6 +669,12 @@ namespace SHADE SaveScene(); } } + if(editorState == State::PLAY && ImGui::IsKeyReleased(ImGuiKey_LeftAlt)) + { + SHInputManager::SetMouseCentering(!SHInputManager::GetMouseCentering()); + SHWindow::SetMouseVisible(!SHWindow::GetMouseVisible()); + + } if (ImGui::IsKeyDown(ImGuiKey_LeftShift) && ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_Z)) { SHCommandManager::RedoCommand();