summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-01-04 00:31:44 +0200
committerAndrei Karas <akaras@inbox.ru>2011-01-04 00:31:44 +0200
commit311783bebbe2bed366dca5097697ce34c690292d (patch)
tree0533581ca605f773a67739efccf75472a4d35dd7 /src/gui
parent76bc1a5c994b46d8a4486a1226f681f7a4982f1c (diff)
downloadplus-311783bebbe2bed366dca5097697ce34c690292d.tar.gz
plus-311783bebbe2bed366dca5097697ce34c690292d.tar.bz2
plus-311783bebbe2bed366dca5097697ce34c690292d.tar.xz
plus-311783bebbe2bed366dca5097697ce34c690292d.zip
Add draw filter (incomplete)
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/inventorywindow.cpp15
-rw-r--r--src/gui/widgets/inventoryfilter.cpp13
-rw-r--r--src/gui/widgets/inventoryfilter.h6
-rw-r--r--src/gui/widgets/itemcontainer.cpp62
-rw-r--r--src/gui/widgets/itemcontainer.h6
5 files changed, 90 insertions, 12 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;