summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/engine.cpp15
-rw-r--r--src/gui/minimap.cpp37
-rw-r--r--src/gui/minimap.h14
3 files changed, 36 insertions, 30 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index a0e475f6..5cceb4cc 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -84,11 +84,8 @@ bool Engine::changeMap(const std::string &mapPath)
logger->error("Could not find map file");
// Notify the minimap and beingManager about the map change
- Image *mapImage = NULL;
if (newMap->hasProperty("minimap"))
{
- mapImage = resman->getImage(newMap->getProperty("minimap"));
-
// Set the title for the Minimap
if (newMap->hasProperty("mapname"))
minimap->setCaption(newMap->getProperty("mapname"));
@@ -100,15 +97,7 @@ bool Engine::changeMap(const std::string &mapPath)
logger->log("WARNING: Map file '%s' defines a minimap image but "
"does not define a 'mapname' property",
map_path.c_str());
- }
-
- // How many pixels equal one tile. .5 (which is the TMW default) is
- // 2 tiles to a pixel, while 1 is 1 tile to 1 pixel
- if (newMap->hasProperty("minimapproportion"))
- minimap->setProportion(atof(
- newMap->getProperty("minimapproportion").c_str()));
- else
- minimap->setProportion(0.5);
+ }
}
if (newMap->hasProperty("name"))
{
@@ -116,7 +105,7 @@ bool Engine::changeMap(const std::string &mapPath)
} else {
minimap->setCaption("Map");
}
- minimap->setMapImage(mapImage);
+ minimap->setMap(newMap);
beingManager->setMap(newMap);
particleEngine->setMap(newMap);
viewport->setMap(newMap);
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 5781b3fe..019ffe6b 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -26,8 +26,11 @@
#include "configuration.h"
#include "graphics.h"
#include "localplayer.h"
+#include "map.h"
+#include "log.h"
#include "resources/image.h"
+#include "resources/resourcemanager.h"
#include "utils/gettext.h"
@@ -38,7 +41,8 @@ bool Minimap::mShow = true;
Minimap::Minimap():
Window(_("MiniMap")),
mMapImage(NULL),
- mProportion(0.5)
+ mHeightProportion(0.5),
+ mWidthProportion(0.5)
{
setWindowName("MiniMap");
mShow = config.getValue(getWindowName() + "Show", true);
@@ -51,6 +55,8 @@ Minimap::Minimap():
setSticky(false);
loadWindowState();
+
+ //Debug
}
Minimap::~Minimap()
@@ -61,12 +67,15 @@ Minimap::~Minimap()
config.setValue(getWindowName() + "Show", mShow);
}
-void Minimap::setMapImage(Image *img)
+void Minimap::setMap(Map *map)
{
if (mMapImage)
mMapImage->decRef();
- mMapImage = img;
+ mMap = map;
+
+ ResourceManager *resman = ResourceManager::getInstance();
+ mMapImage = resman->getImage(mMap->getProperty("minimap"));
if (mMapImage)
{
@@ -80,6 +89,13 @@ void Minimap::setMapImage(Image *img)
setMinWidth(mapWidth > titleWidth ? mapWidth : titleWidth);
setMinHeight(mapHeight);
+
+ mWidthProportion = (float) mMapImage->getWidth() / (float) mMap->getWidth();
+ mHeightProportion = (float) mMapImage->getHeight() / (float) mMap->getHeight();
+
+ logger->log("Minimap width : %d ; %d ; %f", mMapImage->getWidth(), mMap->getWidth(), mWidthProportion);
+ logger->log("Minimap height : %d ; %d ; %f", mMapImage->getHeight(), mMap->getHeight(), mHeightProportion);
+
setMaxWidth(mMapImage->getWidth() > titleWidth ?
mMapImage->getWidth() + offsetX : titleWidth);
setMaxHeight(mMapImage->getHeight() + offsetY);
@@ -117,8 +133,8 @@ void Minimap::draw(gcn::Graphics *graphics)
mMapImage->getHeight() > a.height)
{
const Vector &p = player_node->getPosition();
- mapOriginX = (int) (((a.width) / 2) - (int) (p.x * mProportion) / 32);
- mapOriginY = (int) (((a.height) / 2) - (int) (p.y * mProportion) / 32);
+ mapOriginX = (int) (((a.width) / 2) - (int) (p.x * mWidthProportion) / 32);
+ mapOriginY = (int) (((a.height) / 2) - (int) (p.y * mHeightProportion) / 32);
const int minOriginX = a.width - mMapImage->getWidth();
const int minOriginY = a.height - mMapImage->getHeight();
@@ -145,7 +161,8 @@ void Minimap::draw(gcn::Graphics *graphics)
const Being *being = (*bi);
int dotSize = 2;
- switch (being->getType()) {
+ switch (being->getType())
+ {
case Being::PLAYER:
if (being == player_node)
{
@@ -167,13 +184,15 @@ void Minimap::draw(gcn::Graphics *graphics)
default:
continue;
}
+
- const int offset = (int) ((dotSize - 1) * mProportion);
+ const int offsetHeight = (int) ((dotSize - 1) * mHeightProportion);
+ const int offsetWidth = (int) ((dotSize - 1) * mWidthProportion);
const Vector &pos = being->getPosition();
graphics->fillRectangle(gcn::Rectangle(
- (int) (pos.x * mProportion) / 32 + mapOriginX - offset,
- (int) (pos.y * mProportion) / 32 + mapOriginY - offset,
+ (int) (pos.x * mWidthProportion) / 32 + mapOriginX - offsetWidth,
+ (int) (pos.y * mHeightProportion) / 32 + mapOriginY - offsetHeight,
dotSize, dotSize));
}
diff --git a/src/gui/minimap.h b/src/gui/minimap.h
index c040f7ed..8196683e 100644
--- a/src/gui/minimap.h
+++ b/src/gui/minimap.h
@@ -23,6 +23,7 @@
#define MINIMAP_H
#include "gui/widgets/window.h"
+#include "map.h"
class Image;
@@ -47,13 +48,8 @@ class Minimap : public Window
/**
* Sets the map image that should be displayed.
*/
- void setMapImage(Image *img);
-
- /**
- * Sets the map proportion (1 means 1 tile to one pixel, .5 means 2 tiles to 1 pixel, etc.)
- */
- void setProportion(float proportion) { mProportion = proportion; }
-
+ void setMap(Map *map);
+
/**
* Toggles the displaying of the minimap.
*/
@@ -65,8 +61,10 @@ class Minimap : public Window
void draw(gcn::Graphics *graphics);
private:
+ Map *mMap;
Image *mMapImage;
- float mProportion;
+ float mWidthProportion;
+ float mHeightProportion;
static bool mShow;
};