diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-18 17:49:18 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-18 17:49:18 +0300 |
commit | 70b520b1e876f9698bb95baa2d274ea289a0c6bd (patch) | |
tree | 152c7519b0d9b8fb424af2373ec48db823a85575 /src/gui/widgets/itemcontainer.cpp | |
parent | 62ec17f6e489ec50f17219444468aeb8969dc961 (diff) | |
parent | 3b999f51c740d0541c53d223518e5e4bb482d996 (diff) | |
download | plus-stripped1.1.9.18.tar.gz plus-stripped1.1.9.18.tar.bz2 plus-stripped1.1.9.18.tar.xz plus-stripped1.1.9.18.zip |
Merge branch 'master' into strippedstripped1.1.9.18
Conflicts:
src/guichan/cliprectangle.cpp
src/guichan/focushandler.cpp
src/guichan/gui.cpp
src/guichan/include/guichan/cliprectangle.hpp
src/guichan/include/guichan/inputevent.hpp
src/guichan/include/guichan/keyevent.hpp
src/guichan/include/guichan/mouseevent.hpp
src/guichan/include/guichan/widgets/button.hpp
src/guichan/include/guichan/widgets/checkbox.hpp
src/guichan/include/guichan/widgets/dropdown.hpp
src/guichan/include/guichan/widgets/radiobutton.hpp
src/guichan/include/guichan/widgets/slider.hpp
src/guichan/include/guichan/widgets/tab.hpp
src/guichan/include/guichan/widgets/tabbedarea.hpp
src/guichan/include/guichan/widgets/textfield.hpp
src/guichan/include/guichan/widgets/window.hpp
src/guichan/inputevent.cpp
src/guichan/keyevent.cpp
src/guichan/mouseevent.cpp
src/guichan/widget.cpp
src/guichan/widgets/button.cpp
src/guichan/widgets/checkbox.cpp
src/guichan/widgets/dropdown.cpp
src/guichan/widgets/radiobutton.cpp
src/guichan/widgets/slider.cpp
src/guichan/widgets/tab.cpp
src/guichan/widgets/tabbedarea.cpp
src/guichan/widgets/textfield.cpp
src/guichan/widgets/window.cpp
Diffstat (limited to 'src/gui/widgets/itemcontainer.cpp')
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 82 |
1 files changed, 79 insertions, 3 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 91b674018..2cc80ee8b 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), @@ -456,6 +513,9 @@ void ItemContainer::updateMatrix() int i = 0; int j = 0; + std::string temp = mName; + toLower(temp); + for (unsigned idx = 0; idx < mInventory->getSize(); idx ++) { Item *item = mInventory->getItem(idx); @@ -463,7 +523,15 @@ void ItemContainer::updateMatrix() if (!item || item->getId() == 0 || !item->isHaveTag(mTag)) continue; - sortedItems.push_back(new ItemIdPair(idx, item)); + if (mName.empty()) + { + sortedItems.push_back(new ItemIdPair(idx, item)); + continue; + } + std::string name = item->getInfo().getName(); + toLower(name); + if (name.find(temp) != std::string::npos) + sortedItems.push_back(new ItemIdPair(idx, item)); } switch (mSortType) @@ -477,9 +545,18 @@ 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*>::iterator iter; + std::vector<ItemIdPair*>::const_iterator iter; for (iter = sortedItems.begin(); iter != sortedItems.end(); ++iter) { if (j >= mGridRows) @@ -608,6 +685,5 @@ void ItemContainer::setFilter (int tag) void ItemContainer::setSortType (int sortType) { mSortType = sortType; - logger->log("setSortType: %d", sortType); updateMatrix(); } |