diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-05-06 03:35:15 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-05-06 03:41:41 +0300 |
commit | 7ba416812eff7e24e93e9a3918299d4386b4a89a (patch) | |
tree | 24285fe83c6072c86faac034f2cd6977a6a14d1b /src/gui/viewport.cpp | |
parent | 36eeb46446039147b64a4552242002beaaec680d (diff) | |
download | mv-7ba416812eff7e24e93e9a3918299d4386b4a89a.tar.gz mv-7ba416812eff7e24e93e9a3918299d4386b4a89a.tar.bz2 mv-7ba416812eff7e24e93e9a3918299d4386b4a89a.tar.xz mv-7ba416812eff7e24e93e9a3918299d4386b4a89a.zip |
Fix player moving with mouse.
Now move with mouse is soft moving. Player always can stop or change direction.
Collisions not stoping player what holding down left mouse button.
Also fix typo in method name navigateClean.
Diffstat (limited to 'src/gui/viewport.cpp')
-rw-r--r-- | src/gui/viewport.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index dfc4b217b..eb4fd6047 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -390,7 +390,6 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (Being::isTalking()) return; - mPlayerFollowMouse = false; const int pixelX = event.getX() + static_cast<int>(mPixelViewX); const int pixelY = event.getY() + static_cast<int>(mPixelViewY); @@ -398,6 +397,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) // Right click might open a popup if (event.getButton() == gcn::MouseEvent::RIGHT) { + mPlayerFollowMouse = false; if (mHoverBeing) { if (actorSpriteManager) @@ -434,6 +434,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) // If a popup is active, just remove it if (mPopupMenu->isVisible()) { + mPlayerFollowMouse = false; mPopupMenu->setVisible(false); return; } @@ -488,6 +489,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) } else if (event.getButton() == gcn::MouseEvent::MIDDLE) { + mPlayerFollowMouse = false; // Find the being nearest to the clicked position if (actorSpriteManager) { @@ -526,7 +528,7 @@ void Viewport::mouseDragged(gcn::MouseEvent &event) { if (mLocalWalkTime != player_node->getActionTime()) { - mLocalWalkTime = player_node->getActionTime(); + mLocalWalkTime = cur_time; int destX = static_cast<int>((static_cast<float>(event.getX()) + mPixelViewX) / static_cast<float>(mMap->getTileWidth())); @@ -534,7 +536,24 @@ void Viewport::mouseDragged(gcn::MouseEvent &event) + mPixelViewY) / static_cast<float>(mMap->getTileHeight())); player_node->unSetPickUpTarget(); - player_node->setDestination(destX, destY); + if (!player_node->navigateTo(destX, destY)) + { + int playerX = player_node->getTileX(); + int playerY = player_node->getTileY(); + if (playerX != destX && playerY != destY) + { + if (playerX > destX) + playerX --; + else if (playerX < destX) + playerX ++; + if (playerY > destY) + playerY --; + else if (playerY < destY) + playerY ++; + if (mMap->getWalk(playerX, playerY, 0)) + player_node->navigateTo(playerX, playerY); + } + } } } } @@ -544,6 +563,7 @@ void Viewport::mouseReleased(gcn::MouseEvent &event _UNUSED_) { mPlayerFollowMouse = false; + player_node->navigateClean(); // Only useful for eAthena but doesn't hurt under ManaServ mLocalWalkTime = -1; } |