From 14d406cdcfabf77b6fc1fbce0d381bcdecbb0e94 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 30 Jul 2011 22:21:31 +0000 Subject: Improved trade menu. --- src/client/inventorylistview.cc | 74 ++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 12 deletions(-) (limited to 'src/client/inventorylistview.cc') diff --git a/src/client/inventorylistview.cc b/src/client/inventorylistview.cc index 8ec2c82..5b1dbde 100644 --- a/src/client/inventorylistview.cc +++ b/src/client/inventorylistview.cc @@ -8,6 +8,9 @@ #include "client/inventorylistview.h" #include "ui/listitem.h" #include "ui/paint.h" +#include "ui/ui.h" + +#include namespace client { @@ -61,25 +64,72 @@ void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType std::ostringstream str; - if (item->amount() == 0) { - str << "^N"; - } - str << item->info()->name().c_str(); + if (inventory == core::localcontrol()->inventory()) { + + // special rules for own ship inventory + // retreive price from the trader + const core::Item *trader_item = (core::localplayer()->view() && core::localplayer()->view()->inventory() ? core::localplayer()->view()->inventory()->find(item->info()) : 0); + if (!trader_item) { + // not sold here + str << "^N"; + } + + str << item->info()->name(); + + std::ostringstream str_amount; + str_amount << item->amount(); + str << '\n' << aux::pad_right(str_amount.str(), 10); + + if (trader_item) { + std::ostringstream std_price; + std_price << trader_item->price() << " credits"; + str << aux::pad_left(std_price.str(), 14); + } + + if (trader_item) { + sortkey.assign("+"); + } else { + sortkey.assign("-"); + } + + + } else { - if (item->amount() > 0) { - str << " (" << item->amount() << ")"; - } + if (item->amount() == 0) { + str << "^N"; + } + + str << item->info()->name(); + + if (item->amount() > 0) { + std::ostringstream str_amount; + str_amount << item->amount(); + str << '\n' << aux::pad_right(str_amount.str(), 10); + + std::ostringstream std_price; + std_price << item->price() << " credits"; + str << aux::pad_left(std_price.str(), 14); + + } else { + std::ostringstream std_price; + std_price << item->price() << " credits"; + str << '\n' << aux::pad_left(std_price.str(), 24); + } + + + if (item->amount() == 0) { + sortkey.assign("-"); + } else { + sortkey.assign("+"); + } - if (item->amount() == 0) { - sortkey.assign("-"); - } else { - sortkey.assign("+"); } sortkey.append(item->info()->label()); listitem = new ui::ListItem(this, str.str().c_str()); - listitem->set_height(listitem->font()->height() * 2.0f); + listitem->set_font(ui::root()->font_tiny()); + listitem->set_height(listitem->font()->height() * 3.0f); listitem->set_item(item); listitem->set_info(item->info()); listitem->set_sortkey(sortkey); -- cgit v1.2.3