From 8fda16c465f8ea9ad6c748d4a5a097ff360fe960 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 5 Oct 2013 15:17:44 +0300 Subject: Remember sort order in buy dialog between restarts. --- src/gui/windows/buydialog.cpp | 67 +++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 28 deletions(-) (limited to 'src/gui/windows/buydialog.cpp') diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index 44b143e50..39255a632 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -22,6 +22,7 @@ #include "gui/windows/buydialog.h" +#include "configuration.h" #include "shopitem.h" #include "units.h" @@ -314,6 +315,9 @@ void BuyDialog::init() instances.push_back(this); setVisible(true); + + if (mSortDropDown) + mSortDropDown->setSelected(config.getIntValue("buySortOrder")); } BuyDialog::~BuyDialog() @@ -351,6 +355,38 @@ void BuyDialog::addItem(const int id, const unsigned char color, mShopItemList->adjustSize(); } +void BuyDialog::sort() +{ + if (mSortDropDown && mShopItems) + { + std::vector &items = mShopItems->items(); + switch (mSortDropDown->getSelected()) + { + case 1: + std::sort(items.begin(), items.end(), itemPriceBuySorter); + break; + case 2: + std::sort(items.begin(), items.end(), itemNameBuySorter); + break; + case 3: + std::sort(items.begin(), items.end(), itemIdBuySorter); + break; + case 4: + std::sort(items.begin(), items.end(), itemWeightBuySorter); + break; + case 5: + std::sort(items.begin(), items.end(), itemAmountBuySorter); + break; + case 6: + std::sort(items.begin(), items.end(), itemTypeBuySorter); + break; + case 0: + default: + break; + } + } +} + void BuyDialog::action(const gcn::ActionEvent &event) { const std::string &eventId = event.getId(); @@ -361,34 +397,9 @@ void BuyDialog::action(const gcn::ActionEvent &event) } else if (eventId == "sort") { - if (mSortDropDown && mShopItems) - { - std::vector &items = mShopItems->items(); - switch (mSortDropDown->getSelected()) - { - case 1: - std::sort(items.begin(), items.end(), itemPriceBuySorter); - break; - case 2: - std::sort(items.begin(), items.end(), itemNameBuySorter); - break; - case 3: - std::sort(items.begin(), items.end(), itemIdBuySorter); - break; - case 4: - std::sort(items.begin(), items.end(), itemWeightBuySorter); - break; - case 5: - std::sort(items.begin(), items.end(), itemAmountBuySorter); - break; - case 6: - std::sort(items.begin(), items.end(), itemTypeBuySorter); - break; - case 0: - default: - break; - } - } + sort(); + if (mSortDropDown) + config.setValue("buySortOrder", mSortDropDown->getSelected()); return; } -- cgit v1.2.3-60-g2f50