From 509f043983f347a33c65b0f7beee91236e622bf9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 13 Jul 2015 00:35:00 +0300 Subject: Fix moving with mouse on tiles with height > 0. --- src/gui/viewport.cpp | 32 ++++++++++++++++++++++++++++++-- src/resources/map/map.h | 3 +++ 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'src') 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((event.getX() + mPixelViewX) / static_cast(mMap->getTileWidth())); - const int destY = static_cast((event.getY() + mPixelViewY) - / static_cast(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((event.getY() + mPixelViewY) + / static_cast(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; -- cgit v1.2.3-60-g2f50