diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-18 17:49:18 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-18 17:49:18 +0300 |
commit | 70b520b1e876f9698bb95baa2d274ea289a0c6bd (patch) | |
tree | 152c7519b0d9b8fb424af2373ec48db823a85575 /src/gui/minimap.cpp | |
parent | 62ec17f6e489ec50f17219444468aeb8969dc961 (diff) | |
parent | 3b999f51c740d0541c53d223518e5e4bb482d996 (diff) | |
download | mv-stripped1.1.9.18.tar.gz mv-stripped1.1.9.18.tar.bz2 mv-stripped1.1.9.18.tar.xz mv-stripped1.1.9.18.zip |
Merge branch 'master' into strippedstripped1.1.9.18
Conflicts:
src/guichan/cliprectangle.cpp
src/guichan/focushandler.cpp
src/guichan/gui.cpp
src/guichan/include/guichan/cliprectangle.hpp
src/guichan/include/guichan/inputevent.hpp
src/guichan/include/guichan/keyevent.hpp
src/guichan/include/guichan/mouseevent.hpp
src/guichan/include/guichan/widgets/button.hpp
src/guichan/include/guichan/widgets/checkbox.hpp
src/guichan/include/guichan/widgets/dropdown.hpp
src/guichan/include/guichan/widgets/radiobutton.hpp
src/guichan/include/guichan/widgets/slider.hpp
src/guichan/include/guichan/widgets/tab.hpp
src/guichan/include/guichan/widgets/tabbedarea.hpp
src/guichan/include/guichan/widgets/textfield.hpp
src/guichan/include/guichan/widgets/window.hpp
src/guichan/inputevent.cpp
src/guichan/keyevent.cpp
src/guichan/mouseevent.cpp
src/guichan/widget.cpp
src/guichan/widgets/button.cpp
src/guichan/widgets/checkbox.cpp
src/guichan/widgets/dropdown.cpp
src/guichan/widgets/radiobutton.cpp
src/guichan/widgets/slider.cpp
src/guichan/widgets/tab.cpp
src/guichan/widgets/tabbedarea.cpp
src/guichan/widgets/textfield.cpp
src/guichan/widgets/window.cpp
Diffstat (limited to 'src/gui/minimap.cpp')
-rw-r--r-- | src/gui/minimap.cpp | 71 |
1 files changed, 46 insertions, 25 deletions
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index c3a4417f6..e42f12336 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -47,11 +47,13 @@ bool Minimap::mShow = true; Minimap::Minimap(): - Window(_("Map")), + Window(_("Map"), false, 0, "map.xml"), mMapImage(0), mWidthProportion(0.5), mHeightProportion(0.5), - mCustomMapImage(false) + mCustomMapImage(false), + mMapOriginX(0), + mMapOriginY(0) { setWindowName("Minimap"); mShow = config.getValueBool(getWindowName() + "Show", true); @@ -87,7 +89,7 @@ Minimap::~Minimap() void Minimap::setMap(Map *map) { - std::string caption = ""; + std::string caption(""); std::string minimapName; if (map) @@ -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); + } +} |