diff options
author | Fedja Beader <fedja@protonmail.ch> | 2024-02-11 03:54:47 +0000 |
---|---|---|
committer | Jesusalva Jesusalva <jesusalva@themanaworld.org> | 2024-02-11 03:54:47 +0000 |
commit | ca03d2741ee3c5976b548870f3a844c7fe62e85f (patch) | |
tree | 11419e69431b9db78c9deba13492bfa8f35fb083 /src/gui/widgets | |
parent | 9e076e849643a8decd8125ad3576a31c806206c4 (diff) | |
download | manaverse-ca03d2741ee3c5976b548870f3a844c7fe62e85f.tar.gz manaverse-ca03d2741ee3c5976b548870f3a844c7fe62e85f.tar.bz2 manaverse-ca03d2741ee3c5976b548870f3a844c7fe62e85f.tar.xz manaverse-ca03d2741ee3c5976b548870f3a844c7fe62e85f.zip |
Total weight sorting
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index a88c7798c..af1d24397 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -96,9 +96,9 @@ namespace if ((item1 == nullptr) || (item2 == nullptr)) return false; - const std::string name1 = item1->getInfo().getName( + const std::string& name1 = item1->getInfo().getName( item1->getColor()); - const std::string name2 = item2->getInfo().getName( + const std::string& name2 = item2->getInfo().getName( item2->getColor()); if (name1 == name2) { @@ -146,9 +146,9 @@ namespace const int w2 = pair2->mItem->getInfo().getWeight(); if (w1 == w2) { - const std::string name1 = + const std::string& name1 = pair1->mItem->getInfo().getName(); - const std::string name2 = + const std::string& name2 = pair2->mItem->getInfo().getName(); if (name1 == name2) { @@ -161,6 +161,38 @@ namespace } } itemWeightInvSorter; + class SortItemWeightTimesAmountFunctor final + { + public: + A_DEFAULT_COPY(SortItemWeightTimesAmountFunctor) + + bool operator() (const ItemIdPair *const pair1, + const ItemIdPair *const pair2) const + { + if ((pair1->mItem == nullptr) || (pair2->mItem == nullptr)) + return false; + + const int w1 = pair1->mItem->getInfo().getWeight() + * pair1->mItem->getQuantity(); + const int w2 = pair2->mItem->getInfo().getWeight() + * pair2->mItem->getQuantity(); + if (w1 == w2) + { + const std::string& name1 = + pair1->mItem->getInfo().getName(); + const std::string& name2 = + pair2->mItem->getInfo().getName(); + if (name1 == name2) + { + return pair1->mItem->getInvIndex() < + pair2->mItem->getInvIndex(); + } + return name1 < name2; + } + return w1 < w2; + } + } itemWeightTimesAmountInvSorter; + class SortItemAmountFunctor final { public: @@ -176,9 +208,9 @@ namespace const int c2 = pair2->mItem->getQuantity(); if (c1 == c2) { - const std::string name1 = + const std::string& name1 = pair1->mItem->getInfo().getName(); - const std::string name2 = + const std::string& name2 = pair2->mItem->getInfo().getName(); if (name1 == name2) { @@ -208,8 +240,8 @@ namespace const ItemDbTypeT t2 = info2.getType(); if (t1 == t2) { - const std::string &name1 = info1.getName(); - const std::string &name2 = info2.getName(); + const std::string& name1 = info1.getName(); + const std::string& name2 = info2.getName(); if (name1 == name2) { return pair1->mItem->getInvIndex() < @@ -1229,10 +1261,14 @@ int ItemContainer::updateMatrix() break; case 4: std::sort(sortedItems.begin(), sortedItems.end(), - itemAmountInvSorter); + itemWeightTimesAmountInvSorter); break; case 5: std::sort(sortedItems.begin(), sortedItems.end(), + itemAmountInvSorter); + break; + case 6: + std::sort(sortedItems.begin(), sortedItems.end(), itemTypeInvSorter); break; } |