diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-08 03:15:52 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-08 03:23:43 +0300 |
commit | f1c17766c66394ce875854430f8f028c0fa5b3a5 (patch) | |
tree | d42df4e515bff99c577d44a381dbb143d21833e9 /src/gui/widgets | |
parent | 327c7e01b95263961d1e3ecd450939de01262346 (diff) | |
download | manaverse-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')
-rw-r--r-- | src/gui/widgets/dropdown.cpp | 9 | ||||
-rw-r--r-- | src/gui/widgets/dropdown.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 67 |
3 files changed, 77 insertions, 3 deletions
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index f01d3fb55..687d7dc6d 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -46,7 +46,8 @@ Image *DropDown::buttons[2][2]; ImageRect DropDown::skin; float DropDown::mAlpha = 1.0; -DropDown::DropDown(gcn::ListModel *listModel): +DropDown::DropDown(gcn::ListModel *listModel, gcn::ActionListener* listener, + std::string eventId): gcn::DropDown::DropDown(listModel, new ScrollArea, new ListBox(listModel)) @@ -105,6 +106,12 @@ DropDown::DropDown(gcn::ListModel *listModel): mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); mShadowColor = Theme::getThemeColor(Theme::DROPDOWN_SHADOW); setForegroundColor(Theme::getThemeColor(Theme::TEXT)); + + if (!eventId.empty()) + setActionEventId(eventId); + + if (listener) + addActionListener(listener); } DropDown::~DropDown() diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index 6a22ba497..4cbd23314 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -46,7 +46,9 @@ class DropDown : public gcn::DropDown * @param listBox the listBox to use. * @see ListModel, ScrollArea, ListBox. */ - DropDown(gcn::ListModel *listModel = 0); + DropDown(gcn::ListModel *listModel = 0, + gcn::ActionListener* listener = NULL, + std::string eventId = ""); ~DropDown(); 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(); } |