diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/viewport.cpp | 41 | ||||
-rw-r--r-- | src/gui/viewport.h | 8 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 1407415fd..f4c6c315f 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -875,3 +875,44 @@ bool Viewport::isPopupMenuVisible() { return mPopupMenu ? mPopupMenu->isVisible() : false; } + +void Viewport::moveCameraToActor(int actorId, int x, int y) +{ + if (!player_node) + return; + + Actor *actor = actorSpriteManager->findBeing(actorId); + if (!actor) + return; + Vector actorPos = actor->getPosition(); + Vector playerPos = player_node->getPosition(); + mCameraMode = 1; + mCameraRelativeX = actorPos.x - playerPos.x + x; + mCameraRelativeY = actorPos.y - playerPos.y + y; +} + +void Viewport::moveCameraToPosition(int x, int y) +{ + if (!player_node) + return; + + Vector playerPos = player_node->getPosition(); + mCameraMode = 1; + + mCameraRelativeX = x - playerPos.x; + mCameraRelativeY = y - playerPos.y; +} + +void Viewport::moveCameraRelative(int x, int y) +{ + mCameraMode = 1; + mCameraRelativeX += x; + mCameraRelativeY += y; +} + +void Viewport::returnCamera() +{ + mCameraMode = 0; + mCameraRelativeX = 0; + mCameraRelativeY = 0; +} diff --git a/src/gui/viewport.h b/src/gui/viewport.h index b25f51242..0f56e9426 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -250,6 +250,14 @@ class Viewport : public WindowContainer, public gcn::MouseListener, bool isPopupMenuVisible(); + void moveCameraToActor(int actorId, int x = 0, int y = 0); + + void moveCameraToPosition(int x, int y); + + void moveCameraRelative(int x, int y); + + void returnCamera(); + protected: friend class ActorSpriteManager; |