summaryrefslogtreecommitdiff
path: root/src/gui/inventorywindow.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-09-08 03:15:52 +0300
committerAndrei Karas <akaras@inbox.ru>2011-09-08 03:23:43 +0300
commitf1c17766c66394ce875854430f8f028c0fa5b3a5 (patch)
treed42df4e515bff99c577d44a381dbb143d21833e9 /src/gui/inventorywindow.cpp
parent327c7e01b95263961d1e3ecd450939de01262346 (diff)
downloadmv-f1c17766c66394ce875854430f8f028c0fa5b3a5.tar.gz
mv-f1c17766c66394ce875854430f8f028c0fa5b3a5.tar.bz2
mv-f1c17766c66394ce875854430f8f028c0fa5b3a5.tar.xz
mv-f1c17766c66394ce875854430f8f028c0fa5b3a5.zip
Add additional sorting methods to inventory:
by weight, by amount, by type.
Diffstat (limited to 'src/gui/inventorywindow.cpp')
-rw-r--r--src/gui/inventorywindow.cpp53
1 files changed, 42 insertions, 11 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index d0454c4e1..a8c003019 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -38,6 +38,7 @@
#include "gui/widgets/button.h"
#include "gui/widgets/container.h"
+#include "gui/widgets/dropdown.h"
#include "gui/widgets/inventoryfilter.h"
#include "gui/widgets/itemcontainer.h"
#include "gui/widgets/label.h"
@@ -62,6 +63,34 @@
#include "debug.h"
+const char *SORT_NAME[6] =
+{
+ N_("default"),
+ N_("by name"),
+ N_("by id"),
+ N_("by weight"),
+ N_("by amount"),
+ N_("by type")
+};
+
+class SortListModel : public gcn::ListModel
+{
+public:
+ virtual ~SortListModel()
+ { }
+
+ virtual int getNumberOfElements()
+ { return 6; }
+
+ virtual std::string getElementAt(int i)
+ {
+ if (i >= getNumberOfElements() || i < 0)
+ return _("???");
+
+ return gettext(SORT_NAME[i]);
+ }
+};
+
InventoryWindow::WindowList InventoryWindow::instances;
InventoryWindow::InventoryWindow(Inventory *inventory):
@@ -109,9 +138,9 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
mFilter->addActionListener(this);
mFilter->setActionEventId("tag_");
- mSorter = new InventoryFilter("sorter_" + getWindowName(), 20, 0);
- mSorter->addActionListener(this);
- mSorter->setActionEventId("sort_");
+ mSortModel = new SortListModel();
+ mSortDropDown = new DropDown(mSortModel, this, "sort");
+ mSortDropDown->setSelected(0);
mFilterLabel = new Label(_("Filter:"));
mSorterLabel = new Label(_("Sort:"));
@@ -120,10 +149,6 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
for (unsigned f = 0; f < tags.size(); f ++)
mFilter->addButton(tags[f]);
- mSorter->addButton(_("na"), "na");
- mSorter->addButton(_("az"), "az");
- mSorter->addButton(_("id"), "id");
-
if (isMainInventory())
{
std::string equip = _("Equip");
@@ -154,7 +179,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
place(4, 0, mSlotsLabel, 1).setPadding(3);
place(5, 0, mSlotsBar, 2);
place(7, 0, mSorterLabel, 1);
- place(8, 0, mSorter, 3);
+ place(8, 0, mSortDropDown, 3);
place(0, 1, mFilterLabel, 1).setPadding(3);
place(1, 1, mFilter, 10).setPadding(3);
@@ -176,9 +201,9 @@ InventoryWindow::InventoryWindow(Inventory *inventory):
mCloseButton = new Button(_("Close"), "close", this);
place(0, 0, mSlotsLabel).setPadding(3);
- place(1, 0, mSlotsBar, 3);
- place(4, 0, mSorterLabel, 1);
- place(5, 0, mSorter, 2);
+ place(1, 0, mSlotsBar, 4);
+ place(5, 0, mSorterLabel, 1);
+ place(6, 0, mSortDropDown, 1);
place(0, 1, mFilterLabel, 1).setPadding(3);
place(1, 1, mFilter, 6).setPadding(3);
@@ -219,6 +244,8 @@ InventoryWindow::~InventoryWindow()
mInventory->removeInventoyListener(this);
if (!instances.empty())
instances.front()->updateDropButton();
+ delete mSortModel;
+ mSortModel = 0;
}
void InventoryWindow::action(const gcn::ActionEvent &event)
@@ -258,6 +285,10 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd, this, item);
}
+ else if (event.getId() == "sort")
+ {
+ mItems->setSortType(mSortDropDown->getSelected());
+ }
else if (!event.getId().find("tag_") && mItems)
{
std::string tagName = event.getId().substr(4);