From 25ddd9749b87ea743168c7b4b69a4d1088189bb5 Mon Sep 17 00:00:00 2001 From: OrfeasZ Date: Sat, 30 Dec 2023 15:31:57 +0200 Subject: [PATCH] [Editor] Persist snapping preferences in settings --- .../Src/Components/EntityManipulator.cpp | 8 +++-- .../Src/Components/EntityProperties.cpp | 30 +++++++++++++++---- Mods/Editor/Src/Editor.cpp | 26 ++++++++++++++++ Mods/Editor/Src/Editor.h | 6 ++-- 4 files changed, 58 insertions(+), 12 deletions(-) diff --git a/Mods/Editor/Src/Components/EntityManipulator.cpp b/Mods/Editor/Src/Components/EntityManipulator.cpp index 5d280c20..d173d326 100644 --- a/Mods/Editor/Src/Components/EntityManipulator.cpp +++ b/Mods/Editor/Src/Components/EntityManipulator.cpp @@ -98,7 +98,8 @@ void Editor::DrawEntityManipulator(bool p_HasFocus) s_ModelMatrix.ScaleTransform(s_Scale.Get()); - if (ImGuizmo::Manipulate(&s_ViewMatrix.XAxis.x, &s_ProjectionMatrix.XAxis.x, m_GizmoMode, m_GizmoSpace, &s_ModelMatrix.XAxis.x, NULL, m_UseScaleSnap ? &m_ScaleSnapValue : NULL)) + float s_ScaleSnapValue = static_cast(m_ScaleSnapValue); + if (ImGuizmo::Manipulate(&s_ViewMatrix.XAxis.x, &s_ProjectionMatrix.XAxis.x, m_GizmoMode, m_GizmoSpace, &s_ModelMatrix.XAxis.x, NULL, m_UseScaleSnap ? &s_ScaleSnapValue : NULL)) { m_SelectedEntity.SetProperty("m_PrimitiveScale", s_ModelMatrix.GetScale()); @@ -114,7 +115,7 @@ void Editor::DrawEntityManipulator(bool p_HasFocus) } else if (m_GizmoMode == ImGuizmo::TRANSLATE) { - float m_CombinedSnapValue[3] = {m_SnapValue, m_SnapValue, m_SnapValue}; + float m_CombinedSnapValue[3] = {static_cast(m_SnapValue), static_cast(m_SnapValue), static_cast(m_SnapValue)}; if (ImGuizmo::Manipulate(&s_ViewMatrix.XAxis.x, &s_ProjectionMatrix.XAxis.x, m_GizmoMode, m_GizmoSpace, &s_ModelMatrix.XAxis.x, NULL, m_UseSnap ? m_CombinedSnapValue : NULL)) { @@ -123,7 +124,8 @@ void Editor::DrawEntityManipulator(bool p_HasFocus) } else if (m_GizmoMode == ImGuizmo::ROTATE) { - if (ImGuizmo::Manipulate(&s_ViewMatrix.XAxis.x, &s_ProjectionMatrix.XAxis.x, m_GizmoMode, m_GizmoSpace, &s_ModelMatrix.XAxis.x, NULL, m_UseAngleSnap ? &m_AngleSnapValue : NULL)) + float s_AngleSnapValue = static_cast(m_AngleSnapValue); + if (ImGuizmo::Manipulate(&s_ViewMatrix.XAxis.x, &s_ProjectionMatrix.XAxis.x, m_GizmoMode, m_GizmoSpace, &s_ModelMatrix.XAxis.x, NULL, m_UseAngleSnap ? &s_AngleSnapValue : NULL)) { OnEntityTransformChange(s_SelectedEntity, s_ModelMatrix, false, std::nullopt); } diff --git a/Mods/Editor/Src/Components/EntityProperties.cpp b/Mods/Editor/Src/Components/EntityProperties.cpp index c9fa464f..26971923 100644 --- a/Mods/Editor/Src/Components/EntityProperties.cpp +++ b/Mods/Editor/Src/Components/EntityProperties.cpp @@ -54,17 +54,35 @@ void Editor::DrawEntityProperties() { static bool s_LocalTransform = false; ImGui::Checkbox("Local Transforms", &s_LocalTransform); - ImGui::Checkbox("##UseSnap", &m_UseSnap); + if (ImGui::Checkbox("##UseSnap", &m_UseSnap)) { + SetSettingBool("general", "snap", m_UseSnap); + } + ImGui::SameLine(); - ImGui::InputFloat("Snap", &m_SnapValue); - ImGui::Checkbox("##UseAngleSnap", &m_UseAngleSnap); + if (ImGui::InputDouble("Snap", &m_SnapValue)) { + SetSettingDouble("general", "snap_value", m_SnapValue); + } + + if (ImGui::Checkbox("##UseAngleSnap", &m_UseAngleSnap)) { + SetSettingBool("general", "angle_snap", m_UseAngleSnap); + } + ImGui::SameLine(); - ImGui::InputFloat("Angle Snap", &m_AngleSnapValue); - ImGui::Checkbox("##UseScaleSnap", &m_UseScaleSnap); + if (ImGui::InputDouble("Angle Snap", &m_AngleSnapValue)) { + SetSettingDouble("general", "angle_snap_value", m_AngleSnapValue); + } + + if (ImGui::Checkbox("##UseScaleSnap", &m_UseScaleSnap)) { + SetSettingBool("general", "scale_snap", m_UseScaleSnap); + } + ImGui::SameLine(); - ImGui::InputFloat("Scale Snap", &m_ScaleSnapValue); + + if (ImGui::InputDouble("Scale Snap", &m_ScaleSnapValue)) { + SetSettingDouble("general", "scale_snap_value", m_ScaleSnapValue); + } ImGui::Separator(); diff --git a/Mods/Editor/Src/Editor.cpp b/Mods/Editor/Src/Editor.cpp index f4d7292f..54ac50dc 100644 --- a/Mods/Editor/Src/Editor.cpp +++ b/Mods/Editor/Src/Editor.cpp @@ -86,6 +86,13 @@ void Editor::Init() Hooks::ZTemplateEntityBlueprintFactory_ZTemplateEntityBlueprintFactory->AddDetour(this, &Editor::ZTemplateEntityBlueprintFactory_ctor); Hooks::SignalInputPin->AddDetour(this, &Editor::OnInputPin); Hooks::SignalOutputPin->AddDetour(this, &Editor::OnOutputPin); + + m_UseSnap = GetSettingBool("general", "snap", true); + m_SnapValue = GetSettingDouble("general", "snap_value", 1.0); + m_UseAngleSnap = GetSettingBool("general", "angle_snap", true); + m_AngleSnapValue = GetSettingDouble("general", "angle_snap_value", 90.0); + m_UseScaleSnap = GetSettingBool("general", "scale_snap", true); + m_ScaleSnapValue = GetSettingDouble("general", "scale_snap_value", 1.0); } void Editor::OnDrawMenu() @@ -183,6 +190,25 @@ void Editor::CopyToClipboard(const std::string& p_String) const void Editor::OnDraw3D(IRenderer* p_Renderer) { DrawEntityAABB(p_Renderer); + + /*const auto s_Color = SVector4(0.88, 0.88, 0.08, 0.4); + const auto s_LineColor = SVector4(0.94, 0.12, 0.05, 1.0); + + p_Renderer->DrawQuad3D( + { -26.179094, -25.697458, 0.5 }, + s_Color, + { -25.915297, -27.365824, 0.5 }, + s_Color, + { -27.750357, -27.950037, 0.5 }, + s_Color, + { -27.304773, -25.154234, 0.5 }, + s_Color + );*/ + + //p_Renderer->DrawLine3D({ -35.352013, -23.58427, 0.4925564 }, { -27.71298, -24.866821, 0.4925564 }, s_LineColor, s_LineColor); + //p_Renderer->DrawLine3D({ -27.71298, -24.866821, 0.4925564 }, { -26.691515, -38.064953, 0.4925564 }, s_LineColor, s_LineColor); + //p_Renderer->DrawLine3D({ -26.691515, -38.064953, 0.4925564 }, { -41.43283, -33.25945, 0.49255627 }, s_LineColor, s_LineColor); + //p_Renderer->DrawLine3D({ -41.43283, -33.25945, 0.49255627 }, { -35.352013, -23.58427, 0.4925564 }, s_LineColor, s_LineColor); } void Editor::OnEngineInitialized() diff --git a/Mods/Editor/Src/Editor.h b/Mods/Editor/Src/Editor.h index 795a183b..45ea9c9b 100644 --- a/Mods/Editor/Src/Editor.h +++ b/Mods/Editor/Src/Editor.h @@ -124,9 +124,9 @@ class Editor : public IPluginInterface bool m_UseSnap = false; bool m_UseAngleSnap = false; bool m_UseScaleSnap = false; - float m_SnapValue = 1.0f; - float m_AngleSnapValue = 90.0f; - float m_ScaleSnapValue = 1.0f; + double m_SnapValue = 1.0; + double m_AngleSnapValue = 90.0; + double m_ScaleSnapValue = 1.0; float4 m_From; float4 m_To;