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/itemcontainer.cpp | |
parent | 76bc1a5c994b46d8a4486a1226f681f7a4982f1c (diff) | |
download | manaverse-311783bebbe2bed366dca5097697ce34c690292d.tar.gz manaverse-311783bebbe2bed366dca5097697ce34c690292d.tar.bz2 manaverse-311783bebbe2bed366dca5097697ce34c690292d.tar.xz manaverse-311783bebbe2bed366dca5097697ce34c690292d.zip |
Add draw filter (incomplete)
Diffstat (limited to 'src/gui/widgets/itemcontainer.cpp')
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 62 |
1 files changed, 56 insertions, 6 deletions
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 |