summaryrefslogtreecommitdiff
path: root/src/gui/viewport.cpp
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 /src/gui/viewport.cpp
parentf06bb70e7fb4603fb5888351a7e046e710ba7ae1 (diff)
downloadmv-509f043983f347a33c65b0f7beee91236e622bf9.tar.gz
mv-509f043983f347a33c65b0f7beee91236e622bf9.tar.bz2
mv-509f043983f347a33c65b0f7beee91236e622bf9.tar.xz
mv-509f043983f347a33c65b0f7beee91236e622bf9.zip
Fix moving with mouse on tiles with height > 0.
Diffstat (limited to 'src/gui/viewport.cpp')
-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))