From 9b072c42f4508de8fb15d1fc8b59931777d5b5a7 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 29 Dec 2015 01:48:21 +0300 Subject: Move item into item directory. --- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/actions/commands.cpp | 3 +- src/being/localplayer.cpp | 3 +- src/being/playerinfo.cpp | 3 +- src/beingequipbackend.cpp | 4 +- src/dragdrop.h | 3 +- src/flooritem.cpp | 3 +- src/gui/popups/itempopup.cpp | 3 +- src/gui/popups/popupmenu.cpp | 3 +- src/gui/shortcut/dropshortcut.cpp | 3 +- src/gui/shortcut/itemshortcut.cpp | 5 +- src/gui/shortcut/shortcutbase.cpp | 3 +- src/gui/windows/inventorywindow.cpp | 3 +- src/gui/windows/itemamountwindow.cpp | 4 +- src/gui/windows/maileditwindow.cpp | 7 +- src/gui/windows/npcdialog.cpp | 3 +- src/gui/windows/statuswindow.cpp | 3 +- src/gui/windows/tradewindow.cpp | 3 +- src/inventory.cpp | 3 +- src/item.cpp | 182 ------------------------- src/item.h | 249 ----------------------------------- src/itemsoundmanager.cpp | 3 +- src/net/ea/buysellrecv.cpp | 3 +- src/net/ea/equipbackend.h | 2 +- src/net/eathena/auctionhandler.cpp | 4 +- src/net/eathena/buyingstorerecv.cpp | 3 +- src/net/eathena/inventoryhandler.cpp | 4 +- src/net/eathena/tradehandler.cpp | 4 +- src/net/eathena/traderecv.cpp | 3 +- src/net/tmwa/inventoryhandler.cpp | 4 +- src/net/tmwa/tradehandler.cpp | 4 +- src/net/tmwa/traderecv.cpp | 3 +- src/resources/item/item.cpp | 182 +++++++++++++++++++++++++ src/resources/item/item.h | 249 +++++++++++++++++++++++++++++++++++ src/shopitem.h | 2 +- 36 files changed, 496 insertions(+), 475 deletions(-) delete mode 100644 src/item.cpp delete mode 100644 src/item.h create mode 100644 src/resources/item/item.cpp create mode 100644 src/resources/item/item.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cbb406211..08df3344a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -948,8 +948,8 @@ SET(SRCS resources/sprite/imagesprite.h inventory.cpp inventory.h - item.cpp - item.h + resources/item/item.cpp + resources/item/item.h itemcolormanager.cpp itemcolormanager.h gui/shortcut/itemshortcut.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 83d5ec41a..02310a8e5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -712,8 +712,8 @@ manaplus_SOURCES += main.cpp \ inventory.h \ textcommand.cpp \ textcommand.h \ - item.cpp \ - item.h \ + resources/item/item.cpp \ + resources/item/item.h \ itemcolormanager.cpp \ itemcolormanager.h \ gui/shortcut/itemshortcut.cpp \ diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index 3511e9808..ba793f866 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -24,7 +24,6 @@ #include "configuration.h" #include "game.h" #include "inventory.h" -#include "item.h" #include "party.h" #include "actions/actiondef.h" @@ -64,6 +63,8 @@ #include "resources/iteminfo.h" #include "resources/chatobject.h" +#include "resources/item/item.h" + #include "utils/chatutils.h" #include "utils/gettext.h" #include "utils/process.h" diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 9944a6eb4..a7fdfca82 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -26,7 +26,6 @@ #include "configuration.h" #include "gamemodifiers.h" #include "guild.h" -#include "item.h" #include "party.h" #include "settings.h" #include "soundmanager.h" @@ -74,6 +73,8 @@ #include "resources/db/weaponsdb.h" +#include "resources/item/item.h" + #include "resources/map/map.h" #include "resources/map/mapitem.h" #include "resources/map/speciallayer.h" diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 76ccdcce4..fea36d893 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -22,7 +22,6 @@ #include "being/playerinfo.h" #include "configuration.h" -#include "item.h" #include "itemsoundmanager.h" #include "being/localplayer.h" @@ -45,6 +44,8 @@ #include "resources/itemtype.h" #endif +#include "resources/item/item.h" + #include "utils/delete2.h" #include "debug.h" diff --git a/src/beingequipbackend.cpp b/src/beingequipbackend.cpp index e732e72c4..43f03e67f 100644 --- a/src/beingequipbackend.cpp +++ b/src/beingequipbackend.cpp @@ -20,12 +20,12 @@ #include "beingequipbackend.h" -#include "item.h" - #include "being/being.h" #include "net/inventoryhandler.h" +#include "resources/item/item.h" + #include "utils/delete2.h" #include "debug.h" diff --git a/src/dragdrop.h b/src/dragdrop.h index 97f978ee2..88e6df736 100644 --- a/src/dragdrop.h +++ b/src/dragdrop.h @@ -21,7 +21,8 @@ #ifndef DRAGDROP_H #define DRAGDROP_H -#include "item.h" +#include "resources/item/item.h" + #include "itemsoundmanager.h" #include "textcommand.h" diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 25222229f..49a64ff43 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -23,7 +23,6 @@ #include "flooritem.h" #include "configuration.h" -#include "item.h" #include "render/graphics.h" @@ -34,6 +33,8 @@ #include "resources/iteminfo.h" +#include "resources/item/item.h" + #include "resources/map/map.h" #include "net/serverfeatures.h" diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp index 51f1e8108..806c8e89f 100644 --- a/src/gui/popups/itempopup.cpp +++ b/src/gui/popups/itempopup.cpp @@ -25,7 +25,6 @@ #include "actormanager.h" #include "configuration.h" -#include "item.h" #include "units.h" #include "gui/gui.h" @@ -42,6 +41,8 @@ #include "resources/iteminfo.h" #include "resources/resourcemanager.h" +#include "resources/item/item.h" + #include "net/beinghandler.h" #include "net/serverfeatures.h" diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index eba6f1ee9..b14e3f32c 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -25,7 +25,6 @@ #include "actormanager.h" #include "configuration.h" #include "gamemodifiers.h" -#include "item.h" #include "party.h" #include "being/localplayer.h" @@ -85,6 +84,8 @@ #include "resources/db/npcdb.h" +#include "resources/item/item.h" + #include "resources/map/map.h" #include "resources/map/mapitem.h" #include "resources/map/speciallayer.h" diff --git a/src/gui/shortcut/dropshortcut.cpp b/src/gui/shortcut/dropshortcut.cpp index e9264e9c3..66fcd0dfa 100644 --- a/src/gui/shortcut/dropshortcut.cpp +++ b/src/gui/shortcut/dropshortcut.cpp @@ -23,12 +23,13 @@ #include "gui/shortcut/dropshortcut.h" #include "inventory.h" -#include "item.h" #include "settings.h" #include "being/localplayer.h" #include "being/playerinfo.h" +#include "resources/item/item.h" + #include "net/packetlimiter.h" #include "debug.h" diff --git a/src/gui/shortcut/itemshortcut.cpp b/src/gui/shortcut/itemshortcut.cpp index 7d6aec8f1..ab7e898f6 100644 --- a/src/gui/shortcut/itemshortcut.cpp +++ b/src/gui/shortcut/itemshortcut.cpp @@ -24,16 +24,17 @@ #include "configuration.h" #include "inventory.h" -#include "item.h" #include "spellmanager.h" #include "being/playerinfo.h" #include "const/spells.h" +#include "const/resources/skill.h" + #include "gui/windows/skilldialog.h" -#include "const/resources/skill.h" +#include "resources/item/item.h" #include "debug.h" diff --git a/src/gui/shortcut/shortcutbase.cpp b/src/gui/shortcut/shortcutbase.cpp index 99eb492f1..9e5a4be61 100644 --- a/src/gui/shortcut/shortcutbase.cpp +++ b/src/gui/shortcut/shortcutbase.cpp @@ -23,7 +23,8 @@ #include "gui/shortcut/shortcutbase.h" #include "configuration.h" -#include "item.h" + +#include "resources/item/item.h" #include "debug.h" diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index 4770ef69a..71c09d723 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -23,7 +23,6 @@ #include "gui/windows/inventorywindow.h" #include "configuration.h" -#include "item.h" #include "units.h" #include "being/playerinfo.h" @@ -62,6 +61,8 @@ #include "resources/iteminfo.h" +#include "resources/item/item.h" + #include "utils/delete2.h" #include "debug.h" diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp index fba671675..08227e19e 100644 --- a/src/gui/windows/itemamountwindow.cpp +++ b/src/gui/windows/itemamountwindow.cpp @@ -22,8 +22,6 @@ #include "gui/windows/itemamountwindow.h" -#include "item.h" - #include "being/playerinfo.h" #include "input/keyboardconfig.h" @@ -48,6 +46,8 @@ #include "gui/widgets/label.h" #include "gui/widgets/slider.h" +#include "resources/item/item.h" + #include "utils/gettext.h" #include diff --git a/src/gui/windows/maileditwindow.cpp b/src/gui/windows/maileditwindow.cpp index da7210a43..1030e41ae 100644 --- a/src/gui/windows/maileditwindow.cpp +++ b/src/gui/windows/maileditwindow.cpp @@ -20,10 +20,7 @@ #include "gui/windows/maileditwindow.h" -#include "item.h" - #include "being/playerinfo.h" -#include "net/mailhandler.h" #include "gui/windows/inventorywindow.h" #include "gui/windows/itemamountwindow.h" @@ -35,6 +32,10 @@ #include "gui/widgets/label.h" #include "gui/widgets/scrollarea.h" +#include "resources/item/item.h" + +#include "net/mailhandler.h" + #include "utils/delete2.h" #include "utils/gettext.h" diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 9cdf6a3b0..28ede67e6 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -24,7 +24,6 @@ #include "actormanager.h" #include "configuration.h" -#include "item.h" #include "settings.h" #include "soundmanager.h" @@ -62,6 +61,8 @@ #include "resources/db/npcdb.h" #include "resources/db/npcdialogdb.h" +#include "resources/item/item.h" + #include "net/npchandler.h" #include "net/packetlimiter.h" diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp index 6ac5b34dc..11a0a2f41 100644 --- a/src/gui/windows/statuswindow.cpp +++ b/src/gui/windows/statuswindow.cpp @@ -24,7 +24,6 @@ #include "configuration.h" #include "gamemodifiers.h" -#include "item.h" #include "settings.h" #include "units.h" @@ -49,6 +48,8 @@ #include "net/inventoryhandler.h" #include "net/playerhandler.h" +#include "resources/item/item.h" + #include "utils/delete2.h" #include "utils/gettext.h" diff --git a/src/gui/windows/tradewindow.cpp b/src/gui/windows/tradewindow.cpp index 69cf87848..68c779148 100644 --- a/src/gui/windows/tradewindow.cpp +++ b/src/gui/windows/tradewindow.cpp @@ -24,7 +24,6 @@ #include "configuration.h" #include "game.h" -#include "item.h" #include "units.h" #include "being/localplayer.h" @@ -50,6 +49,8 @@ #include "gui/widgets/tabs/chat/chattab.h" +#include "resources/item/item.h" + #include "net/tradehandler.h" #include "utils/delete2.h" diff --git a/src/inventory.cpp b/src/inventory.cpp index 500e8c207..d1b04555b 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -22,7 +22,6 @@ #include "inventory.h" -#include "item.h" #include "logger.h" #include "being/playerinfo.h" @@ -31,6 +30,8 @@ #include "resources/iteminfo.h" +#include "resources/item/item.h" + #include "listeners/inventorylistener.h" #include "utils/delete2.h" diff --git a/src/item.cpp b/src/item.cpp deleted file mode 100644 index 721c8115b..000000000 --- a/src/item.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2015 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 . - */ - -#include "item.h" - -#include "configuration.h" -#include "dragdrop.h" -#include "itemcolormanager.h" - -#include "gui/theme.h" - -#include "resources/iteminfo.h" -#include "resources/resourcemanager.h" - -#include "net/serverfeatures.h" - -#include "debug.h" - -DragDrop dragDrop(nullptr, DragDropSource::Empty); - -Item::Item(const int id, - const int type, - const int quantity, - const uint8_t refine, - const ItemColor color, - const Identified identified, - const Damaged damaged, - const Favorite favorite, - const Equipm equipment, - const Equipped equipped) : - mId(0), - mColor(ItemColor_zero), - mQuantity(quantity), - mTag(0), - mImage(nullptr), - mDescription(), - mTags(), - mCards(), - mRefine(refine), - mInvIndex(0), - mType(type), - mEquipment(equipment), - mEquipped(equipped), - mInEquipment(false), - mIdentified(identified), - mDamaged(damaged), - mFavorite(favorite) -{ - setId(id, color); - for (int f = 0; f < 4; f ++) - mCards[f] = 0; -} - -Item::~Item() -{ - if (mImage) - { - mImage->decRef(); - mImage = nullptr; - } - dragDrop.clearItem(this); -} - -void Item::setId(const int id, - const ItemColor color) -{ - mId = id; - mColor = color; - - // Types 0 and 1 are not equippable items. - mEquipment = fromBool(id && static_cast(getInfo().getType()) - >= 2, Equipm); - - if (mImage) - mImage->decRef(); - - const ItemInfo &info = getInfo(); - mTags = info.getTags(); - - const std::string dye = combineDye2(paths.getStringValue( - "itemIcons").append(info.getDisplay().image), - info.getDyeIconColorsString(color)); - mImage = resourceManager->getImage(dye); - - if (!mImage) - { - mImage = Theme::getImageFromTheme(paths.getValue("unknownItemFile", - "unknown-item.png")); - } -} - -bool Item::isHaveTag(const int tagId) const -{ - const std::map ::const_iterator it = mTags.find(tagId); - if (it == mTags.end()) - return false; - return (*it).second > 0; -} - -Image *Item::getImage(const int id, - const ItemColor color) -{ - const ItemInfo &info = ItemDB::get(id); - Image *image = resourceManager->getImage(combineDye2(paths.getStringValue( - "itemIcons").append(info.getDisplay().image), - info.getDyeIconColorsString(color))); - - if (!image) - image = Theme::getImageFromTheme("unknown-item.png"); - return image; -} - -std::string Item::getName() const -{ - const ItemInfo &info = ItemDB::get(mId); - if (serverFeatures->haveItemColors()) - return info.getName(mColor); - else - return info.getName(); -} - -void Item::setCard(const int index, const int id) -{ - if (index < 0 || index >= maxCards) - return; - mCards[index] = id; -} - -int Item::getCard(const int index) const -{ - if (index < 0 || index >= maxCards) - return 0; - return mCards[index]; -} - -void Item::setCards(const int *const cards, const int size) -{ - if (size < 0 || !cards) - return; - int sz = size; - if (sz > maxCards) - sz = maxCards; - for (int f = 0; f < sz; f ++) - mCards[f] = cards[f]; -} - -void Item::addCard(const int card) -{ - for (int f = 0; f < maxCards; f ++) - { - if (!mCards[f]) - { - mCards[f] = card; - return; - } - } -} - -void Item::updateColor() -{ - if (serverFeatures && serverFeatures->haveItemColors()) - setId(mId, ItemColorManager::getColorFromCards(&mCards[0])); -} diff --git a/src/item.h b/src/item.h deleted file mode 100644 index 50f6d3fbd..000000000 --- a/src/item.h +++ /dev/null @@ -1,249 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2015 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 . - */ - -#ifndef ITEM_H -#define ITEM_H - -#include "enums/simpletypes/damaged.h" -#include "enums/simpletypes/equipm.h" -#include "enums/simpletypes/equipped.h" -#include "enums/simpletypes/favorite.h" -#include "enums/simpletypes/identified.h" -#include "enums/simpletypes/itemcolor.h" - -#include "resources/db/itemdb.h" - -#include "localconsts.h" - -class Image; - -const int maxCards = 4; - -/** - * Represents one or more instances of a certain item type. - */ -class Item notfinal -{ - public: - /** - * Constructor. - */ - Item(const int id, - const int type, - const int quantity, - const uint8_t refine, - const ItemColor color, - const Identified identified, - const Damaged damaged, - const Favorite favorite, - const Equipm equipment, - const Equipped equipped); - - A_DELETE_COPY(Item) - - /** - * Destructor. - */ - virtual ~Item(); - - /** - * Sets the item id, color the item type. - */ - void setId(const int id, const ItemColor color); - - /** - * Returns the item id. - */ - int getId() const A_WARN_UNUSED - { return mId; } - - /** - * Returns the item image. - */ - Image *getImage() const A_WARN_UNUSED - { return mImage; } - - /** - * Sets the number of items. - */ - void setQuantity(const int quantity) - { mQuantity = quantity; } - - /** - * Increases the number of items by the given amount. - */ - void increaseQuantity(const int amount) - { mQuantity += amount; } - - /** - * Returns the number of items. - */ - int getQuantity() const A_WARN_UNUSED - { return mQuantity; } - - /** - * Sets whether this item is considered equipment. - */ - void setEquipment(const Equipm equipment) - { mEquipment = equipment; } - - /** - * Returns whether this item is considered equipment. - */ - Equipm isEquipment() const A_WARN_UNUSED - { return mEquipment; } - - /** - * Sets whether this item is equipped. - */ - void setEquipped(const Equipped equipped) - { mEquipped = equipped; } - - /** - * Returns whether this item is equipped. - */ - Equipped isEquipped() const A_WARN_UNUSED - { return mEquipped; } - - /** - * Sets this item refine level. - */ - void setRefine(const uint8_t refine) - { mRefine = refine; } - - /** - * Returns this item refine level. - */ - uint8_t getRefine() const A_WARN_UNUSED - { return mRefine; } - - /** - * Sets whether this item is in equipment. - */ - void setInEquipment(const bool inEquipment) - { mInEquipment = inEquipment; } - - /** - * Returns whether this item is in equipment. - */ - bool isInEquipment() const A_WARN_UNUSED - { return mInEquipment; } - - /** - * Sets the inventory index of this item. - */ - void setInvIndex(const int index) - { mInvIndex = index; } - - /** - * Returns the inventory index of this item. - */ - int getInvIndex() const A_WARN_UNUSED - { return mInvIndex; } - - /** - * Returns information about this item type. - */ - const ItemInfo &getInfo() const A_WARN_UNUSED - { return ItemDB::get(mId); } - - std::string getName() const A_WARN_UNUSED; - - static Image *getImage(const int id, - const ItemColor color) A_WARN_UNUSED; - - bool isHaveTag(const int tagId) const A_WARN_UNUSED; - - ItemColor getColor() const A_WARN_UNUSED - { return mColor; } - - void setColor(const ItemColor color) - { mColor = color; } - - const std::string &getDescription() const A_WARN_UNUSED - { return mDescription; } - - void setIdentified(const Identified b) - { mIdentified = b; } - - Identified getIdentified() const A_WARN_UNUSED - { return mIdentified; } - - void setDamaged(const Damaged b) - { mDamaged = b; } - - Damaged getDamaged() const A_WARN_UNUSED - { return mDamaged; } - - void setFavorite(const Favorite b) - { mFavorite = b; } - - Favorite getFavorite() const A_WARN_UNUSED - { return mFavorite; } - - void setCard(const int index, const int id); - - int getCard(const int index) const; - - void setCards(const int *const cards, const int size); - - const int *getCards() const - { return mCards; } - - void setType(const int type) - { mType = type; } - - int getType() const A_WARN_UNUSED - { return mType; } - - void setTag(const int tag) - { mTag = tag; } - - int getTag() const A_WARN_UNUSED - { return mTag; } - - void addCard(const int card); - - void updateColor(); - - int mId; /**< Item type id. */ - ItemColor mColor; - int mQuantity; /**< Number of items. */ - int mTag; - - protected: - Image *mImage; /**< Item image. */ - std::string mDescription; - std::map mTags; - int mCards[maxCards]; - uint8_t mRefine; /**< Item refine level. */ - int mInvIndex; /**< Inventory index. */ - int mType; /**< Item type. */ - Equipm mEquipment; /**< Item is equipment. */ - Equipped mEquipped; /**< Item is equipped. */ - bool mInEquipment; /**< Item is in equipment */ - Identified mIdentified; - Damaged mDamaged; - Favorite mFavorite; -}; - -#endif // ITEM_H diff --git a/src/itemsoundmanager.cpp b/src/itemsoundmanager.cpp index 36238274f..6c3bb0a85 100644 --- a/src/itemsoundmanager.cpp +++ b/src/itemsoundmanager.cpp @@ -21,13 +21,14 @@ #include "itemsoundmanager.h" #include "flooritem.h" -#include "item.h" #include "soundmanager.h" #include "being/localplayer.h" #include "resources/iteminfo.h" +#include "resources/item/item.h" + #include "debug.h" void ItemSoundManager::playSfx(const Item *const item, diff --git a/src/net/ea/buysellrecv.cpp b/src/net/ea/buysellrecv.cpp index 8ec0e86b0..795ec5a33 100644 --- a/src/net/ea/buysellrecv.cpp +++ b/src/net/ea/buysellrecv.cpp @@ -23,7 +23,6 @@ #include "net/ea/buysellrecv.h" #include "inventory.h" -#include "item.h" #include "notifymanager.h" #include "being/playerinfo.h" @@ -40,6 +39,8 @@ #include "net/messagein.h" +#include "resources/item/item.h" + #include "debug.h" namespace Ea diff --git a/src/net/ea/equipbackend.h b/src/net/ea/equipbackend.h index 673708aa6..67985dbea 100644 --- a/src/net/ea/equipbackend.h +++ b/src/net/ea/equipbackend.h @@ -23,7 +23,7 @@ #ifndef NET_EA_EQUIPBACKEND_H #define NET_EA_EQUIPBACKEND_H -#include "item.h" +#include "resources/item/item.h" #include "being/playerinfo.h" diff --git a/src/net/eathena/auctionhandler.cpp b/src/net/eathena/auctionhandler.cpp index 02e903929..2ecc6d90f 100644 --- a/src/net/eathena/auctionhandler.cpp +++ b/src/net/eathena/auctionhandler.cpp @@ -20,13 +20,13 @@ #include "net/eathena/auctionhandler.h" -#include "item.h" - #include "const/net/inventory.h" #include "net/eathena/messageout.h" #include "net/eathena/protocolout.h" +#include "resources/item/item.h" + #include "debug.h" extern Net::AuctionHandler *auctionHandler; diff --git a/src/net/eathena/buyingstorerecv.cpp b/src/net/eathena/buyingstorerecv.cpp index 13054c2c3..78cbce318 100644 --- a/src/net/eathena/buyingstorerecv.cpp +++ b/src/net/eathena/buyingstorerecv.cpp @@ -22,7 +22,6 @@ #include "actormanager.h" #include "inventory.h" -#include "item.h" #include "notifymanager.h" #include "being/localplayer.h" @@ -42,6 +41,8 @@ #include "net/messagein.h" +#include "resources/item/item.h" + #include "debug.h" namespace EAthena diff --git a/src/net/eathena/inventoryhandler.cpp b/src/net/eathena/inventoryhandler.cpp index 706d286f1..96bc36043 100644 --- a/src/net/eathena/inventoryhandler.cpp +++ b/src/net/eathena/inventoryhandler.cpp @@ -22,8 +22,6 @@ #include "net/eathena/inventoryhandler.h" -#include "item.h" - #include "const/net/inventory.h" #include "enums/equipslot.h" @@ -33,6 +31,8 @@ #include "net/eathena/messageout.h" #include "net/eathena/protocolout.h" +#include "resources/item/item.h" + #include "debug.h" extern Net::InventoryHandler *inventoryHandler; diff --git a/src/net/eathena/tradehandler.cpp b/src/net/eathena/tradehandler.cpp index 6c3026e7b..cd811e199 100644 --- a/src/net/eathena/tradehandler.cpp +++ b/src/net/eathena/tradehandler.cpp @@ -22,8 +22,6 @@ #include "net/eathena/tradehandler.h" -#include "item.h" - #include "being/playerinfo.h" #include "const/net/inventory.h" @@ -32,6 +30,8 @@ #include "net/eathena/protocolout.h" #include "net/eathena/traderecv.h" +#include "resources/item/item.h" + #include "debug.h" extern Net::TradeHandler *tradeHandler; diff --git a/src/net/eathena/traderecv.cpp b/src/net/eathena/traderecv.cpp index bae158aa7..4b6cbf237 100644 --- a/src/net/eathena/traderecv.cpp +++ b/src/net/eathena/traderecv.cpp @@ -23,7 +23,6 @@ #include "net/eathena/traderecv.h" #include "inventory.h" -#include "item.h" #include "itemcolormanager.h" #include "notifymanager.h" @@ -37,6 +36,8 @@ #include "net/ea/traderecv.h" +#include "resources/item/item.h" + #include "debug.h" extern int packetVersion; diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index ea4d27804..0df6c9cf1 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -22,8 +22,6 @@ #include "net/tmwa/inventoryhandler.h" -#include "item.h" - #include "const/net/inventory.h" #include "enums/equipslot.h" @@ -31,6 +29,8 @@ #include "net/tmwa/messageout.h" #include "net/tmwa/protocolout.h" +#include "resources/item/item.h" + #include "debug.h" extern Net::InventoryHandler *inventoryHandler; diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index ebdd56fb6..7449b3555 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -22,8 +22,6 @@ #include "net/tmwa/tradehandler.h" -#include "item.h" - #include "being/playerinfo.h" #include "const/net/inventory.h" @@ -31,6 +29,8 @@ #include "net/tmwa/messageout.h" #include "net/tmwa/protocolout.h" +#include "resources/item/item.h" + #include "debug.h" extern Net::TradeHandler *tradeHandler; diff --git a/src/net/tmwa/traderecv.cpp b/src/net/tmwa/traderecv.cpp index db27d7800..59250122d 100644 --- a/src/net/tmwa/traderecv.cpp +++ b/src/net/tmwa/traderecv.cpp @@ -23,7 +23,6 @@ #include "net/tmwa/traderecv.h" #include "inventory.h" -#include "item.h" #include "notifymanager.h" #include "being/playerinfo.h" @@ -41,6 +40,8 @@ #include "net/ea/traderecv.h" +#include "resources/item/item.h" + #include "utils/stringutils.h" #include "debug.h" diff --git a/src/resources/item/item.cpp b/src/resources/item/item.cpp new file mode 100644 index 000000000..2292a66eb --- /dev/null +++ b/src/resources/item/item.cpp @@ -0,0 +1,182 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2015 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 . + */ + +#include "resources/item/item.h" + +#include "configuration.h" +#include "dragdrop.h" +#include "itemcolormanager.h" + +#include "gui/theme.h" + +#include "resources/iteminfo.h" +#include "resources/resourcemanager.h" + +#include "net/serverfeatures.h" + +#include "debug.h" + +DragDrop dragDrop(nullptr, DragDropSource::Empty); + +Item::Item(const int id, + const int type, + const int quantity, + const uint8_t refine, + const ItemColor color, + const Identified identified, + const Damaged damaged, + const Favorite favorite, + const Equipm equipment, + const Equipped equipped) : + mId(0), + mColor(ItemColor_zero), + mQuantity(quantity), + mTag(0), + mImage(nullptr), + mDescription(), + mTags(), + mCards(), + mRefine(refine), + mInvIndex(0), + mType(type), + mEquipment(equipment), + mEquipped(equipped), + mInEquipment(false), + mIdentified(identified), + mDamaged(damaged), + mFavorite(favorite) +{ + setId(id, color); + for (int f = 0; f < 4; f ++) + mCards[f] = 0; +} + +Item::~Item() +{ + if (mImage) + { + mImage->decRef(); + mImage = nullptr; + } + dragDrop.clearItem(this); +} + +void Item::setId(const int id, + const ItemColor color) +{ + mId = id; + mColor = color; + + // Types 0 and 1 are not equippable items. + mEquipment = fromBool(id && static_cast(getInfo().getType()) + >= 2, Equipm); + + if (mImage) + mImage->decRef(); + + const ItemInfo &info = getInfo(); + mTags = info.getTags(); + + const std::string dye = combineDye2(paths.getStringValue( + "itemIcons").append(info.getDisplay().image), + info.getDyeIconColorsString(color)); + mImage = resourceManager->getImage(dye); + + if (!mImage) + { + mImage = Theme::getImageFromTheme(paths.getValue("unknownItemFile", + "unknown-item.png")); + } +} + +bool Item::isHaveTag(const int tagId) const +{ + const std::map ::const_iterator it = mTags.find(tagId); + if (it == mTags.end()) + return false; + return (*it).second > 0; +} + +Image *Item::getImage(const int id, + const ItemColor color) +{ + const ItemInfo &info = ItemDB::get(id); + Image *image = resourceManager->getImage(combineDye2(paths.getStringValue( + "itemIcons").append(info.getDisplay().image), + info.getDyeIconColorsString(color))); + + if (!image) + image = Theme::getImageFromTheme("unknown-item.png"); + return image; +} + +std::string Item::getName() const +{ + const ItemInfo &info = ItemDB::get(mId); + if (serverFeatures->haveItemColors()) + return info.getName(mColor); + else + return info.getName(); +} + +void Item::setCard(const int index, const int id) +{ + if (index < 0 || index >= maxCards) + return; + mCards[index] = id; +} + +int Item::getCard(const int index) const +{ + if (index < 0 || index >= maxCards) + return 0; + return mCards[index]; +} + +void Item::setCards(const int *const cards, const int size) +{ + if (size < 0 || !cards) + return; + int sz = size; + if (sz > maxCards) + sz = maxCards; + for (int f = 0; f < sz; f ++) + mCards[f] = cards[f]; +} + +void Item::addCard(const int card) +{ + for (int f = 0; f < maxCards; f ++) + { + if (!mCards[f]) + { + mCards[f] = card; + return; + } + } +} + +void Item::updateColor() +{ + if (serverFeatures && serverFeatures->haveItemColors()) + setId(mId, ItemColorManager::getColorFromCards(&mCards[0])); +} diff --git a/src/resources/item/item.h b/src/resources/item/item.h new file mode 100644 index 000000000..ed53b3241 --- /dev/null +++ b/src/resources/item/item.h @@ -0,0 +1,249 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2015 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 . + */ + +#ifndef RESOURCES_ITEM_ITEM_H +#define RESOURCES_ITEM_ITEM_H + +#include "enums/simpletypes/damaged.h" +#include "enums/simpletypes/equipm.h" +#include "enums/simpletypes/equipped.h" +#include "enums/simpletypes/favorite.h" +#include "enums/simpletypes/identified.h" +#include "enums/simpletypes/itemcolor.h" + +#include "resources/db/itemdb.h" + +#include "localconsts.h" + +class Image; + +const int maxCards = 4; + +/** + * Represents one or more instances of a certain item type. + */ +class Item notfinal +{ + public: + /** + * Constructor. + */ + Item(const int id, + const int type, + const int quantity, + const uint8_t refine, + const ItemColor color, + const Identified identified, + const Damaged damaged, + const Favorite favorite, + const Equipm equipment, + const Equipped equipped); + + A_DELETE_COPY(Item) + + /** + * Destructor. + */ + virtual ~Item(); + + /** + * Sets the item id, color the item type. + */ + void setId(const int id, const ItemColor color); + + /** + * Returns the item id. + */ + int getId() const A_WARN_UNUSED + { return mId; } + + /** + * Returns the item image. + */ + Image *getImage() const A_WARN_UNUSED + { return mImage; } + + /** + * Sets the number of items. + */ + void setQuantity(const int quantity) + { mQuantity = quantity; } + + /** + * Increases the number of items by the given amount. + */ + void increaseQuantity(const int amount) + { mQuantity += amount; } + + /** + * Returns the number of items. + */ + int getQuantity() const A_WARN_UNUSED + { return mQuantity; } + + /** + * Sets whether this item is considered equipment. + */ + void setEquipment(const Equipm equipment) + { mEquipment = equipment; } + + /** + * Returns whether this item is considered equipment. + */ + Equipm isEquipment() const A_WARN_UNUSED + { return mEquipment; } + + /** + * Sets whether this item is equipped. + */ + void setEquipped(const Equipped equipped) + { mEquipped = equipped; } + + /** + * Returns whether this item is equipped. + */ + Equipped isEquipped() const A_WARN_UNUSED + { return mEquipped; } + + /** + * Sets this item refine level. + */ + void setRefine(const uint8_t refine) + { mRefine = refine; } + + /** + * Returns this item refine level. + */ + uint8_t getRefine() const A_WARN_UNUSED + { return mRefine; } + + /** + * Sets whether this item is in equipment. + */ + void setInEquipment(const bool inEquipment) + { mInEquipment = inEquipment; } + + /** + * Returns whether this item is in equipment. + */ + bool isInEquipment() const A_WARN_UNUSED + { return mInEquipment; } + + /** + * Sets the inventory index of this item. + */ + void setInvIndex(const int index) + { mInvIndex = index; } + + /** + * Returns the inventory index of this item. + */ + int getInvIndex() const A_WARN_UNUSED + { return mInvIndex; } + + /** + * Returns information about this item type. + */ + const ItemInfo &getInfo() const A_WARN_UNUSED + { return ItemDB::get(mId); } + + std::string getName() const A_WARN_UNUSED; + + static Image *getImage(const int id, + const ItemColor color) A_WARN_UNUSED; + + bool isHaveTag(const int tagId) const A_WARN_UNUSED; + + ItemColor getColor() const A_WARN_UNUSED + { return mColor; } + + void setColor(const ItemColor color) + { mColor = color; } + + const std::string &getDescription() const A_WARN_UNUSED + { return mDescription; } + + void setIdentified(const Identified b) + { mIdentified = b; } + + Identified getIdentified() const A_WARN_UNUSED + { return mIdentified; } + + void setDamaged(const Damaged b) + { mDamaged = b; } + + Damaged getDamaged() const A_WARN_UNUSED + { return mDamaged; } + + void setFavorite(const Favorite b) + { mFavorite = b; } + + Favorite getFavorite() const A_WARN_UNUSED + { return mFavorite; } + + void setCard(const int index, const int id); + + int getCard(const int index) const; + + void setCards(const int *const cards, const int size); + + const int *getCards() const + { return mCards; } + + void setType(const int type) + { mType = type; } + + int getType() const A_WARN_UNUSED + { return mType; } + + void setTag(const int tag) + { mTag = tag; } + + int getTag() const A_WARN_UNUSED + { return mTag; } + + void addCard(const int card); + + void updateColor(); + + int mId; /**< Item type id. */ + ItemColor mColor; + int mQuantity; /**< Number of items. */ + int mTag; + + protected: + Image *mImage; /**< Item image. */ + std::string mDescription; + std::map mTags; + int mCards[maxCards]; + uint8_t mRefine; /**< Item refine level. */ + int mInvIndex; /**< Inventory index. */ + int mType; /**< Item type. */ + Equipm mEquipment; /**< Item is equipment. */ + Equipped mEquipped; /**< Item is equipped. */ + bool mInEquipment; /**< Item is in equipment */ + Identified mIdentified; + Damaged mDamaged; + Favorite mFavorite; +}; + +#endif // RESOURCES_ITEM_ITEM_H diff --git a/src/shopitem.h b/src/shopitem.h index 36ccf3c65..cfafbec50 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -23,7 +23,7 @@ #ifndef SHOPITEM_H #define SHOPITEM_H -#include "item.h" +#include "resources/item/item.h" #include -- cgit v1.2.3-60-g2f50