summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-01-03 19:48:48 +0200
committerAndrei Karas <akaras@inbox.ru>2011-01-03 20:00:51 +0200
commit76bc1a5c994b46d8a4486a1226f681f7a4982f1c (patch)
treea2326dcfe0aa2208c03d7432168bca9ae35b5da4
parent3436558bfd7bbbe0c63a0a89330b099b7c9da7ed (diff)
downloadmanaverse-76bc1a5c994b46d8a4486a1226f681f7a4982f1c.tar.gz
manaverse-76bc1a5c994b46d8a4486a1226f681f7a4982f1c.tar.bz2
manaverse-76bc1a5c994b46d8a4486a1226f681f7a4982f1c.tar.xz
manaverse-76bc1a5c994b46d8a4486a1226f681f7a4982f1c.zip
Impliment base items tags. And show this tags in inventory.
-rw-r--r--src/gui/inventorywindow.cpp6
-rw-r--r--src/resources/itemdb.cpp35
-rw-r--r--src/resources/itemdb.h3
-rw-r--r--src/resources/iteminfo.h11
4 files changed, 52 insertions, 3 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 8ae9c0f32..3930ef207 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -96,7 +96,11 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
mFilterLabel = new Label(_("Filter:"));
- mFilter->add("All");
+ std::vector<std::string> tags = ItemDB::getTags();
+ for (int f = 0; f < tags.size(); f ++)
+ mFilter->add(tags[f]);
+
+// mFilter->add("All");
if (isMainInventory())
{
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index cc70e33b7..385f32ee6 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -42,6 +42,8 @@ namespace
ItemDB::NamedItemInfos mNamedItemInfos;
ItemInfo *mUnknown;
bool mLoaded = false;
+ std::vector<std::string> mTagNames;
+ std::map<std::string, int> mTags;
}
// Forward declarations
@@ -149,6 +151,7 @@ void ItemDB::load()
if (mLoaded)
unload();
+ int tagNum = 0;
logger->log1("Initializing item database...");
mUnknown = new ItemInfo;
@@ -168,6 +171,17 @@ void ItemDB::load()
return;
}
+ mTags.clear();
+ mTagNames.clear();
+ mTagNames.push_back("All");
+ mTagNames.push_back("Usable");
+ mTagNames.push_back("Unusable");
+ mTagNames.push_back("Equipment");
+ mTags["All"] = tagNum ++;
+ mTags["Usable"] = tagNum ++;
+ mTags["Unusable"] = tagNum ++;
+ mTags["Equipment"] = tagNum ++;
+
for_each_xml_child_node(node, rootNode)
{
if (!xmlStrEqual(node->name, BAD_CAST "item"))
@@ -210,6 +224,20 @@ void ItemDB::load()
itemInfo->setName(name.empty() ? _("unnamed") : name);
itemInfo->setDescription(description);
itemInfo->setType(itemTypeFromString(typeStr));
+ itemInfo->addTag(mTags["All"]);
+ switch (itemInfo->getType())
+ {
+ case ITEM_USABLE:
+ itemInfo->addTag(mTags["Usable"]);
+ break;
+ case ITEM_UNUSABLE:
+ itemInfo->addTag(mTags["Unusable"]);
+ break;
+ default:
+ itemInfo->addTag(mTags["Equipment"]);
+ break;
+ }
+
itemInfo->setView(view);
itemInfo->setWeight(weight);
itemInfo->setAttackAction(attackAction);
@@ -315,6 +343,11 @@ void ItemDB::load()
mLoaded = true;
}
+std::vector<std::string> &ItemDB::getTags()
+{
+ return mTagNames;
+}
+
void ItemDB::unload()
{
logger->log1("Unloading item database...");
@@ -325,6 +358,8 @@ void ItemDB::unload()
delete_all(mItemInfos);
mItemInfos.clear();
mNamedItemInfos.clear();
+ mTags.clear();
+ mTagNames.clear();
mLoaded = false;
}
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h
index 76e646c0f..54e8ceb33 100644
--- a/src/resources/itemdb.h
+++ b/src/resources/itemdb.h
@@ -23,6 +23,7 @@
#define ITEM_MANAGER_H
#include <list>
+#include <vector>
#include <map>
#include <string>
@@ -49,6 +50,8 @@ namespace ItemDB
*/
void unload();
+ std::vector<std::string> &getTags();
+
bool exists(int id);
const ItemInfo &get(int id);
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index bb84193bb..3ccbf01ec 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -207,6 +207,12 @@ class ItemInfo
void setDrawPriority(int n)
{ mDrawPriority = n; }
+ std::set<int> &getTags()
+ { return mTags; }
+
+ void addTag(int tag)
+ { mTags.insert(tag); }
+
protected:
SpriteDisplay mDisplay; /**< Display info (like icon) */
std::string mName;
@@ -233,10 +239,11 @@ class ItemInfo
std::string mMissileParticle;
/** Maps gender to sprite filenames. */
- std::map<int, std::string> mAnimationFiles;
+ std::map <int, std::string> mAnimationFiles;
/** Stores the names of sounds to be played at certain event. */
- std::map< EquipmentSoundEvent, std::vector<std::string> > mSounds;
+ std::map < EquipmentSoundEvent, std::vector<std::string> > mSounds;
+ std::set <int> mTags;
};
#endif