From ca03d2741ee3c5976b548870f3a844c7fe62e85f Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Sun, 11 Feb 2024 03:54:47 +0000 Subject: Total weight sorting --- src/gui/windows/buydialog.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/gui/windows/buydialog.cpp') 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: -- cgit v1.2.3-70-g09d2