From c62fe609a69058e2e30f757e9a06f72a98464232 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 17 Sep 2010 15:19:34 +0000 Subject: Bump network protocol version to 19, menudescriptions use the info infrastructure, client-side lazy info update requests. Updated ROADMAP --- src/client/buymenu.cc | 52 ++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'src/client/buymenu.cc') 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) -- cgit v1.2.3