From 90dd756673b47eed42e0941838033ba9fae59e1c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 5 Oct 2013 14:45:04 +0300 Subject: Remember sort order in inventory and storage between restarts. --- src/gui/windows/inventorywindow.cpp | 42 +++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/gui/windows/inventorywindow.cpp') diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index e72945b99..dde1bf709 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -136,12 +136,28 @@ InventoryWindow::InventoryWindow(Inventory *const inventory): { setCaption(gettext(inventory->getName().c_str())); setWindowName(inventory->getName()); + switch (inventory->getType()) + { + case Inventory::INVENTORY: + case Inventory::CART: + case Inventory::TRADE: + case Inventory::NPC: + default: + mSortDropDown->setSelected(config.getIntValue( + "inventorySortOrder")); + break; + case Inventory::STORAGE: + mSortDropDown->setSelected(config.getIntValue( + "storageSortOrder")); + break; + }; } else { // TRANSLATORS: inventory window name setCaption(_("Inventory")); setWindowName("Inventory"); + mSortDropDown->setSelected(0); } listen(CHANNEL_ATTRIBUTES); @@ -173,8 +189,6 @@ InventoryWindow::InventoryWindow(Inventory *const inventory): mFilter->addActionListener(this); mFilter->setActionEventId("tag_"); - mSortDropDown->setSelected(0); - StringVect tags = ItemDB::getTags(); const size_t sz = tags.size(); for (size_t f = 0; f < sz; f ++) @@ -270,6 +284,7 @@ InventoryWindow::InventoryWindow(Inventory *const inventory): enableVisibleSound(true); slotsChanged(mInventory); + mItems->setSortType(mSortDropDown->getSelected()); widgetResized(gcn::Event(nullptr)); if (!isMainInventory()) setVisible(true); @@ -288,6 +303,28 @@ InventoryWindow::~InventoryWindow() mTextPopup = nullptr; } +void InventoryWindow::storeSortOrder() +{ + if (mInventory) + { + switch (mInventory->getType()) + { + case Inventory::INVENTORY: + case Inventory::CART: + case Inventory::TRADE: + case Inventory::NPC: + default: + config.setValue("inventorySortOrder", + mSortDropDown->getSelected()); + break; + case Inventory::STORAGE: + config.setValue("storageSortOrder", + mSortDropDown->getSelected()); + break; + }; + } +} + void InventoryWindow::action(const gcn::ActionEvent &event) { const std::string &eventId = event.getId(); @@ -337,6 +374,7 @@ void InventoryWindow::action(const gcn::ActionEvent &event) else if (eventId == "sort") { mItems->setSortType(mSortDropDown->getSelected()); + storeSortOrder(); return; } else if (eventId == "namefilter") -- cgit v1.2.3-60-g2f50