diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-06 19:54:39 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-06 19:54:39 +0300 |
commit | 64f4e1132355eaac4f5594bee516b56adb2ad083 (patch) | |
tree | 33d883af8b6d1e513b4982ebf8fdf84bc408082f /src/gui/minimap.cpp | |
parent | b18993f6b577429103497f4a50c3f2035a424820 (diff) | |
download | manaplus-64f4e1132355eaac4f5594bee516b56adb2ad083.tar.gz manaplus-64f4e1132355eaac4f5594bee516b56adb2ad083.tar.bz2 manaplus-64f4e1132355eaac4f5594bee516b56adb2ad083.tar.xz manaplus-64f4e1132355eaac4f5594bee516b56adb2ad083.zip |
Add ability to move by clicking on minimap.
Diffstat (limited to 'src/gui/minimap.cpp')
-rw-r--r-- | src/gui/minimap.cpp | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index c3a4417f6..a16da2b65 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -51,7 +51,9 @@ Minimap::Minimap(): mMapImage(0), mWidthProportion(0.5), mHeightProportion(0.5), - mCustomMapImage(false) + mCustomMapImage(false), + mMapOriginX(0), + mMapOriginY(0) { setWindowName("Minimap"); mShow = config.getValueBool(getWindowName() + "Show", true); @@ -215,8 +217,11 @@ void Minimap::draw(gcn::Graphics *graphics) graphics->pushClipArea(a); - int mapOriginX = 0; - int mapOriginY = 0; + if (!actorSpriteManager) + return; + + mMapOriginX = 0; + mMapOriginY = 0; if (mMapImage) { @@ -224,33 +229,30 @@ void Minimap::draw(gcn::Graphics *graphics) mMapImage->mBounds.h > a.height) { const Vector &p = player_node->getPosition(); - mapOriginX = ((a.width) / 2) - static_cast<int>((p.x + mMapOriginX = ((a.width) / 2) - static_cast<int>((p.x + viewport->getCameraRelativeX()) * static_cast<int>( mWidthProportion)) / 32; - mapOriginY = ((a.height) / 2) - static_cast<int>((p.y + mMapOriginY = ((a.height) / 2) - static_cast<int>((p.y + viewport->getCameraRelativeX()) * static_cast<int>( mHeightProportion)) / 32; const int minOriginX = a.width - mMapImage->mBounds.w; const int minOriginY = a.height - mMapImage->mBounds.h; - if (mapOriginX < minOriginX) - mapOriginX = minOriginX; - if (mapOriginY < minOriginY) - mapOriginY = minOriginY; - if (mapOriginX > 0) - mapOriginX = 0; - if (mapOriginY > 0) - mapOriginY = 0; + if (mMapOriginX < minOriginX) + mMapOriginX = minOriginX; + if (mMapOriginY < minOriginY) + mMapOriginY = minOriginY; + if (mMapOriginX > 0) + mMapOriginX = 0; + if (mMapOriginY > 0) + mMapOriginY = 0; } - graph->drawImage(mMapImage, mapOriginX, mapOriginY); + graph->drawImage(mMapImage, mMapOriginX, mMapOriginY); } - if (!actorSpriteManager) - return; - const ActorSprites &actors = actorSpriteManager->getAll(); for (ActorSpritesConstIterator it = actors.begin(), it_end = actors.end(); @@ -313,9 +315,9 @@ void Minimap::draw(gcn::Graphics *graphics) graphics->fillRectangle(gcn::Rectangle( static_cast<int>(pos.x * mWidthProportion) / 32 - + mapOriginX - offsetWidth, + + mMapOriginX - offsetWidth, static_cast<int>(pos.y * mHeightProportion) / 32 - + mapOriginY - offsetHeight, + + mMapOriginY - offsetHeight, dotSize, dotSize)); } @@ -351,9 +353,9 @@ void Minimap::draw(gcn::Graphics *graphics) graphics->fillRectangle(gcn::Rectangle( static_cast<int>(member->getX() - * mWidthProportion) + mapOriginX - offsetWidth, + * mWidthProportion) + mMapOriginX - offsetWidth, static_cast<int>(member->getY() - * mHeightProportion) + mapOriginY - offsetHeight, + * mHeightProportion) + mMapOriginY - offsetHeight, 2, 2)); } ++ it; @@ -367,10 +369,10 @@ void Minimap::draw(gcn::Graphics *graphics) int x = static_cast<int>((pos.x - (graph->getWidth() / 2) + viewport->getCameraRelativeX()) - * mWidthProportion) / 32 + mapOriginX; + * mWidthProportion) / 32 + mMapOriginX; int y = static_cast<int>((pos.y - (graph->getHeight() / 2) + viewport->getCameraRelativeY()) - * mHeightProportion) / 32 + mapOriginY; + * mHeightProportion) / 32 + mMapOriginY; const int w = static_cast<int>(static_cast<float>( graph->getWidth()) * mWidthProportion / 32); @@ -396,3 +398,22 @@ void Minimap::draw(gcn::Graphics *graphics) graphics->drawRectangle(gcn::Rectangle(x, y, w, h)); graphics->popClipArea(); } + +void Minimap::mouseReleased(gcn::MouseEvent &event) +{ + gcn::Window::mouseReleased(event); + + if (!player_node) + return; + + if (event.getButton() == gcn::MouseEvent::LEFT) + { + const gcn::Rectangle a = getChildrenArea(); + const int x = event.getX() - a.x; + const int y = event.getY() - a.y; + + player_node->navigateTo((x - mMapOriginX + mWidthProportion) + / mWidthProportion, (y - mMapOriginY + mHeightProportion) + / mHeightProportion); + } +} |