Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/inventorylistview.cc81
-rw-r--r--src/client/inventorylistview.h3
-rw-r--r--src/client/map.cc2
-rw-r--r--src/client/playerview.cc2
-rw-r--r--src/client/trademenu.cc12
-rw-r--r--src/client/video.cc4
6 files changed, 71 insertions, 33 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
diff --git a/src/client/inventorylistview.h b/src/client/inventorylistview.h
index ff10aa1..5d5a85f 100644
--- a/src/client/inventorylistview.h
+++ b/src/client/inventorylistview.h
@@ -30,7 +30,10 @@ protected:
virtual void draw();
private:
+ bool verify_inventory();
+
unsigned long listview_timestamp;
+ unsigned long listview_infotimestamp;
core::Inventory *listview_inventory;
core::InfoType *listview_infotype;
};
diff --git a/src/client/map.cc b/src/client/map.cc
index 46f96fd..54afc3f 100644
--- a/src/client/map.cc
+++ b/src/client/map.cc
@@ -266,7 +266,7 @@ void Map::set_target(const core::Entity *entity) {
map_targetlabel->show();
if (map_target->info())
- map_inforecord = core::game()->info(map_target->info()->id());
+ map_inforecord = core::game()->request_info(map_target->info()->id());
else
map_inforecord = 0;
diff --git a/src/client/playerview.cc b/src/client/playerview.cc
index b5629f0..7791a2a 100644
--- a/src/client/playerview.cc
+++ b/src/client/playerview.cc
@@ -129,7 +129,7 @@ void PlayerView::show_menu(const std::string & args)
view_trademenu->hide();
// requesting the info through game makes sure it is retreived from the server
- view_buymenu->set_item( core::game()->info(id) );
+ view_buymenu->set_item( core::game()->request_info(id));
// show buy menu
view_buymenu->show();
} else {
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc
index 0b8fb64..91724f7 100644
--- a/src/client/trademenu.cc
+++ b/src/client/trademenu.cc
@@ -80,6 +80,7 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_listitem = 0;
set_itemtype(0);
+ set_item(0);
hide();
}
@@ -97,17 +98,16 @@ void TradeMenu::set_itemtype(core::InfoType *item_type)
core::Inventory *inventory_player = 0;
core::Inventory *inventory_view = 0;
-
if (core::localcontrol())
- inventory_player = core::localcontrol()->inventory();
+ inventory_player = core::game()->request_inventory(core::localcontrol());
if(core::localplayer()->view())
- inventory_view = core::localplayer()->view()->inventory();
+ inventory_view = core::game()->request_inventory(core::localplayer()->view());
menu_inventorylistview->set_inventory(inventory_player, item_type);
menu_traderlistview->set_inventory(inventory_view, item_type);
- set_item(0);
+ //set_item(0);
}
void TradeMenu::set_item(ui::ListItem *item)
@@ -302,10 +302,12 @@ bool TradeMenu::on_emit(Widget *sender, const Event event, void *data)
set_item(menu_inventorylistview->selected());
}
return true;
+
} else if (event == ui::Widget::EventListViewChanged) {
// listview changed
if (sender == menu_traderlistview) {
set_item(menu_traderlistview->selected());
+
} else if (sender == menu_inventorylistview) {
set_item(menu_inventorylistview->selected());
}
@@ -318,7 +320,7 @@ bool TradeMenu::on_emit(Widget *sender, const Event event, void *data)
void TradeMenu::draw()
{
// sanity check
- if ((menu_inventorylistview->inventory() != (core::localcontrol() ? core::localcontrol()->inventory() : 0 )) ||
+ if ((menu_inventorylistview->inventory() != (core::localcontrol() ? core::localcontrol()->inventory() : 0 )) ||
(menu_traderlistview->inventory() != (core::localplayer()->view() ? core::localplayer()->view()->inventory() : 0 ))) {
set_itemtype(menu_itemtype);
}
diff --git a/src/client/video.cc b/src/client/video.cc
index 6eee36b..aa7ca9e 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -4,14 +4,14 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "core/core.h"
+#include "core/gameserver.h"
#include "client/video.h"
#include "client/input.h"
#include "client/client.h"
#include "client/targets.h"
#include "render/render.h"
#include "render/gl.h"
-#include "core/core.h"
-#include "core/gameserver.h"
#include "filesystem/filesystem.h"
#include "sys/sys.h"
#include "ui/ui.h"