Skip to content

Commit

Permalink
[Editor] Persist snapping preferences in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
OrfeasZ committed Dec 30, 2023
1 parent ed3a0d0 commit 25ddd97
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
8 changes: 5 additions & 3 deletions Mods/Editor/Src/Components/EntityManipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(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<SVector3>("m_PrimitiveScale", s_ModelMatrix.GetScale());

Expand All @@ -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<float>(m_SnapValue), static_cast<float>(m_SnapValue), static_cast<float>(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))
{
Expand All @@ -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<float>(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);
}
Expand Down
30 changes: 24 additions & 6 deletions Mods/Editor/Src/Components/EntityProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
26 changes: 26 additions & 0 deletions Mods/Editor/Src/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions Mods/Editor/Src/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 25ddd97

Please sign in to comment.