diff options
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: |