diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/inventorylistview.h | 4 | ||||
-rw-r--r-- | src/client/playerview.cc | 4 | ||||
-rw-r--r-- | src/client/trademenu.cc | 30 | ||||
-rw-r--r-- | src/client/trademenu.h | 4 |
4 files changed, 33 insertions, 9 deletions
diff --git a/src/client/inventorylistview.h b/src/client/inventorylistview.h index 0d14072..ff10aa1 100644 --- a/src/client/inventorylistview.h +++ b/src/client/inventorylistview.h @@ -21,6 +21,10 @@ public: void set_inventory(core::Inventory *inventory, core::InfoType *infotype); + inline const core::Inventory *inventory() const { + return listview_inventory; + } + protected: virtual void draw(); diff --git a/src/client/playerview.cc b/src/client/playerview.cc index 2c2ecaa..b5629f0 100644 --- a/src/client/playerview.cc +++ b/src/client/playerview.cc @@ -146,9 +146,9 @@ void PlayerView::show_menu(const std::string & args) // hide other menus view_buymenu->hide(); view_entitymenu->hide(); - // show trade menu + // show trade menu + view_trademenu->set_itemtype(core::InfoType::find(typestr)); view_trademenu->show(); - view_trademenu->set_item_type(core::InfoType::find(typestr)); } else { con_print << "usage: view trade [string] show the trade menu for this type of items" << std::endl; } diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc index 7ac3e7c..47655f6 100644 --- a/src/client/trademenu.cc +++ b/src/client/trademenu.cc @@ -79,7 +79,7 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent std::string test("test"); - set_item_type(0); + set_itemtype(0); hide(); } @@ -89,10 +89,11 @@ TradeMenu::~TradeMenu() } -void TradeMenu::set_item_type(core::InfoType *item_type) +void TradeMenu::set_itemtype(core::InfoType *item_type) { // reset menu_namelabel->set_text(0); + menu_itemtype = item_type; core::Inventory *inventory_player = 0; core::Inventory *inventory_view = 0; @@ -123,11 +124,13 @@ void TradeMenu::set_item(ui::ListItem *item) menu_modelview->hide(); return; } + + long amount = 1; // reserved if (item->parent() == menu_inventorylistview) { menu_traderlistview->deselect(); // item in ship inventory selected (SELL) - menu_namelabel->set_text("Sell " + item->text()); + menu_namelabel->set_text("Sell " + item->info()->name()); menu_buyallbutton->hide(); menu_buybutton->hide(); @@ -137,20 +140,29 @@ void TradeMenu::set_item(ui::ListItem *item) menu_sellbutton->show(); menu_sellbutton->set_command("remote sell " + item->info()->type()->label() + " " + item->info()->label() + " 1"); + + const core::Item *trader_item = (menu_traderlistview->inventory() ? menu_traderlistview->inventory()->find(item->info()) : 0); + if (trader_item) { + std::ostringstream str; + str << "Price: " << std::setw(8) << amount * trader_item->price() << '\n' << "Volume: " << std::setw(7) << std::setprecision(2) << amount * trader_item->info()->volume(); + menu_tradertext->set_text(str.str()); + } else { + menu_tradertext->set_text("^1Can not sell here"); + } } else if (item->parent() == menu_traderlistview) { menu_inventorylistview->deselect(); // item in trader inventory selected (BUY) - menu_namelabel->set_text("Buy " + item->text()); + menu_namelabel->set_text("Buy " + item->info()->name()); menu_buyallbutton->show(); menu_buyallbutton->set_command("remote buy " + item->info()->type()->label() + " " + item->info()->label() + " -1"); menu_buybutton->show(); - menu_buybutton->set_command("remote buy " + item->info()->type()->label() + " " + item->info()->label() + " 1; "); + menu_buybutton->set_command("remote buy " + item->info()->type()->label() + " " + item->info()->label() + " 1"); std::ostringstream str; - str << "Price: " << std::setw(8) << item->item()->price() << '\n' << "Volume: " << std::setw(7) << std::setprecision(2) << item->info()->volume(); + str << "Price: " << std::setw(8) << amount * item->item()->price() << '\n' << "Volume: " << std::setw(7) << std::setprecision(2) << amount * item->info()->volume(); menu_tradertext->set_text(str.str()); menu_sellallbutton->hide(); @@ -246,6 +258,12 @@ 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 )) || + (menu_traderlistview->inventory() != (core::localplayer()->view() ? core::localplayer()->view()->inventory() : 0 ))) { + set_itemtype(menu_itemtype); + } + std::stringstream str; str << "Credit: " << std::setw(8) << core::localplayer()->credits(); diff --git a/src/client/trademenu.h b/src/client/trademenu.h index 6ee53b5..4682ce7 100644 --- a/src/client/trademenu.h +++ b/src/client/trademenu.h @@ -29,7 +29,7 @@ public: ~TradeMenu(); /// set the item type to trade - void set_item_type(core::InfoType *item_type); + void set_itemtype(core::InfoType *item_type); protected: /// resize event handler @@ -60,6 +60,8 @@ private: InventoryListView *menu_traderlistview; ui::Text menu_infotext; + + core::InfoType *menu_itemtype; }; } |