diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-06-12 09:06:01 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-06-12 09:06:01 +0000 |
commit | 2f8ee95fbacb71e7cbca85fcc11e6f9f7e36c258 (patch) | |
tree | 8d256ac1a38932aaf0db7b55ed178e4212616555 /src/item.cpp | |
parent | eb019ab915998a3ec247b33dad4b23f763d7a29a (diff) | |
download | mana-2f8ee95fbacb71e7cbca85fcc11e6f9f7e36c258.tar.gz mana-2f8ee95fbacb71e7cbca85fcc11e6f9f7e36c258.tar.bz2 mana-2f8ee95fbacb71e7cbca85fcc11e6f9f7e36c258.tar.xz mana-2f8ee95fbacb71e7cbca85fcc11e6f9f7e36c258.zip |
Merged revisions 3738 via svnmerge from
https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/trunk
........
r3738 | b_lindeijer | 2007-11-16 00:44:01 +0100 (Fri, 16 Nov 2007) | 3 lines
Moved item icon from ItemInfo class to the Item class, so that it can be loaded
on demand. Results in faster startup time and reduced memory usage.
........
Diffstat (limited to 'src/item.cpp')
-rw-r--r-- | src/item.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/item.cpp b/src/item.cpp index 3cea30e5..e84a06df 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -21,3 +21,38 @@ * $Id$ */ +#include "item.h" + +#include "resources/image.h" +#include "resources/resourcemanager.h" + +Item::Item(int id, int quantity, bool equipment, bool equipped): + mImage(0), + mQuantity(quantity), + mEquipment(equipment), + mEquipped(equipped) +{ + setId(id); +} + +Item::~Item() +{ + if (mImage) + mImage->decRef(); +} + +void Item::setId(int id) +{ + mId = id; + + // Load the associated image + if (mImage) + mImage->decRef(); + + ResourceManager *resman = ResourceManager::getInstance(); + std::string imagePath = "graphics/items/" + getInfo().getImageName(); + mImage = resman->getImage(imagePath); + + if (!mImage) + mImage = resman->getImage("graphics/gui/unknown-item.png"); +} |