summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-11 15:42:53 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-11 15:42:53 +0300
commit50e0557d790ac007c2db63509b7beed6f8d15b1e (patch)
treebbc22a33ab9b392e731b9413c0c195a86e50eb14
parent788f91b8b779a3b99cf4a7f8f53488f45b2edc09 (diff)
downloadplus-50e0557d790ac007c2db63509b7beed6f8d15b1e.tar.gz
plus-50e0557d790ac007c2db63509b7beed6f8d15b1e.tar.bz2
plus-50e0557d790ac007c2db63509b7beed6f8d15b1e.tar.xz
plus-50e0557d790ac007c2db63509b7beed6f8d15b1e.zip
Move mapitem into separate file.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/being/localplayer.cpp1
-rw-r--r--src/gui/popups/popupmenu.cpp1
-rw-r--r--src/gui/viewport.cpp1
-rw-r--r--src/gui/widgets/avatarlistbox.cpp1
-rw-r--r--src/gui/windows/socialwindow.cpp1
-rw-r--r--src/resources/map/map.cpp1
-rw-r--r--src/resources/map/mapitem.cpp169
-rw-r--r--src/resources/map/mapitem.h106
-rw-r--r--src/resources/map/maplayer.cpp138
-rw-r--r--src/resources/map/maplayer.h76
-rw-r--r--src/resources/map/speciallayer.cpp1
-rw-r--r--src/resources/mapreader.cpp1
14 files changed, 288 insertions, 213 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 28f021e56..fecac64a7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -709,6 +709,8 @@ SET(SRCS
resources/map/map.h
resources/map/mapheights.cpp
resources/map/mapheights.h
+ resources/map/mapitem.cpp
+ resources/map/mapitem.h
resources/map/maplayer.cpp
resources/map/maplayer.h
resources/map/mapobject.h
diff --git a/src/Makefile.am b/src/Makefile.am
index b99c2a2e5..f75a6dc67 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -798,6 +798,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
resources/map/map.h \
resources/map/mapheights.cpp \
resources/map/mapheights.h \
+ resources/map/mapitem.cpp \
+ resources/map/mapitem.h \
resources/map/maplayer.cpp \
resources/map/maplayer.h \
resources/map/mapobject.h \
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index f1ab7a126..94edde0ab 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -68,6 +68,7 @@
#include "resources/db/emotedb.h"
#include "resources/db/weaponsdb.h"
+#include "resources/map/mapitem.h"
#include "resources/map/maplayer.h"
#include "resources/map/speciallayer.h"
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
index 00f22a6e8..02feef997 100644
--- a/src/gui/popups/popupmenu.cpp
+++ b/src/gui/popups/popupmenu.cpp
@@ -76,6 +76,7 @@
#include "resources/iteminfo.h"
+#include "resources/map/mapitem.h"
#include "resources/map/maplayer.h"
#include "resources/map/speciallayer.h"
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 792d64b7e..d4e13559a 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -28,6 +28,7 @@
#include "sdlshared.h"
#include "textmanager.h"
+#include "resources/map/mapitem.h"
#include "resources/map/maplayer.h"
#include "resources/map/speciallayer.h"
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 1ff611cab..89fc382d6 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -37,6 +37,7 @@
#include "resources/image.h"
+#include "resources/map/mapitem.h"
#include "resources/map/maplayer.h"
#include "debug.h"
diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp
index 61198b736..1cfc313b5 100644
--- a/src/gui/windows/socialwindow.cpp
+++ b/src/gui/windows/socialwindow.cpp
@@ -27,6 +27,7 @@
#include "guildmanager.h"
#include "party.h"
+#include "resources/map/mapitem.h"
#include "resources/map/maplayer.h"
#include "resources/map/speciallayer.h"
diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp
index d1b1bdb47..9cffaa422 100644
--- a/src/resources/map/map.cpp
+++ b/src/resources/map/map.cpp
@@ -31,6 +31,7 @@
#include "resources/map/mapheights.h"
#include "resources/map/maplayer.h"
+#include "resources/map/mapitem.h"
#include "resources/map/speciallayer.h"
#include "resources/map/tileset.h"
#include "resources/map/walklayer.h"
diff --git a/src/resources/map/mapitem.cpp b/src/resources/map/mapitem.cpp
new file mode 100644
index 000000000..eee82d253
--- /dev/null
+++ b/src/resources/map/mapitem.cpp
@@ -0,0 +1,169 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "resources/map/mapitem.h"
+
+#include "gui/font.h"
+#include "gui/gui.h"
+#include "gui/userpalette.h"
+
+#include "resources/image.h"
+#include "resources/resourcemanager.h"
+
+#include "render/graphics.h"
+
+#include "debug.h"
+
+MapItem::MapItem():
+ mImage(nullptr),
+ mComment(),
+ mName(),
+ mType(EMPTY),
+ mX(-1),
+ mY(-1)
+{
+ setType(EMPTY);
+}
+
+MapItem::MapItem(const int type):
+ mImage(nullptr),
+ mComment(),
+ mName(),
+ mType(type),
+ mX(-1),
+ mY(-1)
+{
+ setType(type);
+}
+
+MapItem::MapItem(const int type, std::string comment):
+ mImage(nullptr),
+ mComment(comment),
+ mName(),
+ mType(type),
+ mX(-1),
+ mY(-1)
+{
+ setType(type);
+}
+
+MapItem::MapItem(const int type, std::string comment,
+ const int x, const int y):
+ mImage(nullptr),
+ mComment(comment),
+ mName(),
+ mType(type),
+ mX(x),
+ mY(y)
+{
+ setType(type);
+}
+
+MapItem::~MapItem()
+{
+ if (mImage)
+ {
+ mImage->decRef();
+ mImage = nullptr;
+ }
+}
+
+void MapItem::setType(const int type)
+{
+ std::string name;
+ mType = type;
+ if (mImage)
+ mImage->decRef();
+
+ switch (type)
+ {
+ case ARROW_UP:
+ name = "graphics/sprites/arrow_up.png";
+ break;
+ case ARROW_DOWN:
+ name = "graphics/sprites/arrow_down.png";
+ break;
+ case ARROW_LEFT:
+ name = "graphics/sprites/arrow_left.png";
+ break;
+ case ARROW_RIGHT:
+ name = "graphics/sprites/arrow_right.png";
+ break;
+ default:
+ break;
+ }
+
+ if (!name.empty())
+ {
+ ResourceManager *const resman = ResourceManager::getInstance();
+ mImage = resman->getImage(name);
+ }
+ else
+ {
+ mImage = nullptr;
+ }
+}
+
+void MapItem::setPos(const int x, const int y)
+{
+ mX = x;
+ mY = y;
+}
+
+void MapItem::draw(Graphics *const graphics, const int x, const int y,
+ const int dx, const int dy) const
+{
+ BLOCK_START("MapItem::draw")
+ if (mImage)
+ graphics->drawImage(mImage, x, y);
+
+ switch (mType)
+ {
+ case ROAD:
+ case CROSS:
+ graphics->setColor(userPalette->getColorWithAlpha(
+ UserPalette::ROAD_POINT));
+ graphics->fillRectangle(Rect(x + dx / 3, y + dy / 3,
+ dx / 3, dy / 3));
+ break;
+ case HOME:
+ {
+ graphics->setColor(userPalette->getColorWithAlpha(
+ UserPalette::HOME_PLACE));
+ graphics->fillRectangle(Rect(x, y, dx, dy));
+ graphics->setColor(userPalette->getColorWithAlpha(
+ UserPalette::HOME_PLACE_BORDER));
+ graphics->drawRectangle(Rect(x, y, dx, dy));
+ break;
+ }
+ default:
+ break;
+ }
+ if (!mName.empty() && mType != PORTAL && mType != EMPTY)
+ {
+ Font *const font = gui->getFont();
+ if (font)
+ {
+ graphics->setColor(userPalette->getColor(UserPalette::BEING));
+ font->drawString(graphics, mName, x, y);
+ }
+ }
+ BLOCK_END("MapItem::draw")
+}
diff --git a/src/resources/map/mapitem.h b/src/resources/map/mapitem.h
new file mode 100644
index 000000000..3e92c536e
--- /dev/null
+++ b/src/resources/map/mapitem.h
@@ -0,0 +1,106 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RESOURCES_MAP_MAPITEM_H
+#define RESOURCES_MAP_MAPITEM_H
+
+#include <string>
+
+#include "localconsts.h"
+
+class Graphics;
+class Image;
+
+class MapItem final
+{
+ public:
+ friend class Map;
+ friend class MapLayer;
+
+ enum ItemType
+ {
+ EMPTY = 0,
+ HOME = 1,
+ ROAD = 2,
+ CROSS = 3,
+ ARROW_UP = 4,
+ ARROW_DOWN = 5,
+ ARROW_LEFT = 6,
+ ARROW_RIGHT = 7,
+ PORTAL = 8,
+ MUSIC = 9,
+ ATTACK = 10,
+ PRIORITY = 11,
+ IGNORE_ = 12,
+ PICKUP = 13,
+ NOPICKUP = 14,
+ SEPARATOR = 15
+ };
+
+ MapItem();
+
+ explicit MapItem(const int type);
+
+ MapItem(const int type, std::string comment);
+
+ MapItem(const int type, std::string comment, const int x, const int y);
+
+ A_DELETE_COPY(MapItem)
+
+ ~MapItem();
+
+ int getType() const A_WARN_UNUSED
+ { return mType; }
+
+ void setType(const int type);
+
+ void setPos(const int x, const int y);
+
+ int getX() const A_WARN_UNUSED
+ { return mX; }
+
+ int getY() const A_WARN_UNUSED
+ { return mY; }
+
+ const std::string &getComment() const A_WARN_UNUSED
+ { return mComment; }
+
+ void setComment(const std::string &comment)
+ { mComment = comment; }
+
+ const std::string &getName() const A_WARN_UNUSED
+ { return mName; }
+
+ void setName(const std::string &name)
+ { mName = name; }
+
+ void draw(Graphics *const graphics, const int x, const int y,
+ const int dx, const int dy) const;
+
+ private:
+ Image *mImage;
+ std::string mComment;
+ std::string mName;
+ int mType;
+ int mX;
+ int mY;
+};
+
+#endif // RESOURCES_MAP_MAPITEM_H
diff --git a/src/resources/map/maplayer.cpp b/src/resources/map/maplayer.cpp
index 05013bf71..e5036676d 100644
--- a/src/resources/map/maplayer.cpp
+++ b/src/resources/map/maplayer.cpp
@@ -36,6 +36,7 @@
#include "resources/image.h"
#include "resources/resourcemanager.h"
+#include "resources/map/mapitem.h"
#include "resources/map/mapobjectlist.h"
#include "resources/map/maprowvertexes.h"
#include "resources/map/speciallayer.h"
@@ -582,143 +583,6 @@ int MapLayer::getTileDrawWidth(const Image *img,
return c;
}
-MapItem::MapItem():
- mImage(nullptr),
- mComment(),
- mName(),
- mType(EMPTY),
- mX(-1),
- mY(-1)
-{
- setType(EMPTY);
-}
-
-MapItem::MapItem(const int type):
- mImage(nullptr),
- mComment(),
- mName(),
- mType(type),
- mX(-1),
- mY(-1)
-{
- setType(type);
-}
-
-MapItem::MapItem(const int type, std::string comment):
- mImage(nullptr),
- mComment(comment),
- mName(),
- mType(type),
- mX(-1),
- mY(-1)
-{
- setType(type);
-}
-
-MapItem::MapItem(const int type, std::string comment,
- const int x, const int y):
- mImage(nullptr),
- mComment(comment),
- mName(),
- mType(type),
- mX(x),
- mY(y)
-{
- setType(type);
-}
-
-MapItem::~MapItem()
-{
- if (mImage)
- {
- mImage->decRef();
- mImage = nullptr;
- }
-}
-
-void MapItem::setType(const int type)
-{
- std::string name;
- mType = type;
- if (mImage)
- mImage->decRef();
-
- switch (type)
- {
- case ARROW_UP:
- name = "graphics/sprites/arrow_up.png";
- break;
- case ARROW_DOWN:
- name = "graphics/sprites/arrow_down.png";
- break;
- case ARROW_LEFT:
- name = "graphics/sprites/arrow_left.png";
- break;
- case ARROW_RIGHT:
- name = "graphics/sprites/arrow_right.png";
- break;
- default:
- break;
- }
-
- if (!name.empty())
- {
- ResourceManager *const resman = ResourceManager::getInstance();
- mImage = resman->getImage(name);
- }
- else
- {
- mImage = nullptr;
- }
-}
-
-void MapItem::setPos(const int x, const int y)
-{
- mX = x;
- mY = y;
-}
-
-void MapItem::draw(Graphics *const graphics, const int x, const int y,
- const int dx, const int dy) const
-{
- BLOCK_START("MapItem::draw")
- if (mImage)
- graphics->drawImage(mImage, x, y);
-
- switch (mType)
- {
- case ROAD:
- case CROSS:
- graphics->setColor(userPalette->getColorWithAlpha(
- UserPalette::ROAD_POINT));
- graphics->fillRectangle(Rect(x + dx / 3, y + dy / 3,
- dx / 3, dy / 3));
- break;
- case HOME:
- {
- graphics->setColor(userPalette->getColorWithAlpha(
- UserPalette::HOME_PLACE));
- graphics->fillRectangle(Rect(x, y, dx, dy));
- graphics->setColor(userPalette->getColorWithAlpha(
- UserPalette::HOME_PLACE_BORDER));
- graphics->drawRectangle(Rect(x, y, dx, dy));
- break;
- }
- default:
- break;
- }
- if (!mName.empty() && mType != PORTAL && mType != EMPTY)
- {
- Font *const font = gui->getFont();
- if (font)
- {
- graphics->setColor(userPalette->getColor(UserPalette::BEING));
- font->drawString(graphics, mName, x, y);
- }
- }
- BLOCK_END("MapItem::draw")
-}
-
ObjectsLayer::ObjectsLayer(const unsigned width, const unsigned height) :
mTiles(new MapObjectList*[width * height]),
mWidth(width),
diff --git a/src/resources/map/maplayer.h b/src/resources/map/maplayer.h
index 653009b40..59e9db2b5 100644
--- a/src/resources/map/maplayer.h
+++ b/src/resources/map/maplayer.h
@@ -37,7 +37,6 @@
class Image;
class ImageVertexes;
-class MapItem;
class MapObjectList;
class MapRowVertexes;
class SpecialLayer;
@@ -158,81 +157,6 @@ class MapLayer final: public ConfigListener
bool mHighlightAttackRange;
};
-class MapItem final
-{
- public:
- friend class Map;
- friend class MapLayer;
-
- enum ItemType
- {
- EMPTY = 0,
- HOME = 1,
- ROAD = 2,
- CROSS = 3,
- ARROW_UP = 4,
- ARROW_DOWN = 5,
- ARROW_LEFT = 6,
- ARROW_RIGHT = 7,
- PORTAL = 8,
- MUSIC = 9,
- ATTACK = 10,
- PRIORITY = 11,
- IGNORE_ = 12,
- PICKUP = 13,
- NOPICKUP = 14,
- SEPARATOR = 15
- };
-
- MapItem();
-
- explicit MapItem(const int type);
-
- MapItem(const int type, std::string comment);
-
- MapItem(const int type, std::string comment, const int x, const int y);
-
- A_DELETE_COPY(MapItem)
-
- ~MapItem();
-
- int getType() const A_WARN_UNUSED
- { return mType; }
-
- void setType(const int type);
-
- void setPos(const int x, const int y);
-
- int getX() const A_WARN_UNUSED
- { return mX; }
-
- int getY() const A_WARN_UNUSED
- { return mY; }
-
- const std::string &getComment() const A_WARN_UNUSED
- { return mComment; }
-
- void setComment(const std::string &comment)
- { mComment = comment; }
-
- const std::string &getName() const A_WARN_UNUSED
- { return mName; }
-
- void setName(const std::string &name)
- { mName = name; }
-
- void draw(Graphics *const graphics, const int x, const int y,
- const int dx, const int dy) const;
-
- private:
- Image *mImage;
- std::string mComment;
- std::string mName;
- int mType;
- int mX;
- int mY;
-};
-
class ObjectsLayer final
{
public:
diff --git a/src/resources/map/speciallayer.cpp b/src/resources/map/speciallayer.cpp
index d87a078de..2ebb6ef51 100644
--- a/src/resources/map/speciallayer.cpp
+++ b/src/resources/map/speciallayer.cpp
@@ -21,6 +21,7 @@
#include "resources/map/speciallayer.h"
#include "resources/map/map.h"
+#include "resources/map/mapitem.h"
#include "resources/map/maplayer.h"
#include "utils/delete2.h"
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 89740db65..3f0cb7343 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -37,6 +37,7 @@
#include "resources/db/mapdb.h"
+#include "resources/map/mapitem.h"
#include "resources/map/tileanimation.h"
#include "utils/base64.h"