diff options
-rw-r--r-- | src/flooritem.cpp | 10 | ||||
-rw-r--r-- | src/item.cpp | 8 | ||||
-rw-r--r-- | src/item.h | 6 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/flooritem.cpp b/src/flooritem.cpp index b2f6376b..9420afb4 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -67,11 +67,11 @@ void FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const { if (mItem) { - if (mAlpha != mItem->getImage()->getAlpha()) - mItem->getImage()->setAlpha(mAlpha); + Image *image = mItem->getDrawImage(); - graphics->drawImage(mItem->getImage(), - mX * 32 + offsetX, - mY * 32 + offsetY); + if (image && mAlpha != image->getAlpha()) + image->setAlpha(mAlpha); + + graphics->drawImage(image, mX * 32 + offsetX, mY * 32 + offsetY); } } diff --git a/src/item.cpp b/src/item.cpp index 46905e5c..120a4044 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -27,6 +27,7 @@ Item::Item(int id, int quantity, bool equipment, bool equipped): mImage(0), + mDrawImage(0), mQuantity(quantity), mEquipment(equipment), mEquipped(equipped), mInEquipment(false) { @@ -50,10 +51,17 @@ void Item::setId(int id) if (mImage) mImage->decRef(); + if (mDrawImage) + mDrawImage->decRef(); + ResourceManager *resman = ResourceManager::getInstance(); std::string imagePath = "graphics/items/" + getInfo().getImageName(); mImage = resman->getImage(imagePath); + mDrawImage = resman->getImage(imagePath); if (!mImage) mImage = resman->getImage("graphics/gui/unknown-item.png"); + + if (!mDrawImage) + mDrawImage = resman->getImage("graphics/gui/unknown-item.png"); } @@ -59,6 +59,11 @@ class Item Image *getImage() { return mImage; } /** + * Returns the item image. + */ + Image *getDrawImage() { return mDrawImage; } + + /** * Sets the number of items. */ void setQuantity(int quantity) { mQuantity = quantity; } @@ -121,6 +126,7 @@ class Item protected: int mId; /**< Item type id. */ Image *mImage; /**< Item image. */ + Image *mDrawImage; /**< Draw image. */ int mQuantity; /**< Number of items. */ bool mEquipment; /**< Item is equipment. */ bool mEquipped; /**< Item is equipped. */ |