summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-07-13 00:35:00 +0300
committerAndrei Karas <akaras@inbox.ru>2015-07-13 20:31:02 +0300
commit509f043983f347a33c65b0f7beee91236e622bf9 (patch)
tree082e914f5e49138171f0e056f08e8460c0562ea0
parentf06bb70e7fb4603fb5888351a7e046e710ba7ae1 (diff)
downloadmanaplus-509f043983f347a33c65b0f7beee91236e622bf9.tar.gz
manaplus-509f043983f347a33c65b0f7beee91236e622bf9.tar.bz2
manaplus-509f043983f347a33c65b0f7beee91236e622bf9.tar.xz
manaplus-509f043983f347a33c65b0f7beee91236e622bf9.zip
Fix moving with mouse on tiles with height > 0.
-rw-r--r--src/gui/viewport.cpp32
-rw-r--r--src/resources/map/map.h3
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;