Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/inventorylistview.cc74
-rw-r--r--src/client/inventorywindow.cc11
-rw-r--r--src/client/trademenu.cc147
-rw-r--r--src/client/trademenu.h1
4 files changed, 168 insertions, 65 deletions
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 <iomanip>
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);
diff --git a/src/client/inventorywindow.cc b/src/client/inventorywindow.cc
index 396c449..604145a 100644
--- a/src/client/inventorywindow.cc
+++ b/src/client/inventorywindow.cc
@@ -54,8 +54,8 @@ InventoryWindow::InventoryWindow(ui::Widget *parent) : ui::Window(parent)
inventorywindow_inventorytext = new ui::PlainText(this);
inventorywindow_inventorytext->set_label("inventorytext");
- inventorywindow_inventorytext->set_background(false);
- inventorywindow_inventorytext->set_border(false);
+ inventorywindow_inventorytext->set_background(true);
+ inventorywindow_inventorytext->set_border(true);
inventorywindow_inventorytext->set_font(ui::root()->font_small());
inventorywindow_scrollpane = new ui::ScrollPane(this, inventorywindow_infotext);
@@ -111,11 +111,12 @@ void InventoryWindow::update_inventory()
std::ostringstream str;
str << item->info()->name().c_str();
if (item->amount() > 0) {
- str << " (" << item->amount() << ")";
- }
+ str << '\n' << item->amount();
+ }
listitem = new ui::ListItem(inventorywindow_listview, 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());
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc
index 20117c7..d86a04a 100644
--- a/src/client/trademenu.cc
+++ b/src/client/trademenu.cc
@@ -36,11 +36,16 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_modelview->set_background(false);
menu_modelview->set_border(false);
- menu_slider = new ui::Slider(menu_tradewindow);
+ menu_slider = new ui::Slider(menu_modelview);
//menu_slider->set_background(false);
//menu_slider->set_border(true);
- menu_msgtext = new ui::Label(menu_tradewindow);
+ menu_modellabel = new ui::Label(menu_modelview);
+ menu_modellabel->set_background(false);
+ menu_modellabel->set_border(false);
+ menu_modellabel->set_alignment(ui::AlignCenter);
+
+ menu_msgtext = new ui::Label(menu_modelview);
menu_msgtext->set_label("label");
menu_msgtext->set_background(false);
menu_msgtext->set_border(false);
@@ -61,8 +66,8 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_inventorytext = new ui::PlainText(menu_tradewindow);
menu_inventorytext->set_label("inventorytext");
- menu_inventorytext->set_background(false);
- menu_inventorytext->set_border(false);
+ menu_inventorytext->set_background(true);
+ menu_inventorytext->set_border(true);
menu_inventorytext->set_font(ui::root()->font_small());
menu_scrollpane = new ui::ScrollPane(menu_tradewindow, menu_infotext);
@@ -78,11 +83,12 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_tradertext = new ui::PlainText(menu_tradewindow);
menu_tradertext->set_label("tradertext");
- menu_tradertext->set_background(false);
- menu_tradertext->set_border(false);
+ menu_tradertext->set_background(true);
+ menu_tradertext->set_border(true);
menu_tradertext->set_font(ui::root()->font_small());
menu_closebutton = new ui::Button(menu_tradewindow, "Return", "view hide");
+ menu_closebutton->hide();
menu_buybutton = new ui::Button(menu_tradewindow, "Buy");
menu_listitem = 0;
@@ -101,7 +107,7 @@ TradeMenu::~TradeMenu()
void TradeMenu::set_itemtype(core::InfoType *item_type)
{
// reset
- menu_namelabel->set_text(0);
+ menu_modellabel->set_text(0);
menu_itemtype = item_type;
core::Inventory *inventory_player = 0;
@@ -122,9 +128,17 @@ void TradeMenu::set_item(ui::ListItem *item)
{
menu_infotext.clear();
- menu_namelabel->set_text("TRADE");
+ std::string title;
+ if (core::localplayer()->view()) {
+ title.assign(core::localplayer()->view()->name());
+ title += ' ';
+ }
+
+ title.append ("TRADER");
+ aux::to_uppercase(title);
+ menu_namelabel->set_text(title);
- menu_tradertext->clear();
+ menu_tradertext->set_text("TRADER");
menu_msgtext->clear();
menu_msgtext->hide();
menu_slider->hide();
@@ -162,7 +176,6 @@ void TradeMenu::set_item(ui::ListItem *item)
if (item->parent() == menu_inventorylistview) {
// item in ship inventory selected (SELL)
- menu_buybutton->set_text("Sell");
menu_traderlistview->deselect();
const core::Item *trader_item = (menu_traderlistview->inventory() ? menu_traderlistview->inventory()->find(item->info()) : 0);
@@ -178,6 +191,8 @@ void TradeMenu::set_item(ui::ListItem *item)
std::ostringstream commandstr;
commandstr << "remote sell " << item->info()->type()->label() << " " << item->info()->label() << " " << amount;
menu_buybutton->set_command(commandstr.str());
+
+ menu_buybutton->set_text("Sell");
menu_buybutton->enable();
menu_buybutton->show();
@@ -189,6 +204,7 @@ void TradeMenu::set_item(ui::ListItem *item)
}
std::ostringstream str;
+ str << "TRADER" << '\n' << '\n';
str << "Price: " << std::setw(12) << (amount > 0 ? amount : 1) * trader_item->price() << '\n'
<< "Volume: " << std::setw(12) << (float)(amount > 0 ? amount : 1) * trader_item->info()->volume();
menu_tradertext->set_text(str.str());
@@ -197,17 +213,11 @@ void TradeMenu::set_item(ui::ListItem *item)
menu_msgtext->show();
}
- std::ostringstream labelstr;
- labelstr << "Sell " << item->info()->name();
- if (amount)
- labelstr << " (" << amount << ")";
- menu_namelabel->set_text(labelstr.str());
-
+ menu_modellabel->set_text(item->info()->name());
} else if (item->parent() == menu_traderlistview) {
// item in trader inventory selected (BUY)
- menu_buybutton->set_text("Buy");
menu_inventorylistview->deselect();
if (menu_inventorylistview->inventory()) {
@@ -229,6 +239,8 @@ void TradeMenu::set_item(ui::ListItem *item)
commandstr << "remote buy " << item->info()->type()->label() << " " << item->info()->label() << " " << amount;
menu_buybutton->set_command(commandstr.str());
+ menu_buybutton->set_text("Buy");
+
menu_buybutton->enable();
menu_buybutton->show();
}
@@ -247,17 +259,15 @@ void TradeMenu::set_item(ui::ListItem *item)
}
std::ostringstream str;
- str << "Price: " << std::setw(12) << (amount > 0 ? amount : 1) * item->item()->price() << '\n'
- << "Volume: " << std::setw(12) << (float) (amount > 0 ? amount : 1) * item->info()->volume();
+ str << "TRADER" << '\n' << '\n';
+ str << "Price: " << std::setw(12) << (amount > 0 ? (float) amount : 1.0f) * item->item()->price() << '\n'
+ << "Volume: " << std::setw(12) << (amount > 0 ? (float) amount : 1.0f) * item->info()->volume() << '\n';
+
menu_tradertext->set_text(str.str());
}
-
- std::ostringstream labelstr;
- labelstr << "Buy " << item->info()->name();
- if (amount > 0)
- labelstr << " (" << amount << ")";
- menu_namelabel->set_text(labelstr.str());
+
+ menu_modellabel->set_text(item->info()->name());
} else {
menu_traderlistview->deselect();
@@ -281,42 +291,80 @@ void TradeMenu::resize()
menu_namelabel->set_size(menu_tradewindow->width() - fontmargin * 2.0f, menu_namelabel->font()->height());
menu_namelabel->set_location(fontmargin, fontmargin);
- // resize inventory listview
- 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);
+ // resize player inventory text
+ menu_inventorytext->set_size(
+ ui::UI::elementsize.width(),
+ fontmargin * 3.0f
+ );
+ menu_inventorytext->set_location(fontmargin, menu_namelabel->bottom() + fontmargin);
+
+ // resize player inventory listview
+ menu_inventorylistview->set_size(
+ ui::UI::elementsize.width(),
+ menu_tradewindow->height() - menu_inventorytext->bottom() - 2.0f * fontmargin
+ );
+ menu_inventorylistview->set_location(
+ fontmargin,
+ menu_inventorytext->bottom() + fontmargin
+ );
- menu_inventorytext->set_size(menu_inventorylistview->width(), fontmargin * 2.0f);
- menu_inventorytext->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);
- // resize slider
- menu_slider->set_size(menu_modelview->width(), fontmargin);
- menu_slider->set_location(menu_modelview->left(), menu_modelview->bottom() - menu_slider->height());
+ // resize modelview title label
+ menu_modellabel->set_location(0, 0);
+ menu_modellabel->set_size(menu_modelview->width(), menu_modellabel->font()->height());
+ // resize slider
+ menu_slider->set_size(menu_modelview->width(), menu_slider->font()->height());
+ menu_slider->set_location(0, menu_modelview->height() - menu_slider->height());
+
// warning text
menu_msgtext->set_size(menu_slider->size());
menu_msgtext->set_location(menu_slider->location());
-
- // resize scrollpane
- 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 * 6.0f);
- menu_traderlistview->set_location(menu_tradewindow->width() - menu_traderlistview->width() - fontmargin, fontmargin * 3.0f);
- menu_tradertext->set_size(menu_traderlistview->width(), fontmargin * 2.0f);
- menu_tradertext->set_location(menu_traderlistview->left(), menu_traderlistview->bottom() + fontmargin);
-
+ // resize trader inventory text
+ menu_tradertext->set_size(
+ ui::UI::elementsize.width(),
+ fontmargin * 3.0f
+ );
+ menu_tradertext->set_location(
+ menu_tradewindow->width() - ui::UI::elementsize.width() - fontmargin,
+ menu_namelabel->bottom() + fontmargin
+ );
+
+ // resize trader inventory listview
+ menu_traderlistview->set_size(
+ ui::UI::elementsize.width(),
+ menu_tradewindow->height() - menu_tradertext->bottom() - 2.0f * fontmargin
+ );
+ menu_traderlistview->set_location(
+ menu_tradewindow->width() - ui::UI::elementsize.width() - fontmargin,
+ menu_tradertext->bottom() + 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);
-
- 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_buybutton->set_location(
+ menu_modelview->left() + (menu_modelview->width() - menu_buybutton->width()) * 0.5f,
+ menu_modelview->bottom() + fontmargin
+ );
+
+ // resize infotext scrollpane
+ menu_scrollpane->set_size(
+ menu_tradewindow->width() - 2.0f * ui::UI::elementsize.width() - fontmargin * 4.0f,
+ menu_tradewindow->height() - menu_buybutton->bottom() - fontmargin * 2.0f
+ );
+
+ menu_scrollpane->set_location(
+ fontmargin * 2.0f + ui::UI::elementsize.width(),
+ menu_buybutton->bottom() + fontmargin
+ );
+
+ //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);
}
bool TradeMenu::on_emit(Widget *sender, const Event event, void *data)
@@ -357,6 +405,9 @@ void TradeMenu::draw()
creditstr << core::localplayer()->credits();
std::stringstream str;
+
+ str << "INVENTORY" << '\n' << '\n';
+
str << "Credits: " << aux::pad_left(creditstr.str(),12);
if (core::localcontrol() && core::localcontrol()->inventory()) {
diff --git a/src/client/trademenu.h b/src/client/trademenu.h
index 61609e2..60aad55 100644
--- a/src/client/trademenu.h
+++ b/src/client/trademenu.h
@@ -54,6 +54,7 @@ private:
ui::PlainText *menu_inventorytext;
ui::PlainText *menu_tradertext;
ui::ModelView *menu_modelview;
+ ui::Label *menu_modellabel;
ui::ScrollPane *menu_scrollpane;
ui::Slider *menu_slider;
ui::Label *menu_msgtext;