diff options
-rw-r--r-- | src/gui/viewport.cpp | 32 | ||||
-rw-r--r-- | src/resources/map/map.h | 3 |
2 files changed, 33 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)) diff --git a/src/resources/map/map.h b/src/resources/map/map.h index 30ec2d240..ea083bd99 100644 --- a/src/resources/map/map.h +++ b/src/resources/map/map.h @@ -331,6 +331,9 @@ class Map final : public Properties, public ConfigListener void updateDrawLayersList(); + bool isHeightsPresent() const + { return mHeights != nullptr; } + protected: friend class Actor; friend class Minimap; |