diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-02-17 20:33:27 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-02-21 15:47:08 +0100 |
commit | b57e51ff732c93808aa844c511b87decc533237d (patch) | |
tree | 50beae6e97da3e8a655504e42f94e9109dce6129 | |
parent | ffb5fe6236fd9c9e758631c2ea715943018af402 (diff) | |
download | mana-b57e51ff732c93808aa844c511b87decc533237d.tar.gz mana-b57e51ff732c93808aa844c511b87decc533237d.tar.bz2 mana-b57e51ff732c93808aa844c511b87decc533237d.tar.xz mana-b57e51ff732c93808aa844c511b87decc533237d.zip |
Removed ImageSprite
The only use of ImageSprite was for FloorItem instances, which now just
draw the item icon in FloorItem::draw.
This leaves only one Sprite subclass, AnimatedSprite, which means we can
remove the entire virtual Sprite interface.
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/actorsprite.cpp | 22 | ||||
-rw-r--r-- | src/flooritem.cpp | 36 | ||||
-rw-r--r-- | src/flooritem.h | 15 | ||||
-rw-r--r-- | src/gui/widgets/emoteshortcutcontainer.cpp | 2 | ||||
-rw-r--r-- | src/imagesprite.cpp | 39 | ||||
-rw-r--r-- | src/imagesprite.h | 64 |
7 files changed, 44 insertions, 136 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 521d240d..8add7f9a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -443,8 +443,6 @@ set(SRCS guild.h imageparticle.cpp imageparticle.h - imagesprite.cpp - imagesprite.h inventory.cpp inventory.h item.cpp diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index f2c9ac88..444696c6 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -23,14 +23,12 @@ #include "animatedsprite.h" #include "configuration.h" #include "event.h" -#include "imagesprite.h" #include "localplayer.h" #include "log.h" #include "particle.h" #include "simpleanimation.h" #include "resources/animation.h" -#include "resources/image.h" #include "resources/imageset.h" #include "resources/resourcemanager.h" #include "resources/theme.h" @@ -142,24 +140,8 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, // Ensure that something is shown, if desired if (mSprites.size() == 0 && forceDisplay) { - if (display.image.empty()) - { - mSprites.add(AnimatedSprite::load(paths.getStringValue("sprites") - + paths.getStringValue("spriteErrorFile"))); - } - else - { - ResourceManager *resman = ResourceManager::getInstance(); - std::string imagePath = paths.getStringValue("itemIcons") - + display.image; - Image *img = resman->getImage(imagePath); - - if (!img) - img = Theme::getImageFromTheme( - paths.getStringValue("unknownItemFile")); - - mSprites.add(new ImageSprite(img)); - } + mSprites.add(AnimatedSprite::load(paths.getStringValue("sprites") + + paths.getStringValue("spriteErrorFile"))); } mChildParticleEffects.clear(); diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 15975687..330936ec 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -21,8 +21,13 @@ #include "flooritem.h" +#include "configuration.h" + +#include "resources/image.h" #include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "resources/resourcemanager.h" +#include "resources/theme.h" FloorItem::FloorItem(int id, int itemId, @@ -39,7 +44,36 @@ FloorItem::FloorItem(int id, mX = (int)position.x / map->getTileWidth(); mY = (int)position.y / map->getTileHeight(); - setupSpriteDisplay(itemDb->get(itemId).display); + // Set up sprites and particle effects + auto &info = getInfo(); + setupSpriteDisplay(info.display, false); + + // If no sprites are defined, fall back to the item icon + if (info.display.sprites.empty()) + { + ResourceManager *resman = ResourceManager::getInstance(); + std::string imagePath = paths.getStringValue("itemIcons") + info.display.image; + + mImage = resman->getImageRef(imagePath); + if (!mImage) + { + imagePath = Theme::resolveThemePath(paths.getStringValue("unknownItemFile")); + mImage = resman->getImageRef(imagePath); + } + } +} + +bool FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const +{ + if (mImage) + { + mImage->setAlpha(getAlpha()); + return graphics->drawImage(mImage, + getPixelX() + offsetX - mImage->getWidth() / 2, + getPixelY() + offsetY - mImage->getHeight() / 2); + } + + return ActorSprite::draw(graphics, offsetX, offsetY); } const ItemInfo &FloorItem::getInfo() const diff --git a/src/flooritem.h b/src/flooritem.h index 82693861..909d6195 100644 --- a/src/flooritem.h +++ b/src/flooritem.h @@ -28,7 +28,7 @@ class ItemInfo; /** * An item lying on the floor. */ -class FloorItem : public ActorSprite +class FloorItem final : public ActorSprite { public: /** @@ -46,11 +46,12 @@ class FloorItem : public ActorSprite Type getType() const override { return FLOOR_ITEM; } + bool draw(Graphics *graphics, int offsetX, int offsetY) const override; + /** * Returns the item ID. */ - int getItemId() const - { return mItemId; } + int getItemId() const { return mItemId; } /** * Returns the item info for this floor item. Useful for adding an item @@ -58,13 +59,11 @@ class FloorItem : public ActorSprite */ const ItemInfo &getInfo() const; - int getTileX() const override - { return mX; } - - int getTileY() const override - { return mY; } + int getTileX() const override { return mX; } + int getTileY() const override { return mY; } private: int mItemId; int mX, mY; + ResourceRef<Image> mImage; }; diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index d80cbb53..812377e9 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -24,7 +24,6 @@ #include "configuration.h" #include "emoteshortcut.h" #include "graphics.h" -#include "imagesprite.h" #include "item.h" #include "keyboardconfig.h" @@ -177,4 +176,3 @@ void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event) mEmoteClicked = false; } } - diff --git a/src/imagesprite.cpp b/src/imagesprite.cpp deleted file mode 100644 index 9ef27cd1..00000000 --- a/src/imagesprite.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2010-2012 The Mana Developers - * - * This file is part of The Mana 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 "imagesprite.h" - -#include "graphics.h" - -ImageSprite::ImageSprite(Image *image): - mImage(image) -{ - mAlpha = mImage->getAlpha(); -} - -ImageSprite::~ImageSprite() = default; - -bool ImageSprite::draw(Graphics *graphics, int posX, int posY) const -{ - if (mImage->getAlpha() != mAlpha) - mImage->setAlpha(mAlpha); - - return graphics->drawImage(mImage, posX, posY); -} diff --git a/src/imagesprite.h b/src/imagesprite.h deleted file mode 100644 index f66628ce..00000000 --- a/src/imagesprite.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2010-2012 The Mana Developers - * - * This file is part of The Mana 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/>. - */ - -#pragma once - -#include "sprite.h" - -#include "resources/image.h" - -class Graphics; - -class ImageSprite final : public Sprite -{ -public: - ImageSprite(Image *image); - - ~ImageSprite() override; - - bool reset() override - { return false; } - - bool play(const std::string &action) override - { return false; } - - bool update(int time) override - { return false; } - - bool draw(Graphics *graphics, int posX, int posY) const override; - - int getWidth() const override - { return mImage->getWidth(); } - - int getHeight() const override - { return mImage->getHeight(); } - - const Image *getImage() const override - { return mImage; } - - bool setDirection(SpriteDirection direction) override - { return false; } - - int getDuration() const override - { return 0; } - -private: - ResourceRef<Image> mImage; -}; |