summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/viewport.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index caf55fcca..2ef6b836d 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -673,8 +673,36 @@ void Viewport::walkByMouse(const MouseEvent &event)
{
const int destX = static_cast<int>((event.getX() + mPixelViewX)
/ static_cast<float>(mMap->getTileWidth()));
- const int destY = static_cast<int>((event.getY() + mPixelViewY)
- / static_cast<float>(mMap->getTileHeight()));
+ int destY;
+
+ if (mMap->isHeightsPresent())
+ {
+ const int clickY = event.getY() + mPixelViewY - 16;
+ destY = event.getY() + mPixelViewY;
+ int newDiffY = 1000000;
+ const int heightTiles = mainGraphics->mHeight / mMap->getTileHeight();
+ const int tileViewY = mPixelViewY / 32;
+ for (int f = tileViewY; f < tileViewY + heightTiles; f ++)
+ {
+ if (!mMap->getWalk(destX, f))
+ continue;
+
+ const int offset = mMap->getHeightOffset(destX, f) * 16;
+ const int pixelF = f * 32;
+ const int diff = abs(clickY + offset - pixelF);
+ if (diff < newDiffY)
+ {
+ destY = pixelF;
+ newDiffY = diff;
+ }
+ }
+ destY /= 32;
+ }
+ else
+ {
+ destY = static_cast<int>((event.getY() + mPixelViewY)
+ / static_cast<float>(mMap->getTileHeight()));
+ }
if (playerX != destX || playerY != destY)
{
if (!localPlayer->navigateTo(destX, destY))