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/gui/widgets | |
parent | 76bc1a5c994b46d8a4486a1226f681f7a4982f1c (diff) | |
download | manaplus-311783bebbe2bed366dca5097697ce34c690292d.tar.gz manaplus-311783bebbe2bed366dca5097697ce34c690292d.tar.bz2 manaplus-311783bebbe2bed366dca5097697ce34c690292d.tar.xz manaplus-311783bebbe2bed366dca5097697ce34c690292d.zip |
Add draw filter (incomplete)
Diffstat (limited to 'src/gui/widgets')
-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 |
4 files changed, 80 insertions, 7 deletions
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; |