summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-09-06 19:54:39 +0300
committerAndrei Karas <akaras@inbox.ru>2011-09-06 19:54:39 +0300
commit64f4e1132355eaac4f5594bee516b56adb2ad083 (patch)
tree33d883af8b6d1e513b4982ebf8fdf84bc408082f
parentb18993f6b577429103497f4a50c3f2035a424820 (diff)
downloadManaVerse-64f4e1132355eaac4f5594bee516b56adb2ad083.tar.gz
ManaVerse-64f4e1132355eaac4f5594bee516b56adb2ad083.tar.bz2
ManaVerse-64f4e1132355eaac4f5594bee516b56adb2ad083.tar.xz
ManaVerse-64f4e1132355eaac4f5594bee516b56adb2ad083.zip
Add ability to move by clicking on minimap.
-rw-r--r--src/gui/minimap.cpp67
-rw-r--r--src/gui/minimap.h4
2 files changed, 48 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);
+ }
+}
diff --git a/src/gui/minimap.h b/src/gui/minimap.h
index 33e0f14ee..86996f51c 100644
--- a/src/gui/minimap.h
+++ b/src/gui/minimap.h
@@ -58,12 +58,16 @@ class Minimap : public Window
*/
void draw(gcn::Graphics *graphics);
+ void mouseReleased(gcn::MouseEvent &event);
+
private:
Image *mMapImage;
float mWidthProportion;
float mHeightProportion;
static bool mShow;
bool mCustomMapImage;
+ int mMapOriginX;
+ int mMapOriginY;
};
extern Minimap *minimap;