diff options
author | Stijn Buys <ingar@osirion.org> | 2010-11-08 23:33:49 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-11-08 23:33:49 +0000 |
commit | baf6ad1f48ef08187f50247115c09a3612ebeec3 (patch) | |
tree | c3c81f530c09b027f9880c8434df82a033a33323 /src/client/inventorylistview.cc | |
parent | 106d0cb0cf884dd7a2920564852c001e13af1568 (diff) |
added sorting of listview items
Diffstat (limited to 'src/client/inventorylistview.cc')
-rw-r--r-- | src/client/inventorylistview.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/client/inventorylistview.cc b/src/client/inventorylistview.cc index a8d98f3..e41aea2 100644 --- a/src/client/inventorylistview.cc +++ b/src/client/inventorylistview.cc @@ -17,6 +17,7 @@ InventoryListView::InventoryListView(ui::Widget *parent) : ui::ListView (parent) listview_infotype = 0; listview_timestamp = 0; listview_infotimestamp = 0; + listview_showempty = false; set_inventory(0, 0); } @@ -54,19 +55,30 @@ void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType listview_infotimestamp = item->info()->timestamp(); } - if ((item->info()->type() == infotype) && (item->amount() != 0)) { + if ((item->info()->type() == infotype) && (listview_showempty || (item->amount() != 0))) { ui::ListItem *listitem = 0; + std::string sortkey; std::ostringstream str; str << item->info()->name().c_str(); - if (item->amount() > 0) { + if (item->amount() >= 0) { str << " (" << item->amount() << ")"; } + + if (item->amount() == 0) { + sortkey.assign("-"); + } else { + sortkey.assign("+"); + } + + sortkey.append(item->info()->label()); + listitem = new ui::ListItem(this, str.str().c_str()); listitem->set_height(listitem->font()->height() * 2.0f); listitem->set_item(item); listitem->set_info(item->info()); + listitem->set_sortkey(sortkey); // preserve previous selection during update if (item == selecteditem) { ui::ListView::select(listitem); @@ -75,6 +87,8 @@ void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType } } + sort(); + event_resize(); emit(EventListViewChanged); |