diff --git a/src/main/java/games/rednblack/editor/controller/commands/CompositeCameraChangeCommand.java b/src/main/java/games/rednblack/editor/controller/commands/CompositeCameraChangeCommand.java index 55aa68c2..9d3c1708 100644 --- a/src/main/java/games/rednblack/editor/controller/commands/CompositeCameraChangeCommand.java +++ b/src/main/java/games/rednblack/editor/controller/commands/CompositeCameraChangeCommand.java @@ -71,6 +71,7 @@ public class CompositeCameraChangeCommand extends RevertibleCommand { facade.sendNotification(MsgAPI.EMPTY_SPACE_CLICKED); sandbox.overrideAmbientLightInComposite(); + sandbox.adjustCameraInComposites(); } @Override diff --git a/src/main/java/games/rednblack/editor/view/stage/Sandbox.java b/src/main/java/games/rednblack/editor/view/stage/Sandbox.java index 025727db..275f2c3e 100644 --- a/src/main/java/games/rednblack/editor/view/stage/Sandbox.java +++ b/src/main/java/games/rednblack/editor/view/stage/Sandbox.java @@ -83,6 +83,8 @@ public class Sandbox { private ProjectManager projectManager; private ResourceManager resourceManager; + + SceneConfigVO sceneConfigVO; public PixelRect selectionRec; @@ -93,6 +95,9 @@ public class Sandbox { private float timeToCameraZoomTarget, cameraZoomTarget, cameraZoomOrigin; private boolean moveCameraWithZoom = false; + private float timeToCameraPosTarget; + private Vector2 cameraPosTarget = new Vector2(), cameraPosOrigin = new Vector2(); + private Sandbox() { init(); } @@ -185,7 +190,7 @@ public class Sandbox { currentViewingEntity = getRootEntity(); - SceneConfigVO sceneConfigVO = projectManager.getCurrentSceneConfigVO(); + sceneConfigVO = projectManager.getCurrentSceneConfigVO(); getCamera().position.set(sceneConfigVO.cameraPosition[0], sceneConfigVO.cameraPosition[1], 0); setZoomPercent(sceneConfigVO.cameraZoom, false); projectManager.changeSceneWindowTitle(); @@ -226,6 +231,33 @@ public class Sandbox { facade.sendNotification(MsgAPI.ZOOM_CHANGED); } + + if (timeToCameraPosTarget > 0) { + timeToCameraPosTarget -= deltaTime; + float progress = timeToCameraPosTarget < 0 ? 1 : 1f - timeToCameraPosTarget / CAMERA_ZOOM_DURATION; + float x = Interpolation.smoother.apply(cameraPosOrigin.x, cameraPosTarget.x, progress); + float y = Interpolation.smoother.apply(cameraPosOrigin.y, cameraPosTarget.y, progress); + getCamera().position.set(x, y, 0); + } + } + + public void adjustCameraInComposites() { + if (!isViewingRootEntity()) { + cameraPosOrigin.set(getCamera().position.x, getCamera().position.y); + cameraPosTarget.set(0, 0); + timeToCameraPosTarget = CAMERA_ZOOM_DURATION; + } else { + cameraPosOrigin.set(getCamera().position.x, getCamera().position.y); + cameraPosTarget.set(sceneConfigVO.cameraPosition[0], sceneConfigVO.cameraPosition[1]); + timeToCameraPosTarget = CAMERA_ZOOM_DURATION; + } + } + + public void scenePanned() { + if (isViewingRootEntity()) { + sceneConfigVO.cameraPosition[0] = getCamera().position.x; + sceneConfigVO.cameraPosition[1] = getCamera().position.y; + } } /** @@ -293,21 +325,21 @@ public class Sandbox { public int getZoomPercent() { - return (int)projectManager.getCurrentSceneConfigVO().cameraZoom; + return (int)sceneConfigVO.cameraZoom; } public void setZoomPercent(float percent, boolean moveCamera) { - projectManager.getCurrentSceneConfigVO().cameraZoom = percent; + sceneConfigVO.cameraZoom = percent; cameraZoomOrigin = getCamera().zoom; - cameraZoomTarget = 1f / (projectManager.getCurrentSceneConfigVO().cameraZoom / 100f); + cameraZoomTarget = 1f / (sceneConfigVO.cameraZoom / 100f); timeToCameraZoomTarget = CAMERA_ZOOM_DURATION; moveCameraWithZoom = moveCamera; } public void zoomDivideBy(float amount) { - float zoomPercent = projectManager.getCurrentSceneConfigVO().cameraZoom / amount; + float zoomPercent = sceneConfigVO.cameraZoom / amount; if (zoomPercent < 20) zoomPercent = 20; if (zoomPercent > 1000) zoomPercent = 1000; @@ -343,11 +375,15 @@ public class Sandbox { return sceneControl.getRootEntity(); } + public boolean isViewingRootEntity() { + return currentViewingEntity.equals(getRootEntity()); + } + public void overrideAmbientLightInComposite() { SceneVO sceneVO = sceneControl.getCurrentSceneVO(); SettingsManager settingsManager = facade.retrieveProxy(SettingsManager.NAME); - boolean override = !currentViewingEntity.equals(getRootEntity()) && settingsManager.editorConfigVO.disableAmbientComposite; + boolean override = !isViewingRootEntity() && settingsManager.editorConfigVO.disableAmbientComposite; sceneLoader.setAmbientInfo(sceneVO, override); } diff --git a/src/main/java/games/rednblack/editor/view/stage/SandboxMediator.java b/src/main/java/games/rednblack/editor/view/stage/SandboxMediator.java index 3a8e9e19..b6f19d7f 100644 --- a/src/main/java/games/rednblack/editor/view/stage/SandboxMediator.java +++ b/src/main/java/games/rednblack/editor/view/stage/SandboxMediator.java @@ -104,7 +104,8 @@ public class SandboxMediator extends SimpleMediator { CompositeCameraChangeCommand.DONE, AddComponentToItemCommand.DONE, RemoveComponentFromItemCommand.DONE, - MsgAPI.ITEM_SELECTION_CHANGED + MsgAPI.ITEM_SELECTION_CHANGED, + PanTool.SCENE_PANNED }; } @@ -124,6 +125,9 @@ public class SandboxMediator extends SimpleMediator { case CompositeCameraChangeCommand.DONE: initItemListeners(); break; + case PanTool.SCENE_PANNED: + viewComponent.scenePanned(); + break; default: break; } diff --git a/src/main/java/games/rednblack/editor/view/stage/tools/PanTool.java b/src/main/java/games/rednblack/editor/view/stage/tools/PanTool.java index b214d73b..55b44372 100644 --- a/src/main/java/games/rednblack/editor/view/stage/tools/PanTool.java +++ b/src/main/java/games/rednblack/editor/view/stage/tools/PanTool.java @@ -105,12 +105,5 @@ public class PanTool extends SimpleTool { lastCoordinates = new Vector2(Gdx.input.getX(), Gdx.input.getY()); HyperLap2DFacade.getInstance().sendNotification(SCENE_PANNED); - - // Save the current position - // TODO: (this has to move to some kind of mediator that listens to scene panned event) - ProjectManager projectManager = HyperLap2DFacade.getInstance().retrieveProxy(ProjectManager.NAME); - SceneConfigVO sceneConfigVO = projectManager.getCurrentSceneConfigVO(); - sceneConfigVO.cameraPosition[0] = sandbox.getCamera().position.x; - sceneConfigVO.cameraPosition[1] = sandbox.getCamera().position.y; } }