diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-01-04 00:31:44 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-01-04 00:31:44 +0200 |
commit | 311783bebbe2bed366dca5097697ce34c690292d (patch) | |
tree | 0533581ca605f773a67739efccf75472a4d35dd7 /src | |
parent | 76bc1a5c994b46d8a4486a1226f681f7a4982f1c (diff) | |
download | mv-311783bebbe2bed366dca5097697ce34c690292d.tar.gz mv-311783bebbe2bed366dca5097697ce34c690292d.tar.bz2 mv-311783bebbe2bed366dca5097697ce34c690292d.tar.xz mv-311783bebbe2bed366dca5097697ce34c690292d.zip |
Add draw filter (incomplete)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/inventorywindow.cpp | 15 | ||||
-rw-r--r-- | src/gui/widgets/inventoryfilter.cpp | 13 | ||||
-rw-r--r-- | src/gui/widgets/inventoryfilter.h | 6 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 62 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.h | 6 | ||||
-rw-r--r-- | src/item.cpp | 16 | ||||
-rw-r--r-- | src/item.h | 5 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 7 | ||||
-rw-r--r-- | src/resources/itemdb.h | 3 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 6 |
10 files changed, 121 insertions, 18 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 3930ef207..a02fab4e6 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -93,15 +93,15 @@ InventoryWindow::InventoryWindow(Inventory *inventory): mSlotsBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_INVY_SLOTS); mFilter = new InventoryFilter(getWindowName(), 20, 10); + mFilter->addActionListener(this); + mFilter->setActionEventId("tags"); mFilterLabel = new Label(_("Filter:")); std::vector<std::string> tags = ItemDB::getTags(); - for (int f = 0; f < tags.size(); f ++) + for (unsigned f = 0; f < tags.size(); f ++) mFilter->add(tags[f]); -// mFilter->add("All"); - if (isMainInventory()) { std::string equip = _("Equip"); @@ -207,8 +207,7 @@ void InventoryWindow::action(const gcn::ActionEvent &event) outfitWindow->requestMoveToTop(); } } - - if (event.getId() == "shop") + else if (event.getId() == "shop") { if (shopWindow) { @@ -233,6 +232,12 @@ void InventoryWindow::action(const gcn::ActionEvent &event) ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, this, item); } + else if (!event.getId().find("tag_") && mItems) + { + std::string tagName = event.getId().substr(4); + mItems->setFilter(ItemDB::getTagId(tagName)); +// logger->log("eventid: %s", tagName.c_str()); + } Item *item = mItems->getSelectedItem(); diff --git a/src/gui/widgets/inventoryfilter.cpp b/src/gui/widgets/inventoryfilter.cpp index 406860719..faceafa9e 100644 --- a/src/gui/widgets/inventoryfilter.cpp +++ b/src/gui/widgets/inventoryfilter.cpp @@ -23,6 +23,7 @@ #include "gui/widgets/horizontcontainer.h" #include "gui/widgets/radiobutton.h" +#include "log.h" InventoryFilter::InventoryFilter(std::string group, int height, int spacing): HorizontContainer(height, spacing), @@ -37,5 +38,17 @@ void InventoryFilter::add(std::string tag) RadioButton *radio = new RadioButton(tag, mGroup, mCount == 0); radio->adjustSize(); + radio->setActionEventId("tag_" + tag); + radio->addActionListener(this); HorizontContainer::add(radio); } + +void InventoryFilter::action(const gcn::ActionEvent &event) +{ + ActionListenerIterator iter; + for (iter = mActionListeners.begin(); + iter != mActionListeners.end(); ++iter) + { + (*iter)->action(event); + } +}
\ No newline at end of file diff --git a/src/gui/widgets/inventoryfilter.h b/src/gui/widgets/inventoryfilter.h index 36112d374..28423413f 100644 --- a/src/gui/widgets/inventoryfilter.h +++ b/src/gui/widgets/inventoryfilter.h @@ -22,6 +22,7 @@ #ifndef GUI_INVENTORYFILTER_H #define GUI_INVENTORYFILTER_H +#include <guichan/actionlistener.hpp> #include <guichan/widgetlistener.hpp> #include "gui/widgets/horizontcontainer.h" @@ -39,12 +40,15 @@ * * This container places it's contents veritcally. */ -class InventoryFilter : public HorizontContainer +class InventoryFilter : public HorizontContainer, public gcn::ActionListener { public: InventoryFilter(std::string group, int height, int spacing); + void add(std::string tag); + void action(const gcn::ActionEvent &event); + private: std::string mGroup; }; diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 8b5b1914a..3f6a6b45c 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -65,7 +65,9 @@ ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity): mSelectionStatus(SEL_NONE), mForceQuantity(forceQuantity), mSwapItems(false), - mDescItems(false) + mDescItems(false), + mTag(0), + mShowMatrix(0) { mItemPopup = new ItemPopup; setFocusable(true); @@ -108,21 +110,29 @@ void ItemContainer::logic() void ItemContainer::draw(gcn::Graphics *graphics) { - if (!mInventory) + if (!mInventory || !mShowMatrix) return; Graphics *g = static_cast<Graphics*>(graphics); g->setFont(getFont()); - for (int i = 0; i < mGridColumns; i++) + int i = 0; + int j = 0; + +// int idx = 0; + + for (int j = 0; j < mGridRows; j++) { - for (int j = 0; j < mGridRows; j++) + for (int i = 0; i < mGridColumns; i++) { int itemX = i * BOX_WIDTH; int itemY = j * BOX_HEIGHT; - int itemIndex = (j * mGridColumns) + i; - Item *item = mInventory->getItem(itemIndex); + int itemIndex = j * mGridColumns + i; + if (mShowMatrix[itemIndex] < 0) + continue; + + Item *item = mInventory->getItem(mShowMatrix[itemIndex]); if (!item || item->getId() == 0) continue; @@ -385,6 +395,40 @@ void ItemContainer::adjustHeight() ++mGridRows; setHeight(mGridRows * BOX_HEIGHT); + + updateMatrix(); +} + +void ItemContainer::updateMatrix() +{ + delete mShowMatrix; + mShowMatrix = new int[mGridRows * mGridColumns]; + memset(mShowMatrix, -1, mGridRows * mGridColumns); + + int i = 0; + int j = 0; + + for (int idx = 0; idx < mInventory->getSize(); idx ++) + { +// int itemX = i * BOX_WIDTH; +// int itemY = j * BOX_HEIGHT; + int itemIndex = idx; + Item *item = mInventory->getItem(itemIndex); + + if (!item || item->getId() == 0 || !item->isHaveTag(mTag)) + continue; + + mShowMatrix[j * mGridColumns + i] = itemIndex; + + i ++; + if (i >= mGridColumns) + { + i = 0; + j ++; + } + if (j >= mGridRows) + break; + } } int ItemContainer::getSlotIndex(int x, int y) const @@ -473,3 +517,9 @@ void ItemContainer::moveHighlight(Direction direction) break; } } + +void ItemContainer::setFilter (int tag) +{ + mTag = tag; + updateMatrix(); +}
\ No newline at end of file diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index 8aaa236b4..9ce819534 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -119,6 +119,8 @@ class ItemContainer : public gcn::Widget, void removeSelectionListener(gcn::SelectionListener *listener) { mSelectionListeners.remove(listener); } + void setFilter (int tag); + private: enum Direction { @@ -173,6 +175,8 @@ class ItemContainer : public gcn::Widget, */ int getSlotIndex(int x, int y) const; + void updateMatrix(); + Inventory *mInventory; int mGridColumns, mGridRows; Image *mSelImg; @@ -183,8 +187,10 @@ class ItemContainer : public gcn::Widget, bool mSwapItems; bool mDescItems; int mDragPosX, mDragPosY; + int mTag; ItemPopup *mItemPopup; + int *mShowMatrix; typedef std::list<gcn::SelectionListener*> SelectionListenerList; typedef SelectionListenerList::iterator SelectionListenerIterator; diff --git a/src/item.cpp b/src/item.cpp index 94eaf383e..33d3916d3 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -62,7 +62,14 @@ void Item::setId(int id) mDrawImage->decRef(); ResourceManager *resman = ResourceManager::getInstance(); - SpriteDisplay display = getInfo().getDisplay(); + ItemInfo info = getInfo(); + mTags = info.getTags(); + logger->log("tag0=" + toString(mTags[1])); + +// for (int f = 0; f < mTags->size(); f ++) +// logger->log("tag: %d", (*mTags)[f]); + + SpriteDisplay display = info.getDisplay(); std::string imagePath = paths.getStringValue("itemIcons") + display.image; mImage = resman->getImage(imagePath); @@ -81,6 +88,13 @@ void Item::setId(int id) } } +bool Item::isHaveTag(int tagId) +{ + if (mTags.find(tagId) == mTags.end()) + return false; + return mTags[tagId] > 0; +} + Image *Item::getImage(int id) { ResourceManager *resman = ResourceManager::getInstance(); diff --git a/src/item.h b/src/item.h index 520028f8f..de19b2937 100644 --- a/src/item.h +++ b/src/item.h @@ -24,6 +24,8 @@ #include "resources/itemdb.h" +#include <map> + class Image; /** @@ -152,6 +154,8 @@ class Item static Image *getImage(int id); + bool isHaveTag(int tagId); + protected: int mId; /**< Item type id. */ Image *mImage; /**< Item image. */ @@ -162,6 +166,7 @@ class Item bool mInEquipment; /**< Item is in equipment */ int mRefine; /**< Item refine level. */ int mInvIndex; /**< Inventory index. */ + std::map <int, int> mTags; }; #endif diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 385f32ee6..71b88d192 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -343,11 +343,16 @@ void ItemDB::load() mLoaded = true; } -std::vector<std::string> &ItemDB::getTags() +const std::vector<std::string> &ItemDB::getTags() { return mTagNames; } +int ItemDB::getTagId(std::string tagName) +{ + return mTags[tagName]; +} + void ItemDB::unload() { logger->log1("Unloading item database..."); diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h index 54e8ceb33..19e36889e 100644 --- a/src/resources/itemdb.h +++ b/src/resources/itemdb.h @@ -50,7 +50,7 @@ namespace ItemDB */ void unload(); - std::vector<std::string> &getTags(); + const std::vector<std::string> &getTags(); bool exists(int id); @@ -63,6 +63,7 @@ namespace ItemDB const std::map<int, ItemInfo*> &getItemInfos(); + int getTagId(std::string tagName); struct Stat { Stat(const std::string &tag, diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 3ccbf01ec..19bba335d 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -207,11 +207,11 @@ class ItemInfo void setDrawPriority(int n) { mDrawPriority = n; } - std::set<int> &getTags() + std::map<int, int> getTags() { return mTags; } void addTag(int tag) - { mTags.insert(tag); } + { mTags[tag] = 1; } protected: SpriteDisplay mDisplay; /**< Display info (like icon) */ @@ -243,7 +243,7 @@ class ItemInfo /** Stores the names of sounds to be played at certain event. */ std::map < EquipmentSoundEvent, std::vector<std::string> > mSounds; - std::set <int> mTags; + std::map <int,int> mTags; }; #endif |