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/windows | |
parent | 9e076e849643a8decd8125ad3576a31c806206c4 (diff) | |
download | plus-ca03d2741ee3c5976b548870f3a844c7fe62e85f.tar.gz plus-ca03d2741ee3c5976b548870f3a844c7fe62e85f.tar.bz2 plus-ca03d2741ee3c5976b548870f3a844c7fe62e85f.tar.xz plus-ca03d2741ee3c5976b548870f3a844c7fe62e85f.zip |
Total weight sorting
Diffstat (limited to 'src/gui/windows')
-rw-r--r-- | src/gui/windows/buydialog.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index ac795eb10..c1d6ba958 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -146,6 +146,27 @@ namespace } } itemWeightBuySorter; + class SortItemWeightTimesAmountFunctor final + { + public: + A_DEFAULT_COPY(SortItemWeightTimesAmountFunctor) + + bool operator() (const ShopItem *const item1, + const ShopItem *const item2) const + { + if ((item1 == nullptr) || (item2 == nullptr)) + return false; + + const int weight1 = item1->getInfo().getWeight() + * item1->getQuantity(); + const int weight2 = item2->getInfo().getWeight() + * item2->getQuantity(); + if (weight1 == weight2) + return item1->getPrice() < item2->getPrice(); + return weight1 < weight2; + } + } itemWeightTimesAmountBuySorter; + class SortItemAmountFunctor final { public: @@ -489,9 +510,12 @@ void BuyDialog::sort() std::sort(items.begin(), items.end(), itemWeightBuySorter); break; case 5: - std::sort(items.begin(), items.end(), itemAmountBuySorter); + std::sort(items.begin(), items.end(), itemWeightTimesAmountBuySorter); break; case 6: + std::sort(items.begin(), items.end(), itemAmountBuySorter); + break; + case 7: std::sort(items.begin(), items.end(), itemTypeBuySorter); break; case 0: |