From a1af19c271775fe998eee74251f1dbfa63448918 Mon Sep 17 00:00:00 2001 From: Yuri Pourre Date: Tue, 12 Apr 2022 17:51:46 -0700 Subject: [PATCH] QOL: Keep selection when changing tools --- .../mundus/editor/tools/ToolManager.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/editor/src/main/com/mbrlabs/mundus/editor/tools/ToolManager.java b/editor/src/main/com/mbrlabs/mundus/editor/tools/ToolManager.java index 2e508ddf6..2beb507ff 100644 --- a/editor/src/main/com/mbrlabs/mundus/editor/tools/ToolManager.java +++ b/editor/src/main/com/mbrlabs/mundus/editor/tools/ToolManager.java @@ -21,6 +21,8 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Disposable; +import com.mbrlabs.mundus.commons.scene3d.GameObject; +import com.mbrlabs.mundus.editor.core.EditorScene; import com.mbrlabs.mundus.editor.core.project.ProjectManager; import com.mbrlabs.mundus.editor.history.CommandHistory; import com.mbrlabs.mundus.editor.input.InputManager; @@ -68,10 +70,17 @@ public ToolManager(InputManager inputManager, ProjectManager projectManager, Gam } public void activateTool(Tool tool) { + boolean shouldKeepSelection = activeTool != null && activeTool instanceof SelectionTool && tool instanceof SelectionTool; + GameObject selected = getSelectedObject(); + deactivateTool(); activeTool = tool; inputManager.addProcessor(activeTool); activeTool.onActivated(); + + if (shouldKeepSelection) { + ((SelectionTool)activeTool).gameObjectSelected(selected); + } } public void deactivateTool() { @@ -130,4 +139,16 @@ public void dispose() { scaleTool.dispose(); } + private GameObject getSelectedObject() { + if (activeTool == null) { + return null; + } + EditorScene scene = getActiveTool().getProjectManager().current().currScene; + + if (scene == null) { + return null; + } + return scene.currentSelection; + } + }