Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-09-22 21:32:34 +0000
committerStijn Buys <ingar@osirion.org>2010-09-22 21:32:34 +0000
commita6f9773c358dd7d091ff64cbda504ab8d8066dd3 (patch)
tree226e23c4656957e908623ccda9d3d1c50240a0b4 /src/client/inventorylistview.cc
parentbbb43d1c15f2858573f5abb595aa62f8224e4d76 (diff)
full trading support for networked games
Diffstat (limited to 'src/client/inventorylistview.cc')
-rw-r--r--src/client/inventorylistview.cc81
1 files changed, 57 insertions, 24 deletions
diff --git a/src/client/inventorylistview.cc b/src/client/inventorylistview.cc
index d87ed2b..e2b613b 100644
--- a/src/client/inventorylistview.cc
+++ b/src/client/inventorylistview.cc
@@ -4,14 +4,20 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "core/application.h"
#include "client/inventorylistview.h"
#include "ui/listitem.h"
+#include "ui/paint.h"
namespace client {
InventoryListView::InventoryListView(ui::Widget *parent) : ui::ListView (parent)
{
+ listview_inventory = 0;
+ listview_infotype = 0;
listview_timestamp = 0;
+ listview_infotimestamp = 0;
+
set_inventory(0, 0);
}
@@ -22,55 +28,82 @@ void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType
{
remove_children();
+ deselect();
+
+ listview_timestamp = 0;
+ listview_infotimestamp = 0;
listview_inventory = inventory;
listview_infotype = infotype;
-
- const core::Item *selecteditem = (selected() ? selected()->item() : 0);
-
- if (!inventory || !infotype) {
+
+ if (!listview_inventory || !listview_infotype) {
return;
}
- // TODO scan the inventories and request updated infos
- // update when necessary
+ const core::Item *selecteditem = (selected() ? selected()->item() : 0);
+ listview_timestamp = inventory->timestamp();
for (core::Inventory::Items::const_iterator it = inventory->items().begin(); it != inventory->items().end(); it++) {
core::Item *item = (*it);
- if (item->info() && (item->info()->type() == infotype) && (item->amount() != 0) ) {
- ui::ListItem *listitem = 0;
+ if (item->info()) {
- std::ostringstream str;
- str << item->info()->name().c_str();
+ // this makes sure inventory info gets requested from the server
+ core::game()->request_info(item->info()->id());
- if (item->amount() > 0) {
- str << " (" << item->amount() << ")";
+ if (item->info()->timestamp() > listview_infotimestamp) {
+ listview_infotimestamp = item->info()->timestamp();
}
- 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());
- // preserve previous selection during update
- if (item == selecteditem) {
- ui::ListView::select(listitem);
+
+ if ((item->info()->type() == infotype) && (item->amount() != 0)) {
+ ui::ListItem *listitem = 0;
+
+ std::ostringstream str;
+ str << item->info()->name().c_str();
+
+ if (item->amount() > 0) {
+ str << " (" << item->amount() << ")";
+ }
+ 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());
+ // preserve previous selection during update
+ if (item == selecteditem) {
+ ui::ListView::select(listitem);
+ }
}
}
}
- listview_timestamp = inventory->timestamp();
-
event_resize();
emit(EventListViewChanged);
}
+bool InventoryListView::verify_inventory()
+{
+ for (core::Inventory::Items::const_iterator it = listview_inventory->items().begin(); it != listview_inventory->items().end(); it++) {
+ core::Item *item = (*it);
+ if (item->info() && (item->info()->timestamp() > listview_infotimestamp)) {
+ return false;
+ }
+ }
+ return true;
+}
+
void InventoryListView::draw()
{
- if (listview_inventory && (listview_timestamp != listview_inventory->timestamp())) {
- set_inventory(listview_inventory, listview_infotype);
+ if (listview_inventory && listview_infotype) {
+ // inventory was updated
+ if (listview_timestamp != listview_inventory->timestamp()) {
+ set_inventory(listview_inventory, listview_infotype);
+ // inventory info was updated
+ } else if (!verify_inventory()) {
+ set_inventory(listview_inventory, listview_infotype);
+ }
}
ListView::draw();
}
-} // namespace client \ No newline at end of file
+} // namespace client