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 | |
parent | 36eeb46446039147b64a4552242002beaaec680d (diff) | |
download | manaverse-7ba416812eff7e24e93e9a3918299d4386b4a89a.tar.gz manaverse-7ba416812eff7e24e93e9a3918299d4386b4a89a.tar.bz2 manaverse-7ba416812eff7e24e93e9a3918299d4386b4a89a.tar.xz manaverse-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')
-rw-r--r-- | src/commandhandler.cpp | 2 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 26 | ||||
-rw-r--r-- | src/localplayer.cpp | 23 | ||||
-rw-r--r-- | src/localplayer.h | 4 | ||||
-rw-r--r-- | src/net/tmwa/playerhandler.cpp | 2 |
5 files changed, 39 insertions, 18 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 6b7706a00..8d4168e76 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -690,7 +690,7 @@ void CommandHandler::handleNavigate(const std::string &args, if (parse2Int(args, &x, &y)) player_node->navigateTo(x, y); else - player_node->naviageClean(); + player_node->navigateClean(); } bool CommandHandler::parse2Int(const std::string &args, int *x, int *y) 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; } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index f43d7e2d5..0ab1ca713 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -2771,7 +2771,7 @@ void LocalPlayer::moveByDirection(unsigned char dir) void LocalPlayer::specialMove(unsigned char direction) { if (direction && (mNavigateX || mNavigateY)) - naviageClean(); + navigateClean(); if (direction && (getInvertDirection() >= 2 && getInvertDirection() <= 4) @@ -2922,7 +2922,7 @@ void LocalPlayer::setMap(Map *map) if (socialWindow) socialWindow->updateActiveList(); } - naviageClean(); + navigateClean(); mCrossX = 0; mCrossY = 0; @@ -3128,7 +3128,7 @@ void LocalPlayer::changeAwayMode() chatWindow->clearAwayLog(); cancelFollow(); - naviageClean(); + navigateClean(); if (outfitWindow) outfitWindow->wearAwayOutfit(); mAwayDialog = new OkDialog(_("Away"), @@ -3187,14 +3187,14 @@ void LocalPlayer::afkRespond(ChatTab *tab, const std::string &nick) } } -void LocalPlayer::navigateTo(int x, int y) +bool LocalPlayer::navigateTo(int x, int y) { if (!mMap) - return; + return false; SpecialLayer *tmpLayer = mMap->getTempLayer(); if (!tmpLayer) - return; + return false; const Vector &playerPos = getPosition(); mShowNavigePath = true; @@ -3213,6 +3213,7 @@ void LocalPlayer::navigateTo(int x, int y) if (mDrawPath) tmpLayer->addRoad(mNavigatePath); + return !mNavigatePath.empty(); } void LocalPlayer::navigateTo(Being *being) @@ -3243,7 +3244,7 @@ void LocalPlayer::navigateTo(Being *being) tmpLayer->addRoad(mNavigatePath); } -void LocalPlayer::naviageClean() +void LocalPlayer::navigateClean() { if (!mMap) return; @@ -3309,14 +3310,14 @@ void LocalPlayer::updateCoords() { if (!actorSpriteManager) { - naviageClean(); + navigateClean(); return; } Being* being = actorSpriteManager->findBeing(mNavigateId); if (!being) { - naviageClean(); + navigateClean(); return; } mNavigateX = being->getTileX(); @@ -3325,7 +3326,7 @@ void LocalPlayer::updateCoords() if (mNavigateX == x && mNavigateY == y) { - naviageClean(); + navigateClean(); return; } else @@ -3733,7 +3734,7 @@ void LocalPlayer::fixAttackTarget() void LocalPlayer::respawn() { - naviageClean(); + navigateClean(); } int LocalPlayer::getTargetTime() diff --git a/src/localplayer.h b/src/localplayer.h index e48afff12..4b9e98c13 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -327,11 +327,11 @@ class LocalPlayer : public Being, public ActorSpriteListener, void afkRespond(ChatTab *tab, const std::string &nick); - void navigateTo(int x, int y); + bool navigateTo(int x, int y); void navigateTo(Being *being); - void naviageClean(); + void navigateClean(); void updateCoords(); diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index ba881858e..5fb9d9508 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -249,7 +249,7 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) player_node->setAction(Being::STAND); player_node->setTileCoords(x, y); - player_node->naviageClean(); + player_node->navigateClean(); // player_node->updateNavigateList(); } |