diff --git a/src/engine/editor/Gizmo.cpp b/src/engine/editor/Gizmo.cpp index 7bfbf9d0a..71e011166 100644 --- a/src/engine/editor/Gizmo.cpp +++ b/src/engine/editor/Gizmo.cpp @@ -82,21 +82,28 @@ void Gizmo::Translate() { _selected->Pos->x = (cameras[0].pos[0] + _ray.x * PickDistance) + _cursorOffset.x; _selected->Pos->y = (cameras[0].pos[1] + _ray.y * PickDistance) + _cursorOffset.y; _selected->Pos->z = (cameras[0].pos[2] + _ray.z * PickDistance) + _cursorOffset.z; + if (CVarGetInteger("gEditorSnapToGround", false) == true) { + _selected->Pos->y = SnapToSurface(_selected->Pos); + } + printf("TEST %f\n", _selected->Pos->y); break; case GizmoHandle::X_Axis: _selected->Pos->x = (cameras[0].pos[0] + _ray.x * length) + _cursorOffset.x; + if (CVarGetInteger("gEditorSnapToGround", false) == true) { + _selected->Pos->y = SnapToSurface(_selected->Pos); + } break; case GizmoHandle::Y_Axis: _selected->Pos->y = (cameras[0].pos[1] + _ray.y * length) + _cursorOffset.y; break; case GizmoHandle::Z_Axis: _selected->Pos->z = (cameras[0].pos[2] + _ray.z * length) + _cursorOffset.z; + if (CVarGetInteger("gEditorSnapToGround", false) == true) { + _selected->Pos->y = SnapToSurface(_selected->Pos); + } break; } - if (CVarGetInteger("gEditorSnapToGround", false) == true) { - _selected->Pos->y = spawn_actor_on_surface(_selected->Pos->x, 2000.0f, _selected->Pos->z); - } Pos = FVector( _selected->Pos->x, @@ -106,6 +113,17 @@ void Gizmo::Translate() { } } +f32 Gizmo::SnapToSurface(FVector* pos) { + float y; + y = spawn_actor_on_surface(pos->x, 2000.0f, pos->z); + + if (y == 3000.0f || y == -3000.0f) { + y = pos->y; + } + + return y; +} + // void Gizmo::Rotate() { // } diff --git a/src/engine/editor/Gizmo.h b/src/engine/editor/Gizmo.h index f7d556f73..2dde2d4cc 100644 --- a/src/engine/editor/Gizmo.h +++ b/src/engine/editor/Gizmo.h @@ -25,6 +25,7 @@ public: void Enable(GameObject* object, Ray ray); void Translate(); void DrawHandles(); + f32 SnapToSurface(FVector* pos); bool Enabled; diff --git a/src/port/ui/ContentBrowser.cpp b/src/port/ui/ContentBrowser.cpp index 6d9d7099c..6c3ab0de1 100644 --- a/src/port/ui/ContentBrowser.cpp +++ b/src/port/ui/ContentBrowser.cpp @@ -23,4 +23,4 @@ namespace Editor { // Handle button click (example) } } -} \ No newline at end of file +} diff --git a/src/port/ui/SceneExplorer.cpp b/src/port/ui/SceneExplorer.cpp index e79289eff..372cb55d5 100644 --- a/src/port/ui/SceneExplorer.cpp +++ b/src/port/ui/SceneExplorer.cpp @@ -22,6 +22,5 @@ namespace Editor { if (ImGui::Button("Click Me")) { // Handle button click (example) } - ImGui::End(); } -} \ No newline at end of file +} diff --git a/src/port/ui/Tools.cpp b/src/port/ui/Tools.cpp index eef624a32..7cd18d481 100644 --- a/src/port/ui/Tools.cpp +++ b/src/port/ui/Tools.cpp @@ -23,8 +23,29 @@ namespace Editor { void ToolsWindow::DrawElement() { static bool toggleState = false; + static int selectedTool = 0; // 0: Move, 1: Rotate, 2: Scale + + // Function to check and highlight the selected button + auto ToolButton = [&](const char* label, int id) { + bool isSelected = (selectedTool == id); + ImGui::PushStyleColor(ImGuiCol_Button, isSelected ? ImVec4(0.2f, 0.8f, 0.2f, 1.0f) : ImVec4(0.8f, 0.2f, 0.2f, 1.0f)); + + if (ImGui::Button(label, ImVec2(125, 25))) { + selectedTool = id; // Set the selected tool + } + + ImGui::PopStyleColor(); + }; + + // Draw buttons + ToolButton("Move", 0); + ImGui::SameLine(); + ToolButton("Rotate", 1); + ImGui::SameLine(); + ToolButton("Scale", 2); + ImGui::PushStyleColor(ImGuiCol_Button, toggleState ? ImVec4(0.2f, 0.8f, 0.2f, 1.0f) : ImVec4(0.8f, 0.2f, 0.2f, 1.0f)); - if (ImGui::Button(toggleState ? "v" : "v", ImVec2(50, 25))) { + if (ImGui::Button(toggleState ? "SNAP TO GROUND" : "SNAP TO GROUND", ImVec2(125, 25))) { toggleState = !toggleState; CVarSetInteger("gEditorSnapToGround", toggleState);