diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-10-05 15:17:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-10-05 15:17:44 +0300 |
commit | 8fda16c465f8ea9ad6c748d4a5a097ff360fe960 (patch) | |
tree | 8d4dcaf063751f201c828ca19da54d0d3a85ac84 | |
parent | f23f96aaf3e4fbfa44645a69ca57748a5570f70c (diff) | |
download | mv-8fda16c465f8ea9ad6c748d4a5a097ff360fe960.tar.gz mv-8fda16c465f8ea9ad6c748d4a5a097ff360fe960.tar.bz2 mv-8fda16c465f8ea9ad6c748d4a5a097ff360fe960.tar.xz mv-8fda16c465f8ea9ad6c748d4a5a097ff360fe960.zip |
Remember sort order in buy dialog between restarts.
-rw-r--r-- | src/commands.cpp | 1 | ||||
-rw-r--r-- | src/defaults.cpp | 1 | ||||
-rw-r--r-- | src/gui/windows/buydialog.cpp | 67 | ||||
-rw-r--r-- | src/gui/windows/buydialog.h | 2 | ||||
-rw-r--r-- | src/gui/windows/shopwindow.cpp | 2 | ||||
-rw-r--r-- | src/net/eathena/buysellhandler.cpp | 1 | ||||
-rw-r--r-- | src/net/tmwa/buysellhandler.cpp | 1 |
7 files changed, 47 insertions, 28 deletions
diff --git a/src/commands.cpp b/src/commands.cpp index 788a20b98..8cb71739b 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1243,6 +1243,7 @@ impHandler0(createItems) } } } + dialog->sort(); } impHandler0(testsdlfont) diff --git a/src/defaults.cpp b/src/defaults.cpp index 9c5a3472f..02c0b8cbe 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -344,6 +344,7 @@ DefaultsData* getConfigDefaults() AddDEF("protectedItems", ""); AddDEF("inventorySortOrder", 0); AddDEF("storageSortOrder", 0); + AddDEF("buySortOrder", 0); return configData; } 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<ShopItem*> &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<ShopItem*> &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; } diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h index 5f19dd5ab..25d8bdb69 100644 --- a/src/gui/windows/buydialog.h +++ b/src/gui/windows/buydialog.h @@ -120,6 +120,8 @@ class BuyDialog final : public Window, */ void setVisible(bool visible); + void sort(); + /** * Returns true if any instances exist. */ diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index 7e6fbbb7c..082ebddb0 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -680,6 +680,8 @@ void ShopWindow::showList(const std::string &nick, std::string data) const } } } + if (buyDialog) + buyDialog->sort(); } void ShopWindow::processRequest(const std::string &nick, std::string data, diff --git a/src/net/eathena/buysellhandler.cpp b/src/net/eathena/buysellhandler.cpp index 361fe89a0..bd9264415 100644 --- a/src/net/eathena/buysellhandler.cpp +++ b/src/net/eathena/buysellhandler.cpp @@ -104,6 +104,7 @@ void BuySellHandler::processNpcBuy(Net::MessageIn &msg) const unsigned char color = 1; mBuyDialog->addItem(itemId, color, 0, value); } + mBuyDialog->sort(); } void BuySellHandler::processNpcSellResponse(Net::MessageIn &msg) const diff --git a/src/net/tmwa/buysellhandler.cpp b/src/net/tmwa/buysellhandler.cpp index 4fc80acb1..de4a03631 100644 --- a/src/net/tmwa/buysellhandler.cpp +++ b/src/net/tmwa/buysellhandler.cpp @@ -111,6 +111,7 @@ void BuySellHandler::processNpcBuy(Net::MessageIn &msg) color = msg.readInt8(); mBuyDialog->addItem(itemId, color, 0, value); } + mBuyDialog->sort(); } void BuySellHandler::processNpcSellResponse(Net::MessageIn &msg) const |