From baf6ad1f48ef08187f50247115c09a3612ebeec3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 8 Nov 2010 23:33:49 +0000 Subject: added sorting of listview items --- src/client/inventorylistview.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/client/inventorylistview.cc') 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); -- cgit v1.2.3