summaryrefslogtreecommitdiff
path: root/src/gui/widgets/itemcontainer.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-09-08 03:15:52 +0300
committerAndrei Karas <akaras@inbox.ru>2011-09-08 03:23:43 +0300
commitf1c17766c66394ce875854430f8f028c0fa5b3a5 (patch)
treed42df4e515bff99c577d44a381dbb143d21833e9 /src/gui/widgets/itemcontainer.cpp
parent327c7e01b95263961d1e3ecd450939de01262346 (diff)
downloadManaVerse-f1c17766c66394ce875854430f8f028c0fa5b3a5.tar.gz
ManaVerse-f1c17766c66394ce875854430f8f028c0fa5b3a5.tar.bz2
ManaVerse-f1c17766c66394ce875854430f8f028c0fa5b3a5.tar.xz
ManaVerse-f1c17766c66394ce875854430f8f028c0fa5b3a5.zip
Add additional sorting methods to inventory:
by weight, by amount, by type.
Diffstat (limited to 'src/gui/widgets/itemcontainer.cpp')
-rw-r--r--src/gui/widgets/itemcontainer.cpp67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 3d6d24868..75968d668 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -96,6 +96,63 @@ class SortItemIdFunctor
}
} itemIdSorter;
+class SortItemWeightFunctor
+{
+ public:
+ bool operator() (ItemIdPair* pair1, ItemIdPair* pair2)
+ {
+ if (!pair1 || !pair2)
+ return false;
+
+ const int w1 = pair1->mItem->getInfo().getWeight();
+ const int w2 = pair2->mItem->getInfo().getWeight();
+ if (w1 == w2)
+ {
+ return (pair1->mItem->getInfo().getName()
+ < pair2->mItem->getInfo().getName());
+ }
+ return w1 < w2;
+ }
+} itemWeightSorter;
+
+class SortItemAmountFunctor
+{
+ public:
+ bool operator() (ItemIdPair* pair1, ItemIdPair* pair2)
+ {
+ if (!pair1 || !pair2)
+ return false;
+
+ const int c1 = pair1->mItem->getQuantity();
+ const int c2 = pair2->mItem->getQuantity();
+ if (c1 == c2)
+ {
+ return (pair1->mItem->getInfo().getName()
+ < pair2->mItem->getInfo().getName());
+ }
+ return c1 < c2;;
+ }
+} itemAmountSorter;
+
+class SortItemTypeFunctor
+{
+ public:
+ bool operator() (ItemIdPair* pair1, ItemIdPair* pair2)
+ {
+ if (!pair1 || !pair2)
+ return false;
+
+ const int t1 = pair1->mItem->getInfo().getType();
+ const int t2 = pair2->mItem->getInfo().getType();
+ if (t1 == t2)
+ {
+ return (pair1->mItem->getInfo().getName()
+ < pair2->mItem->getInfo().getName());
+ }
+ return t1 < t2;;
+ }
+} itemTypeSorter;
+
ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity):
mInventory(inventory),
mGridColumns(1),
@@ -477,6 +534,15 @@ void ItemContainer::updateMatrix()
case 2:
sort(sortedItems.begin(), sortedItems.end(), itemIdSorter);
break;
+ case 3:
+ sort(sortedItems.begin(), sortedItems.end(), itemWeightSorter);
+ break;
+ case 4:
+ sort(sortedItems.begin(), sortedItems.end(), itemAmountSorter);
+ break;
+ case 5:
+ sort(sortedItems.begin(), sortedItems.end(), itemTypeSorter);
+ break;
}
std::vector<ItemIdPair*>::const_iterator iter;
@@ -608,6 +674,5 @@ void ItemContainer::setFilter (int tag)
void ItemContainer::setSortType (int sortType)
{
mSortType = sortType;
- logger->log("setSortType: %d", sortType);
updateMatrix();
}