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.cc39
-rw-r--r--src/client/inventorylistview.h11
-rw-r--r--src/client/trademenu.cc50
-rw-r--r--src/client/trademenu.h4
4 files changed, 91 insertions, 13 deletions
diff --git a/src/client/inventorylistview.cc b/src/client/inventorylistview.cc
index 1b46fd0..d2752d6 100644
--- a/src/client/inventorylistview.cc
+++ b/src/client/inventorylistview.cc
@@ -11,17 +11,23 @@ namespace client {
InventoryListView::InventoryListView(ui::Widget *parent) : ui::ListView (parent)
{
+ listview_timestamp = 0;
set_inventory(0, 0);
}
InventoryListView::~InventoryListView() {
}
-void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType *info_type)
+void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType *infotype)
{
remove_children();
- if (!inventory || !info_type) {
+ listview_inventory = inventory;
+ listview_infotype = infotype;
+
+ const core::Item *selecteditem = (selected() ? selected()->item() : 0);
+
+ if (!inventory || !infotype) {
return;
}
@@ -31,15 +37,38 @@ void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType
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() == info_type) {
- ui::ListItem *listitem = 0;
- listitem = new ui::ListItem(this, item->info()->name().c_str());
+ if (item->info() && (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();
}
+void InventoryListView::draw()
+{
+ if (listview_timestamp != listview_inventory->timestamp()) {
+ set_inventory(listview_inventory, listview_infotype);
+ }
+
+ ListView::draw();
+}
+
} // namespace client \ No newline at end of file
diff --git a/src/client/inventorylistview.h b/src/client/inventorylistview.h
index 82a9cc4..0d14072 100644
--- a/src/client/inventorylistview.h
+++ b/src/client/inventorylistview.h
@@ -19,7 +19,16 @@ public:
InventoryListView(ui::Widget *parent = 0);
~InventoryListView();
- void set_inventory(core::Inventory *inventory, core::InfoType *info_type);
+ void set_inventory(core::Inventory *inventory, core::InfoType *infotype);
+
+protected:
+
+ virtual void draw();
+
+private:
+ unsigned long listview_timestamp;
+ core::Inventory *listview_inventory;
+ core::InfoType *listview_infotype;
};
} // namespace client
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc
index 837ee87..d93864d 100644
--- a/src/client/trademenu.cc
+++ b/src/client/trademenu.cc
@@ -42,6 +42,15 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_inventorylistview->set_background(false);
menu_inventorylistview->set_border(true);
+ menu_inventorylabel = new ui::Label(menu_tradewindow);
+ menu_inventorylabel->set_label("label");
+ menu_inventorylabel->set_background(false);
+ menu_inventorylabel->set_border(false);
+ menu_inventorylabel->set_font(ui::root()->font_small());
+ menu_inventorylabel->set_alignment(ui::AlignLeft);
+
+
+
menu_modelview = new ui::ModelView(menu_tradewindow);
menu_modelview->set_label("modelview");
menu_modelview->set_background(false);
@@ -57,12 +66,19 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_traderlistview->set_background(false);
menu_traderlistview->set_border(true);
+ menu_traderlabel = new ui::Label(menu_tradewindow);
+ menu_traderlabel->set_label("label");
+ menu_traderlabel->set_background(false);
+ menu_traderlabel->set_border(false);
+ menu_traderlabel->set_font(ui::root()->font_small());
+ menu_traderlabel->set_alignment(ui::AlignLeft);
+
menu_closebutton = new ui::Button(menu_tradewindow, "Return", "view hide");
menu_buyallbutton = new ui::Button(menu_modelview, "<<");
menu_buybutton = new ui::Button(menu_modelview, "<");
- menu_sellallbutton = new ui::Button(menu_modelview, ">");
- menu_sellbutton = new ui::Button(menu_modelview, ">>");
+ menu_sellallbutton = new ui::Button(menu_modelview, ">>");
+ menu_sellbutton = new ui::Button(menu_modelview, ">");
std::string test("test");
@@ -99,7 +115,8 @@ void TradeMenu::set_item_type(core::InfoType *item_type)
void TradeMenu::set_item(ui::ListItem *item)
{
menu_infotext.clear();
- menu_namelabel->clear();
+ menu_namelabel->set_text("Trade");
+ menu_traderlabel->clear();
if (!item || !item->info()) {
menu_traderlistview->deselect();
@@ -135,6 +152,10 @@ void TradeMenu::set_item(ui::ListItem *item)
menu_buybutton->show();
menu_buybutton->set_command("remote buy " + item->info()->type()->label() + " " + item->info()->label() + " 1; ");
+ std::ostringstream str;
+ str << "Price: " << item->item()->price();
+ menu_traderlabel->set_text(str.str());
+
menu_sellallbutton->hide();
menu_sellbutton->hide();
@@ -177,9 +198,12 @@ void TradeMenu::resize()
menu_namelabel->set_location(fontmargin, fontmargin);
// resize inventory listview
- menu_inventorylistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f);
+ menu_inventorylistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 6.0f);
menu_inventorylistview->set_location(fontmargin, fontmargin * 3.0f);
+ menu_inventorylabel->set_size(menu_inventorylistview->width(), fontmargin);
+ menu_inventorylabel->set_location(menu_inventorylistview->left(), menu_inventorylistview->bottom() + fontmargin);
+
// resize modelview
menu_modelview->set_size(menu_tradewindow->width() - 2.0f * ui::UI::elementsize.width() - fontmargin * 4.0f, ui::UI::elementsize.width());
menu_modelview->set_location(fontmargin * 2.0f + ui::UI::elementsize.width(), fontmargin * 3.0f);
@@ -198,13 +222,16 @@ void TradeMenu::resize()
menu_sellbutton->set_location(menu_modelview->width() - 3.0f * fontmargin, menu_modelview->height() - fontmargin);
// resize scrollpane
- menu_scrollpane->set_size(menu_tradewindow->width() - 2.0f * ui::UI::elementsize.width() - fontmargin * 4.0f, menu_inventorylistview->height() - fontmargin - ui::UI::elementsize.width());
+ menu_scrollpane->set_size(menu_tradewindow->width() - 2.0f * ui::UI::elementsize.width() - fontmargin * 4.0f, menu_inventorylistview->height() + 2.0f * fontmargin - ui::UI::elementsize.width());
menu_scrollpane->set_location(fontmargin * 2.0f + ui::UI::elementsize.width(), fontmargin * 4.0f + ui::UI::elementsize.width());
// resize trader listview
- menu_traderlistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f);
+ menu_traderlistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 6.0f);
menu_traderlistview->set_location(menu_tradewindow->width() - menu_traderlistview->width() - fontmargin, fontmargin * 3.0f);
-
+
+ menu_traderlabel->set_size(menu_traderlistview->width(), fontmargin);
+ menu_traderlabel->set_location(menu_traderlistview->left(), menu_traderlistview->bottom() + fontmargin);
+
// resize close button
menu_closebutton->set_size(ui::UI::elementsize);
menu_closebutton->set_location(0.5f * (menu_tradewindow->width() - ui::UI::elementsize.width()), menu_tradewindow->height() - smallmargin * 1.5f );
@@ -220,4 +247,13 @@ bool TradeMenu::on_emit(Widget *sender, const Event event, void *data)
return ui::Window::on_emit(sender, event, data);
}
+void TradeMenu::draw()
+{
+ std::stringstream str;
+ str << "Credits: " << core::localplayer()->credits();
+ menu_inventorylabel->set_text(str.str());
+
+ Window::draw();
+}
+
}
diff --git a/src/client/trademenu.h b/src/client/trademenu.h
index 477a372..5f56a08 100644
--- a/src/client/trademenu.h
+++ b/src/client/trademenu.h
@@ -34,6 +34,8 @@ protected:
/// resize event handler
virtual void resize();
+ virtual void draw();
+
/// emit event handler
virtual bool on_emit(Widget *sender, const Event event, void *data);
@@ -43,6 +45,8 @@ private:
ui::Window *menu_tradewindow;
ui::Button *menu_closebutton;
ui::Label *menu_namelabel;
+ ui::Label *menu_inventorylabel;
+ ui::Label *menu_traderlabel;
ui::ModelView *menu_modelview;
ui::ScrollPane *menu_scrollpane;