diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-05-19 00:51:19 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-05-19 00:51:19 +0300 |
commit | 29a93440367af32463f285ae5f0bd2aa23aadc92 (patch) | |
tree | f04bcf2f82649a5eb6b729399c49d431959d032c /src | |
parent | 495b746d928f28ce3e13ff95f26e8cddff2fb06e (diff) | |
download | manaverse-29a93440367af32463f285ae5f0bd2aa23aadc92.tar.gz manaverse-29a93440367af32463f285ae5f0bd2aa23aadc92.tar.bz2 manaverse-29a93440367af32463f285ae5f0bd2aa23aadc92.tar.xz manaverse-29a93440367af32463f285ae5f0bd2aa23aadc92.zip |
Move itemtype into separate file.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/being/playerinfo.cpp | 4 | ||||
-rw-r--r-- | src/gui/popups/itempopup.cpp | 36 | ||||
-rw-r--r-- | src/gui/popups/itempopup.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 4 | ||||
-rw-r--r-- | src/gui/windows/buydialog.cpp | 4 | ||||
-rw-r--r-- | src/resources/db/itemdb.cpp | 68 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 2 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 30 | ||||
-rw-r--r-- | src/resources/itemtype.h | 52 |
11 files changed, 119 insertions, 87 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1a6f2cacc..f2cd7340b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -553,6 +553,7 @@ SET(SRCS resources/iteminfo.h resources/iteminfo.cpp resources/itemslot.h + resources/itemtype.h resources/db/mapdb.cpp resources/db/mapdb.h resources/db/moddb.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 4fefd63eb..eea12fa74 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -660,6 +660,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/iteminfo.h \ resources/iteminfo.cpp \ resources/itemslot.h \ + resources/itemtype.h \ resources/db/mapdb.cpp \ resources/db/mapdb.h \ resources/db/moddb.cpp \ diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index b4824599b..4978bd494 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -203,8 +203,8 @@ void setInventoryItem(const int index, const int id, const int amount, const int refine) { bool equipment = false; - const ItemType itemType = ItemDB::get(id).getType(); - if (itemType != ITEM_UNUSABLE && itemType != ITEM_USABLE) + const ItemType::Type itemType = ItemDB::get(id).getType(); + if (itemType != ItemType::UNUSABLE && itemType != ItemType::USABLE) equipment = true; if (mInventory) mInventory->setItem(index, id, amount, refine, equipment); diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp index 9b0870261..c07f99367 100644 --- a/src/gui/popups/itempopup.cpp +++ b/src/gui/popups/itempopup.cpp @@ -50,7 +50,7 @@ ItemPopup::ItemPopup() : mItemDesc(new TextBox(this)), mItemEffect(new TextBox(this)), mItemWeight(new TextBox(this)), - mItemType(ITEM_UNUSABLE), + mItemType(ItemType::UNUSABLE), mIcon(new Icon(this, nullptr)), mLastName(), mLastId(0), @@ -235,26 +235,26 @@ void ItemPopup::setItem(const ItemInfo &item, const unsigned char color, return label->setForegroundColorAll(getThemeColor(name2), \ getThemeColor(name2##_OUTLINE)); \ } -void ItemPopup::setLabelColor(Label *label, const ItemType type) const +void ItemPopup::setLabelColor(Label *label, const ItemType::Type type) const { switch (type) { - caseSetColor(ITEM_UNUSABLE, Theme::GENERIC) - caseSetColor(ITEM_USABLE, Theme::USABLE) - caseSetColor(ITEM_EQUIPMENT_ONE_HAND_WEAPON, Theme::ONEHAND) - caseSetColor(ITEM_EQUIPMENT_TWO_HANDS_WEAPON, Theme::TWOHAND) - caseSetColor(ITEM_EQUIPMENT_TORSO, Theme::TORSO) - caseSetColor(ITEM_EQUIPMENT_ARMS, Theme::ARMS) - caseSetColor(ITEM_EQUIPMENT_HEAD, Theme::HEAD) - caseSetColor(ITEM_EQUIPMENT_LEGS, Theme::LEGS) - caseSetColor(ITEM_EQUIPMENT_SHIELD, Theme::SHIELD) - caseSetColor(ITEM_EQUIPMENT_RING, Theme::RING) - caseSetColor(ITEM_EQUIPMENT_NECKLACE, Theme::NECKLACE) - caseSetColor(ITEM_EQUIPMENT_FEET, Theme::FEET) - caseSetColor(ITEM_EQUIPMENT_AMMO, Theme::AMMO) - caseSetColor(ITEM_EQUIPMENT_CHARM, Theme::CHARM) - caseSetColor(ITEM_SPRITE_RACE, Theme::UNKNOWN_ITEM) - caseSetColor(ITEM_SPRITE_HAIR, Theme::UNKNOWN_ITEM) + caseSetColor(ItemType::UNUSABLE, Theme::GENERIC) + caseSetColor(ItemType::USABLE, Theme::USABLE) + caseSetColor(ItemType::EQUIPMENT_ONE_HAND_WEAPON, Theme::ONEHAND) + caseSetColor(ItemType::EQUIPMENT_TWO_HANDS_WEAPON, Theme::TWOHAND) + caseSetColor(ItemType::EQUIPMENT_TORSO, Theme::TORSO) + caseSetColor(ItemType::EQUIPMENT_ARMS, Theme::ARMS) + caseSetColor(ItemType::EQUIPMENT_HEAD, Theme::HEAD) + caseSetColor(ItemType::EQUIPMENT_LEGS, Theme::LEGS) + caseSetColor(ItemType::EQUIPMENT_SHIELD, Theme::SHIELD) + caseSetColor(ItemType::EQUIPMENT_RING, Theme::RING) + caseSetColor(ItemType::EQUIPMENT_NECKLACE, Theme::NECKLACE) + caseSetColor(ItemType::EQUIPMENT_FEET, Theme::FEET) + caseSetColor(ItemType::EQUIPMENT_AMMO, Theme::AMMO) + caseSetColor(ItemType::EQUIPMENT_CHARM, Theme::CHARM) + caseSetColor(ItemType::SPRITE_RACE, Theme::UNKNOWN_ITEM) + caseSetColor(ItemType::SPRITE_HAIR, Theme::UNKNOWN_ITEM) default: { return label->setForegroundColorAll(getThemeColor( diff --git a/src/gui/popups/itempopup.h b/src/gui/popups/itempopup.h index 73129eaea..7f65f23da 100644 --- a/src/gui/popups/itempopup.h +++ b/src/gui/popups/itempopup.h @@ -68,13 +68,13 @@ class ItemPopup final : public Popup TextBox *mItemDesc; TextBox *mItemEffect; TextBox *mItemWeight; - ItemType mItemType; + ItemType::Type mItemType; Icon *mIcon; std::string mLastName; int mLastId; unsigned char mLastColor; - void setLabelColor(Label *label, const ItemType type) const; + void setLabelColor(Label *label, const ItemType::Type type) const; }; #endif // GUI_POPUPS_ITEMPOPUP_H diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index fccc21b2f..1be268d56 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -149,8 +149,8 @@ namespace const ItemInfo &info1 = pair1->mItem->getInfo(); const ItemInfo &info2 = pair2->mItem->getInfo(); - const ItemType t1 = info1.getType(); - const ItemType t2 = info2.getType(); + const ItemType::Type t1 = info1.getType(); + const ItemType::Type t2 = info2.getType(); if (t1 == t2) { return (info1.getName() < info2.getName()); diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index 6799bcaf8..5d6774a51 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -152,8 +152,8 @@ namespace if (!item1 || !item2) return false; - const ItemType type1 = item1->getInfo().getType(); - const ItemType type2 = item2->getInfo().getType(); + const ItemType::Type type1 = item1->getInfo().getType(); + const ItemType::Type type2 = item2->getInfo().getType(); if (type1 == type2) return item1->getPrice() < item2->getPrice(); return type1 < type2; diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp index 32b724de9..234225fb0 100644 --- a/src/resources/db/itemdb.cpp +++ b/src/resources/db/itemdb.cpp @@ -108,76 +108,76 @@ void ItemDB::setStatsList(const std::vector<ItemDB::Stat> &stats) extraStats = stats; } -static ItemType itemTypeFromString(const std::string &name) +static ItemType::Type itemTypeFromString(const std::string &name) { if (name == "generic" || name == "other") { - return ITEM_UNUSABLE; + return ItemType::UNUSABLE; } else if (name == "usable") { - return ITEM_USABLE; + return ItemType::USABLE; } else if (name == "equip-1hand") { - return ITEM_EQUIPMENT_ONE_HAND_WEAPON; + return ItemType::EQUIPMENT_ONE_HAND_WEAPON; } else if (name == "equip-2hand") { - return ITEM_EQUIPMENT_TWO_HANDS_WEAPON; + return ItemType::EQUIPMENT_TWO_HANDS_WEAPON; } else if (name == "equip-torso") { - return ITEM_EQUIPMENT_TORSO; + return ItemType::EQUIPMENT_TORSO; } else if (name == "equip-arms") { - return ITEM_EQUIPMENT_ARMS; + return ItemType::EQUIPMENT_ARMS; } else if (name == "equip-head") { - return ITEM_EQUIPMENT_HEAD; + return ItemType::EQUIPMENT_HEAD; } else if (name == "equip-legs") { - return ITEM_EQUIPMENT_LEGS; + return ItemType::EQUIPMENT_LEGS; } else if (name == "equip-shield") { - return ITEM_EQUIPMENT_SHIELD; + return ItemType::EQUIPMENT_SHIELD; } else if (name == "equip-ring") { - return ITEM_EQUIPMENT_RING; + return ItemType::EQUIPMENT_RING; } else if (name == "equip-charm") { - return ITEM_EQUIPMENT_CHARM; + return ItemType::EQUIPMENT_CHARM; } else if (name == "equip-necklace" || name == "equip-neck") { - return ITEM_EQUIPMENT_NECKLACE; + return ItemType::EQUIPMENT_NECKLACE; } else if (name == "equip-feet") { - return ITEM_EQUIPMENT_FEET; + return ItemType::EQUIPMENT_FEET; } else if (name == "equip-ammo") { - return ITEM_EQUIPMENT_AMMO; + return ItemType::EQUIPMENT_AMMO; } else if (name == "racesprite") { - return ITEM_SPRITE_RACE; + return ItemType::SPRITE_RACE; } else if (name == "hairsprite") { - return ITEM_SPRITE_HAIR; + return ItemType::SPRITE_HAIR; } else { logger->log("Unknown item type: " + name); - return ITEM_UNUSABLE; + return ItemType::UNUSABLE; } } @@ -353,27 +353,27 @@ void ItemDB::loadXmlFile(const std::string &fileName, int &tagNum) switch (itemInfo->getType()) { - case ITEM_USABLE: + case ItemType::USABLE: itemInfo->addTag(mTags["Usable"]); break; - case ITEM_UNUSABLE: + case ItemType::UNUSABLE: itemInfo->addTag(mTags["Unusable"]); break; default: - case ITEM_EQUIPMENT_ONE_HAND_WEAPON: - case ITEM_EQUIPMENT_TWO_HANDS_WEAPON: - case ITEM_EQUIPMENT_TORSO: - case ITEM_EQUIPMENT_ARMS: - case ITEM_EQUIPMENT_HEAD: - case ITEM_EQUIPMENT_LEGS: - case ITEM_EQUIPMENT_SHIELD: - case ITEM_EQUIPMENT_RING: - case ITEM_EQUIPMENT_NECKLACE: - case ITEM_EQUIPMENT_FEET: - case ITEM_EQUIPMENT_AMMO: - case ITEM_EQUIPMENT_CHARM: - case ITEM_SPRITE_RACE: - case ITEM_SPRITE_HAIR: + case ItemType::EQUIPMENT_ONE_HAND_WEAPON: + case ItemType::EQUIPMENT_TWO_HANDS_WEAPON: + case ItemType::EQUIPMENT_TORSO: + case ItemType::EQUIPMENT_ARMS: + case ItemType::EQUIPMENT_HEAD: + case ItemType::EQUIPMENT_LEGS: + case ItemType::EQUIPMENT_SHIELD: + case ItemType::EQUIPMENT_RING: + case ItemType::EQUIPMENT_NECKLACE: + case ItemType::EQUIPMENT_FEET: + case ItemType::EQUIPMENT_AMMO: + case ItemType::EQUIPMENT_CHARM: + case ItemType::SPRITE_RACE: + case ItemType::SPRITE_HAIR: itemInfo->addTag(mTags["Equipment"]); break; } diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index e6b56c43b..c4af7d30a 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -43,7 +43,7 @@ ItemInfo::ItemInfo() : mName(), mDescription(), mEffect(), - mType(ITEM_UNUSABLE), + mType(ItemType::UNUSABLE), mWeight(0), mView(0), mId(0), diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 8d8d18845..8d25ff8f2 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -26,6 +26,7 @@ #include "being/gender.h" #include "resources/cursor.h" +#include "resources/itemtype.h" #include "resources/soundinfo.h" #include "resources/spritedef.h" @@ -36,29 +37,6 @@ namespace ColorDB class ItemColor; } -/** - * Enumeration of available Item types. - */ -enum ItemType -{ - ITEM_UNUSABLE = 0, - ITEM_USABLE, - ITEM_EQUIPMENT_ONE_HAND_WEAPON, - ITEM_EQUIPMENT_TWO_HANDS_WEAPON, - ITEM_EQUIPMENT_TORSO, - ITEM_EQUIPMENT_ARMS, // 5 - ITEM_EQUIPMENT_HEAD, - ITEM_EQUIPMENT_LEGS, - ITEM_EQUIPMENT_SHIELD, - ITEM_EQUIPMENT_RING, - ITEM_EQUIPMENT_NECKLACE, // 10 - ITEM_EQUIPMENT_FEET, - ITEM_EQUIPMENT_AMMO, - ITEM_EQUIPMENT_CHARM, - ITEM_SPRITE_RACE, - ITEM_SPRITE_HAIR // 15 -}; - // sprite, <itemfrom, itemto> typedef std::map<int, std::map<int, int> > SpriteToItemMap; typedef SpriteToItemMap::const_iterator SpriteToItemMapCIter; @@ -115,10 +93,10 @@ class ItemInfo final const std::string &getEffect() const A_WARN_UNUSED { return mEffect; } - void setType(const ItemType type) + void setType(const ItemType::Type type) { mType = type; } - ItemType getType() const A_WARN_UNUSED + ItemType::Type getType() const A_WARN_UNUSED { return mType; } void setWeight(const int weight) @@ -289,7 +267,7 @@ class ItemInfo final std::string mName; std::string mDescription; /**< Short description. */ std::string mEffect; /**< Description of effects. */ - ItemType mType; /**< Item type. */ + ItemType::Type mType; /**< Item type. */ int mWeight; /**< Weight in grams. */ int mView; /**< Item ID of how this item looks. */ int mId; /**< Item ID */ diff --git a/src/resources/itemtype.h b/src/resources/itemtype.h new file mode 100644 index 000000000..8cb8af0ad --- /dev/null +++ b/src/resources/itemtype.h @@ -0,0 +1,52 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * 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_ITEMTYPE_H +#define RESOURCES_ITEMTYPE_H + +namespace ItemType +{ + /** + * Enumeration of available Item types. + */ + enum Type + { + UNUSABLE = 0, + USABLE, + EQUIPMENT_ONE_HAND_WEAPON, + EQUIPMENT_TWO_HANDS_WEAPON, + EQUIPMENT_TORSO, + EQUIPMENT_ARMS, // 5 + EQUIPMENT_HEAD, + EQUIPMENT_LEGS, + EQUIPMENT_SHIELD, + EQUIPMENT_RING, + EQUIPMENT_NECKLACE, // 10 + EQUIPMENT_FEET, + EQUIPMENT_AMMO, + EQUIPMENT_CHARM, + SPRITE_RACE, + SPRITE_HAIR // 15 + }; +} // namespace ItemType + +#endif // RESOURCES_ITEMTYPE_H |