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/buymenu.cc52
-rw-r--r--src/client/buymenu.h2
-rw-r--r--src/client/map.cc10
-rw-r--r--src/client/playerview.cc16
-rw-r--r--src/client/trademenu.cc122
-rw-r--r--src/client/trademenu.h18
6 files changed, 155 insertions, 65 deletions
diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc
index c3878a8..a106659 100644
--- a/src/client/buymenu.cc
+++ b/src/client/buymenu.cc
@@ -9,7 +9,7 @@
#include "ui/paint.h"
#include "client/buymenu.h"
#include "core/info.h"
-#include "core/application.h"
+
namespace client
{
@@ -30,7 +30,7 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
menu_buywindow->set_border(true);
menu_namelabel = new ui::Label(menu_buywindow);
- menu_namelabel->set_label("infolabel");
+ menu_namelabel->set_label("label");
menu_namelabel->set_background(false);
menu_namelabel->set_border(false);
menu_namelabel->set_font(ui::root()->font_large());
@@ -60,35 +60,41 @@ BuyMenu::~BuyMenu()
}
-void BuyMenu::set_item(std::string const & itemtype, std::string const & itemname)
+void BuyMenu::set_item(core::Info *info)
{
- menu_itemtype.assign(itemtype);
- aux::to_label(menu_itemtype);
-
- menu_itemname.assign(itemname);
- aux::to_label(menu_itemname);
-
- menu_buybutton->set_command("remote buy " + menu_itemtype + ' ' + menu_itemname + "; view hide");
- menu_buybutton->set_label("buy " + menu_itemname);
-
menu_infotext.clear();
menu_namelabel->set_text(0);
menu_modelview->set_modelname(0);
- menu_inforecord = core::game()->info(menu_itemtype, menu_itemname);
+ // if the information timestamp is 0, the info is available
+ menu_inforecord = info;
- if (menu_inforecord) {
- menu_namelabel->set_text(menu_inforecord->name());
- menu_modelview->set_modelname(menu_inforecord->modelname());
-
+ if (!menu_inforecord) {
+ menu_buybutton->hide();
+ menu_modelview->hide();
+
+ menu_infotext.push_back("Information is not available");
+ menu_infotimestamp = 0;
+ } else {
for (core::Info::Text::const_iterator it = menu_inforecord->text().begin(); it != menu_inforecord->text().end(); it++) {
menu_infotext.push_back((*it));
}
+
+ menu_infotimestamp = menu_inforecord->timestamp();
+ if (menu_inforecord->type() && !menu_inforecord->timestamp()) {
+ menu_namelabel->set_text(menu_inforecord->name());
+ menu_modelview->set_modelname(menu_inforecord->modelname());
+
+ menu_buybutton->set_command("remote buy " + menu_inforecord->type()->label() + ' ' + menu_inforecord->label() + "; view hide");
+ menu_buybutton->set_label("buy " + menu_inforecord->name());
+
+ menu_buybutton->show();
+ menu_modelview->show();
+ } else {
+ menu_buybutton->hide();
+ menu_modelview->hide();
+ }
menu_infotimestamp = menu_inforecord->timestamp();
- } else {
- menu_infotext.push_back("Information is not available");
- menu_infotimestamp = 0;
- menu_inforecord = 0;
}
}
@@ -129,8 +135,8 @@ void BuyMenu::resize()
void BuyMenu::draw()
{
// update content if necessary
- if (menu_infotimestamp && menu_inforecord && (menu_infotimestamp != menu_inforecord->timestamp()))
- set_item(menu_itemtype, menu_itemname);
+ if (menu_inforecord && (menu_infotimestamp != menu_inforecord->timestamp()))
+ set_item(menu_inforecord);
}
bool BuyMenu::on_keypress(const int key, const unsigned int modifier)
diff --git a/src/client/buymenu.h b/src/client/buymenu.h
index 016f473..85801ce 100644
--- a/src/client/buymenu.h
+++ b/src/client/buymenu.h
@@ -26,7 +26,7 @@ public:
BuyMenu(ui::Widget *parent, const char * label = 0);
~BuyMenu();
- void set_item(std::string const & itemtype, std::string const & itemname);
+ void set_item(core::Info *info);
protected:
/// resize event
diff --git a/src/client/map.cc b/src/client/map.cc
index 34dcb40..46f96fd 100644
--- a/src/client/map.cc
+++ b/src/client/map.cc
@@ -244,11 +244,11 @@ void Map::draw()
gl::end();
gl::disable(GL_TEXTURE_2D);
- if (map_target != current_target) {
+ if (map_target != current_target ) {
// this makes sure the map target exists
set_target(current_target);
- } else if (map_infotimestamp && map_inforecord && (map_infotimestamp != map_inforecord->timestamp())) {
+ } else if (map_inforecord && (map_infotimestamp != map_inforecord->timestamp())) {
set_target(map_target);
}
}
@@ -265,7 +265,10 @@ void Map::set_target(const core::Entity *entity) {
map_targetlabel->set_text(map_target->name());
map_targetlabel->show();
- map_inforecord = map_target->info();
+ if (map_target->info())
+ map_inforecord = core::game()->info(map_target->info()->id());
+ else
+ map_inforecord = 0;
if (map_inforecord) {
for (core::Info::Text::const_iterator it = map_inforecord->text().begin(); it != map_inforecord->text().end(); it++) {
@@ -274,6 +277,7 @@ void Map::set_target(const core::Entity *entity) {
map_infotimestamp = map_inforecord->timestamp();
} else {
map_infotext.push_back("Information is not available");
+ map_infotimestamp = 0;
}
map_scrollpane->show();
diff --git a/src/client/playerview.cc b/src/client/playerview.cc
index de4c704..4be64d2 100644
--- a/src/client/playerview.cc
+++ b/src/client/playerview.cc
@@ -7,6 +7,8 @@
#include <string>
#include <sstream>
+#include "core/info.h"
+#include "core/application.h"
#include "audio/audio.h"
#include "client/playerview.h"
#include "ui/ui.h"
@@ -119,19 +121,19 @@ void PlayerView::show_menu(const std::string & args)
if (label.compare("buy") == 0) {
// buy menu, single item
- std::string itemtype;
- std::string itemname;
+ unsigned long id;
- if ((argstr >> itemtype) && (argstr >> itemname)) {
+ if (argstr >> id) {
// hide other menus
view_entitymenu->hide();
view_trademenu->hide();
+
+ // requesting the info through game makes sure it is retreived from the server
+ view_buymenu->set_item( core::game()->info(id) );
// show buy menu
- view_buymenu->set_item(itemtype, itemname);
- view_buymenu->show();
-
+ view_buymenu->show();
} else {
- con_print << "usage: view buy [string] [string] buy menu for item type and name" << std::endl;
+ con_print << "usage: view buy [infoid] show the buy menu for this kind of item" << std::endl;
}
} else if (label.compare("trade") == 0) {
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc
index 75b9d67..7e9be4f 100644
--- a/src/client/trademenu.cc
+++ b/src/client/trademenu.cc
@@ -7,6 +7,7 @@
#include "ui/button.h"
#include "ui/paint.h"
#include "ui/ui.h"
+#include "ui/listitem.h"
#include "client/trademenu.h"
namespace client
@@ -25,18 +26,30 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_tradewindow->set_label("tradewindow");
menu_tradewindow->set_border(true);
- menu_listview = new ui::ListView(menu_tradewindow);
- menu_listview->set_label("listview");
- menu_listview->set_background(false);
- menu_listview->set_border(true);
+ menu_namelabel = new ui::Label(menu_tradewindow);
+ menu_namelabel->set_label("label");
+ menu_namelabel->set_background(false);
+ menu_namelabel->set_border(false);
+ menu_namelabel->set_font(ui::root()->font_large());
+ menu_namelabel->set_alignment(ui::AlignCenter);
+ menu_namelabel->show();
+
+ menu_inventorylistview = new ui::ListView(menu_tradewindow);
+ menu_inventorylistview->set_label("inventorylistview");
+ menu_inventorylistview->set_background(false);
+ menu_inventorylistview->set_border(true);
+
+
+ menu_traderlistview = new ui::ListView(menu_tradewindow);
+ menu_traderlistview->set_label("traderlistview");
+ menu_traderlistview->set_background(false);
+ menu_traderlistview->set_border(true);
- menu_scrollpane = new ui::ScrollPane(menu_tradewindow, menu_infotext);
- menu_scrollpane->set_background(false);
- menu_scrollpane->set_border(true);
- menu_scrollpane->set_alignment(ui::AlignTop);
-
menu_closebutton = new ui::Button(menu_tradewindow, "Return", "view hide");
+ std::string test("test");
+ set_item_type(test);
+
hide();
}
@@ -45,6 +58,56 @@ TradeMenu::~TradeMenu()
}
+void TradeMenu::set_item_type(std::string const & itemtype)
+{
+ ui::ListItem *item_label = 0;
+
+ menu_namelabel->set_text(0);
+
+ // update inventorylistview
+ menu_inventorylistview->remove_children();
+
+ //core::Inventory *inventory = 0;
+
+
+ item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 1");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 2");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 3");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 4");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ item_label = new ui::ListItem(menu_inventorylistview, "Inventory item 5");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ menu_inventorylistview->event_resize();
+
+ // update traderlistview
+ menu_traderlistview->remove_children();
+
+ item_label = new ui::ListItem(menu_traderlistview, "Shop item 1");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ item_label = new ui::ListItem(menu_traderlistview, "Shop item 2");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ item_label = new ui::ListItem(menu_traderlistview, "Shop item 3");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ item_label = new ui::ListItem(menu_traderlistview, "Shop item 4");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ item_label = new ui::ListItem(menu_traderlistview, "Shop item 5");
+ item_label->set_height(item_label->font()->height() * 2.0f);
+
+ menu_traderlistview->event_resize();
+}
+
void TradeMenu::resize()
{
const float smallmargin = ui::UI::elementsize.height();
@@ -58,25 +121,36 @@ void TradeMenu::resize()
menu_tradewindow->set_location(smallmargin, smallmargin * 2.0f);
// resize label
- //menu_namelabel->set_size(menu_tradewindow->width() - fontmargin * 2.0f, menu_namelabel->font()->height());
- //menu_namelabel->set_location(fontmargin, fontmargin);
-
- // resize listview
- menu_listview->set_size(ui::UI::elementsize.width() * 1.5f, menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f);
- menu_listview->set_location(fontmargin, fontmargin * 3.0f);
-
- // resize infotext pane
- menu_scrollpane->set_size(menu_tradewindow->width() - ui::UI::elementsize.width() * 1.5f - fontmargin * 3.0f,
- menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f);
- menu_scrollpane->set_location(ui::UI::elementsize.width() * 1.5f + fontmargin * 2.0f, fontmargin * 3.0f);
+ menu_namelabel->set_size(menu_tradewindow->width() - fontmargin * 2.0f, menu_namelabel->font()->height());
+ menu_namelabel->set_location(fontmargin, fontmargin);
- // resize buttons
- //menu_buybutton->set_size(ui::UI::elementsize);
- //menu_buybutton->set_location(menu_tradewindow->width() * 0.5f - ui::UI::elementsize.width() - smallmargin * 2.0f, menu_tradewindow->height() - smallmargin * 1.5f);
+ // resize inventory listview
+ menu_inventorylistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f);
+ menu_inventorylistview->set_location(fontmargin, fontmargin * 3.0f);
+ // resize trader listview
+ menu_traderlistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - smallmargin * 2.0f - fontmargin * 3.0f);
+ menu_traderlistview->set_location(menu_tradewindow->width() - menu_traderlistview->width() - fontmargin, fontmargin * 3.0f);
+
+ // resize close button
menu_closebutton->set_size(ui::UI::elementsize);
- //menu_closebutton->set_location(menu_tradewindow->width() * 0.5f + smallmargin * 2.0f, menu_tradewindow->height() - smallmargin * 1.5f);
menu_closebutton->set_location(0.5f * (menu_tradewindow->width() - ui::UI::elementsize.width()), menu_tradewindow->height() - smallmargin * 1.5f );
}
+bool TradeMenu::on_emit(Widget *sender, const Event event, void *data)
+{
+ if (event == ui::Widget::EventListItemClicked) {
+ if (sender->parent() == menu_inventorylistview) {
+ // item from inventory selected
+ menu_namelabel->set_text("SELL " + static_cast<ui::ListItem *>(sender)->text());
+ } else if (sender->parent() == menu_traderlistview) {
+ // item from trader selected
+ menu_namelabel->set_text("BUY " + static_cast<ui::ListItem *>(sender)->text());
+ }
+ return true;
+ }
+
+ return ui::Window::on_emit(sender, event, data);
+}
+
}
diff --git a/src/client/trademenu.h b/src/client/trademenu.h
index 98cf71d..37823b1 100644
--- a/src/client/trademenu.h
+++ b/src/client/trademenu.h
@@ -23,21 +23,25 @@ public:
/// create a new trade menu
TradeMenu(ui::Widget *parent, const char * label = 0);
~TradeMenu();
+
+ /// set the item type to trade
+ void set_item_type(std::string const & itemtype);
protected:
- /// resize event
+ /// resize event handler
virtual void resize();
+
+ /// emit event handler
+ virtual bool on_emit(Widget *sender, const Event event, void *data);
private:
ui::Window *menu_tradewindow;
- ui::ListView *menu_listview;
- ui::ScrollPane *menu_scrollpane;
+ ui::ListView *menu_inventorylistview;
+ ui::ListView *menu_traderlistview;
ui::Button *menu_closebutton;
- core::Info *menu_inforecord;
- ui::Text menu_infotext;
-
- unsigned long menu_infotimestamp;
+ ui::Label *menu_namelabel;
+
};
}