summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBertram <bertram@cegetel.net>2010-02-09 02:54:09 +0100
committerBertram <bertram@cegetel.net>2010-02-09 03:20:48 +0100
commit6a6b36fa2d19a6ea9d39b975354709e7ad82281d (patch)
tree09451c98d6a711ffd45a7f5da5796549dbcdd173 /src
parentf3ee70f4aa0b4df7388a4539440355bb066dc0d3 (diff)
downloadmana-client-6a6b36fa2d19a6ea9d39b975354709e7ad82281d.tar.gz
mana-client-6a6b36fa2d19a6ea9d39b975354709e7ad82281d.tar.bz2
mana-client-6a6b36fa2d19a6ea9d39b975354709e7ad82281d.tar.xz
mana-client-6a6b36fa2d19a6ea9d39b975354709e7ad82281d.zip
Pushed away some 32 hardcoded values.
Diffstat (limited to 'src')
-rw-r--r--src/flooritem.cpp3
-rw-r--r--src/flooritem.h3
-rw-r--r--src/gui/debugwindow.cpp25
-rw-r--r--src/gui/viewport.h5
-rw-r--r--src/net/ea/playerhandler.cpp11
-rw-r--r--src/net/manaserv/itemhandler.cpp22
6 files changed, 51 insertions, 18 deletions
diff --git a/src/flooritem.cpp b/src/flooritem.cpp
index db779ad4..2c6d81c4 100644
--- a/src/flooritem.cpp
+++ b/src/flooritem.cpp
@@ -73,6 +73,7 @@ void FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const
if (mAlpha != image->getAlpha())
image->setAlpha(mAlpha);
- graphics->drawImage(image, mX * 32 + offsetX, mY * 32 + offsetY);
+ graphics->drawImage(image, mX * mMap->getTileWidth() + offsetX,
+ mY * mMap->getTileHeight() + offsetY);
}
}
diff --git a/src/flooritem.h b/src/flooritem.h
index d8eaf1e6..0218999e 100644
--- a/src/flooritem.h
+++ b/src/flooritem.h
@@ -85,7 +85,8 @@ class FloorItem : public Sprite
*
* @see Sprite::getPixelY()
*/
- int getPixelY() const { return mY * 32 + 16; }
+ int getPixelY() const
+ { return mY * mMap->getTileHeight() + mMap->getTileHeight() / 2; }
/**
* Draws this floor item to the given graphics context.
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index 874c57a6..9adbc84f 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -86,22 +86,25 @@ void DebugWindow::logic()
if (!isVisible())
return;
- // Get the current mouse position
- int mouseTileX = (viewport->getMouseX() + viewport->getCameraX()) / 32;
- int mouseTileY = (viewport->getMouseY() + viewport->getCameraY()) / 32;
-
mFPSLabel->setCaption(strprintf(mFPSText.c_str(), fps));
- mTileMouseLabel->setCaption(strprintf(_("Cursor: (%d, %d)"),
- mouseTileX,
- mouseTileY));
-
if (const Map *map = Game::instance()->getCurrentMap())
{
+ // Get the current mouse position
+ int mouseTileX = (viewport->getMouseX() + viewport->getCameraX())
+ / map->getTileWidth();
+ int mouseTileY = (viewport->getMouseY() + viewport->getCameraY())
+ / map->getTileHeight();
+ mTileMouseLabel->setCaption(strprintf(_("Cursor: (%d, %d)"),
+ mouseTileX,
+ mouseTileY));
// TODO: Add gettext support below
- mMusicFileLabel->setCaption("Music: " + map->getProperty("music"));
- mMinimapLabel->setCaption("Minimap: " + map->getProperty("minimap"));
- mMapLabel->setCaption("Map: " + map->getProperty("_filename"));
+ mMusicFileLabel->setCaption(strprintf(
+ _("Music: %s"), map->getProperty("music").c_str()));
+ mMinimapLabel->setCaption(
+ strprintf(_("Minimap: %s"), map->getProperty("minimap").c_str()));
+ mMapLabel->setCaption(
+ strprintf(_("Map: %s"), map->getProperty("_filename").c_str()));
}
mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"),
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index 1143297a..5fced324 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -144,6 +144,11 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
*/
void scrollBy(float x, float y) { mPixelViewX += x; mPixelViewY += y; }
+ /**
+ * Returns the current map object.
+ */
+ Map *getCurrentMap() const { return mMap; }
+
private:
/**
* Finds a path from the player to the mouse, and draws it. This is for
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index f6f54d59..33a6b146 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -192,8 +192,8 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
Game *game = Game::instance();
- const std::string &currentMap = game->getCurrentMapName();
- bool sameMap = (currentMap == mapPath);
+ const std::string &currentMapName = game->getCurrentMapName();
+ bool sameMap = (currentMapName == mapPath);
// Switch the actual map, deleting the previous one if necessary
mapPath = mapPath.substr(0, mapPath.rfind("."));
@@ -207,8 +207,11 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
|| (abs(x - player_node->getTileX()) > MAP_TELEPORT_SCROLL_DISTANCE)
|| (abs(y - player_node->getTileY()) > MAP_TELEPORT_SCROLL_DISTANCE))
{
- scrollOffsetX = (x - player_node->getTileX()) * 32;
- scrollOffsetY = (y - player_node->getTileY()) * 32;
+ Map *map = game->getCurrentMap();
+ scrollOffsetX = (x - player_node->getTileX())
+ * map->getTileWidth();
+ scrollOffsetY = (y - player_node->getTileY())
+ * map->getTileHeight();
}
player_node->setAction(Being::STAND);
diff --git a/src/net/manaserv/itemhandler.cpp b/src/net/manaserv/itemhandler.cpp
index 6a9dec74..802f9303 100644
--- a/src/net/manaserv/itemhandler.cpp
+++ b/src/net/manaserv/itemhandler.cpp
@@ -26,6 +26,10 @@
#include "net/manaserv/protocol.h"
#include "net/manaserv/messagein.h"
+#include "game.h"
+#include "map.h"
+#include "log.h"
+
namespace ManaServ {
ItemHandler::ItemHandler()
@@ -54,7 +58,23 @@ void ItemHandler::handleMessage(Net::MessageIn &msg)
if (itemId)
{
- floorItemManager->create(id, itemId, x / 32, y / 32);
+ Game *game = Game::instance();
+ Map *map = 0;
+ if (game)
+ {
+ map = game->getCurrentMap();
+ if (map)
+ {
+ floorItemManager->create(id,
+ itemId,
+ x / map->getTileWidth(),
+ y / map->getTileHeight());
+ }
+ else
+ logger->log(
+ "ItemHandler: An item wasn't created because of"
+ "Game/Map not initialized...");
+ }
}
else if (FloorItem *item = floorItemManager->findById(id))
{