summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/inventoryfilter.cpp2
-rw-r--r--src/gui/widgets/inventoryfilter.h7
-rw-r--r--src/gui/widgets/itemcontainer.cpp92
-rw-r--r--src/gui/widgets/itemcontainer.h4
-rw-r--r--src/gui/widgets/radiobutton.cpp3
5 files changed, 86 insertions, 22 deletions
diff --git a/src/gui/widgets/inventoryfilter.cpp b/src/gui/widgets/inventoryfilter.cpp
index faceafa9e..aa2f2a5e4 100644
--- a/src/gui/widgets/inventoryfilter.cpp
+++ b/src/gui/widgets/inventoryfilter.cpp
@@ -38,7 +38,7 @@ void InventoryFilter::add(std::string tag)
RadioButton *radio = new RadioButton(tag, mGroup, mCount == 0);
radio->adjustSize();
- radio->setActionEventId("tag_" + tag);
+ radio->setActionEventId(mActionEventId + tag);
radio->addActionListener(this);
HorizontContainer::add(radio);
}
diff --git a/src/gui/widgets/inventoryfilter.h b/src/gui/widgets/inventoryfilter.h
index 28423413f..42f51c895 100644
--- a/src/gui/widgets/inventoryfilter.h
+++ b/src/gui/widgets/inventoryfilter.h
@@ -33,13 +33,6 @@
#define _UNUSED_
#endif
-//class HorizontContainer;
-
-/**
- * A widget container.
- *
- * This container places it's contents veritcally.
- */
class InventoryFilter : public HorizontContainer, public gcn::ActionListener
{
public:
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index b9123bc5a..d25e4baa1 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -55,6 +55,44 @@
static const int BOX_WIDTH = 35;
static const int BOX_HEIGHT = 43;
+class ItemIdPair
+{
+ public:
+ ItemIdPair(int id, Item* item)
+ {
+ mId = id;
+ mItem = item;
+ }
+
+ int mId;
+ Item* mItem;
+};
+
+class SortItemAlphaFunctor
+{
+ public:
+ bool operator() (ItemIdPair* pair1, ItemIdPair* pair2)
+ {
+ if (!pair1 || !pair2)
+ return false;
+
+ return (pair1->mItem->getInfo().getName()
+ < pair2->mItem->getInfo().getName());
+ }
+} itemAlphaSorter;
+
+class SortItemIdFunctor
+{
+ public:
+ bool operator() (ItemIdPair* pair1, ItemIdPair* pair2)
+ {
+ if (!pair1 || !pair2)
+ return false;
+
+ return pair1->mItem->getId() < pair2->mItem->getId();
+ }
+} itemIdSorter;
+
ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
mInventory(inventory),
mGridColumns(1),
@@ -67,6 +105,7 @@ ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
mSwapItems(false),
mDescItems(false),
mTag(0),
+ mSortType(0),
mShowMatrix(0)
{
mItemPopup = new ItemPopup;
@@ -117,11 +156,6 @@ void ItemContainer::draw(gcn::Graphics *graphics)
g->setFont(getFont());
- int i = 0;
- int j = 0;
-
-// int idx = 0;
-
for (int j = 0; j < mGridRows; j++)
{
for (int i = 0; i < mGridColumns; i++)
@@ -401,24 +435,46 @@ void ItemContainer::adjustHeight()
void ItemContainer::updateMatrix()
{
+ if (!mInventory)
+ return;
+
delete []mShowMatrix;
mShowMatrix = new int[mGridRows * mGridColumns];
+ std::vector<ItemIdPair*> sortedItems;
int i = 0;
int j = 0;
- for (int idx = 0; idx < mInventory->getSize(); idx ++)
+ for (unsigned idx = 0; idx < mInventory->getSize(); idx ++)
{
- int itemIndex = idx;
- if (j >= mGridRows)
- break;
-
- Item *item = mInventory->getItem(itemIndex);
+ Item *item = mInventory->getItem(idx);
if (!item || item->getId() == 0 || !item->isHaveTag(mTag))
continue;
- mShowMatrix[j * mGridColumns + i] = itemIndex;
+ sortedItems.push_back(new ItemIdPair(idx, item));
+ }
+
+ switch (mSortType)
+ {
+ case 0:
+ default:
+ break;
+ case 1:
+ sort(sortedItems.begin(), sortedItems.end(), itemAlphaSorter);
+ break;
+ case 2:
+ sort(sortedItems.begin(), sortedItems.end(), itemIdSorter);
+ break;
+ }
+
+ for (unsigned idx = 0; idx < sortedItems.size(); idx ++)
+ {
+ int itemIndex = idx;
+ if (j >= mGridRows)
+ break;
+
+ mShowMatrix[j * mGridColumns + i] = sortedItems[itemIndex]->mId;
i ++;
if (i >= mGridColumns)
@@ -430,6 +486,9 @@ void ItemContainer::updateMatrix()
for (int idx = j * mGridColumns + i; idx < mGridRows * mGridColumns; idx ++)
mShowMatrix[idx] = -1;
+
+ for (unsigned idx = 0; idx < sortedItems.size(); idx ++)
+ delete sortedItems[idx];
}
int ItemContainer::getSlotIndex(int x, int y) const
@@ -530,4 +589,11 @@ void ItemContainer::setFilter (int tag)
{
mTag = tag;
updateMatrix();
-} \ No newline at end of file
+}
+
+void ItemContainer::setSortType (int sortType)
+{
+ mSortType = sortType;
+ logger->log("setSortType: %d", sortType);
+ updateMatrix();
+}
diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h
index 9ce819534..003187859 100644
--- a/src/gui/widgets/itemcontainer.h
+++ b/src/gui/widgets/itemcontainer.h
@@ -28,6 +28,7 @@
#include <guichan/widgetlistener.hpp>
#include <list>
+#include <algorithm>
#ifdef __GNUC__
#define _UNUSED_ __attribute__ ((unused))
@@ -121,6 +122,8 @@ class ItemContainer : public gcn::Widget,
void setFilter (int tag);
+ void setSortType (int sortType);
+
private:
enum Direction
{
@@ -188,6 +191,7 @@ class ItemContainer : public gcn::Widget,
bool mDescItems;
int mDragPosX, mDragPosY;
int mTag;
+ int mSortType;
ItemPopup *mItemPopup;
int *mShowMatrix;
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index c9738e3cd..9683a11a8 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -148,7 +148,8 @@ void RadioButton::draw(gcn::Graphics* graphics)
graphics->setColor(getForegroundColor());
int h = getHeight() + getHeight() / 2;
- graphics->drawText(getCaption(), h - 2, 0);
+// graphics->drawText(getCaption(), h - 2, 0);
+ graphics->drawText(getCaption(), 16, 0);
}
void RadioButton::mouseEntered(gcn::MouseEvent& event _UNUSED_)