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/inventorylistview.cc2
-rw-r--r--src/client/trademenu.cc206
-rw-r--r--src/client/trademenu.h10
3 files changed, 141 insertions, 77 deletions
diff --git a/src/client/inventorylistview.cc b/src/client/inventorylistview.cc
index 0126ff4..d87ed2b 100644
--- a/src/client/inventorylistview.cc
+++ b/src/client/inventorylistview.cc
@@ -60,6 +60,8 @@ void InventoryListView::set_inventory(core::Inventory *inventory, core::InfoType
listview_timestamp = inventory->timestamp();
event_resize();
+
+ emit(EventListViewChanged);
}
void InventoryListView::draw()
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc
index 47655f6..0b8fb64 100644
--- a/src/client/trademenu.cc
+++ b/src/client/trademenu.cc
@@ -34,6 +34,10 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_modelview->set_label("modelview");
menu_modelview->set_background(false);
menu_modelview->set_border(false);
+
+ menu_slider = new ui::Slider(menu_tradewindow);
+ menu_slider->set_background(false);
+ menu_slider->set_border(true);
menu_namelabel = new ui::Label(menu_tradewindow);
menu_namelabel->set_label("label");
@@ -71,14 +75,10 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
menu_tradertext->set_font(ui::root()->font_small());
menu_closebutton = new ui::Button(menu_tradewindow, "Return", "view hide");
-
- menu_buyallbutton = new ui::Button(menu_modelview, "<<");
- menu_buybutton = new ui::Button(menu_modelview, "<");
- menu_sellallbutton = new ui::Button(menu_modelview, ">>");
- menu_sellbutton = new ui::Button(menu_modelview, ">");
+ menu_buybutton = new ui::Button(menu_tradewindow, "Buy");
+ menu_listitem = 0;
- std::string test("test");
set_itemtype(0);
hide();
@@ -115,78 +115,130 @@ void TradeMenu::set_item(ui::ListItem *item)
menu_infotext.clear();
menu_namelabel->set_text("Trade");
menu_tradertext->clear();
+ menu_buybutton->hide();
+ menu_slider->hide();
+ if (item != menu_listitem) {
+ menu_slider->set_range(0, 2);
+ menu_slider->set_value(1);
+ menu_listitem = item;
+ }
+
if (!item || !item->info()) {
menu_traderlistview->deselect();
menu_inventorylistview->deselect();
menu_scrollpane->hide();
menu_modelview->hide();
+ menu_slider->set_range(0, 2);
+ menu_slider->set_value(1);
return;
}
- long amount = 1; // reserved
+ long amount = 0; // reserved
+
+ for (core::Info::Text::const_iterator it = item->info()->text().begin(); it != item->info()->text().end(); it++) {
+ menu_infotext.push_back((*it));
+ }
+
+ menu_scrollpane->show();
+ menu_modelview->set_modelname(item->info()->modelname());
+ menu_modelview->show();
if (item->parent() == menu_inventorylistview) {
- menu_traderlistview->deselect();
- // item in ship inventory selected (SELL)
- menu_namelabel->set_text("Sell " + item->info()->name());
- menu_buyallbutton->hide();
- menu_buybutton->hide();
-
- menu_sellallbutton->show();
- menu_sellallbutton->set_command("remote sell " + item->info()->type()->label() + " " + item->info()->label() + " -1");
-
- menu_sellbutton->show();
- menu_sellbutton->set_command("remote sell " + item->info()->type()->label() + " " + item->info()->label() + " 1");
+ // item in ship inventory selected (SELL)
+ menu_traderlistview->deselect();
+
const core::Item *trader_item = (menu_traderlistview->inventory() ? menu_traderlistview->inventory()->find(item->info()) : 0);
if (trader_item) {
+
+ const long max_amount = item->item()->amount();
+ if (max_amount > 0) {
+ menu_slider->set_range(1, max_amount);
+ menu_slider->show();
+
+ amount = menu_slider->value();
+
+ 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->show();
+ }
+
+ if (amount < 1) {
+ menu_buybutton->set_command("");
+ menu_buybutton->set_text("^1Can not sell");
+ menu_buybutton->show();
+ }
+
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();
+ str << "Price: " << std::setw(12) << (amount > 0 ? amount : 1) * trader_item->price() << '\n'
+ << "Volume: " << std::setw(12) << std::setprecision(2) << (float)(amount > 0 ? amount : 1) * trader_item->info()->volume();
menu_tradertext->set_text(str.str());
} else {
- menu_tradertext->set_text("^1Can not sell here");
+ menu_tradertext->set_text(" ^1Can not sell here");
}
+
+ std::ostringstream labelstr;
+ labelstr << "Sell " << item->info()->name();
+ if (amount)
+ labelstr << " (" << amount << ")";
+ menu_namelabel->set_text(labelstr.str());
+
} else if (item->parent() == menu_traderlistview) {
- menu_inventorylistview->deselect();
- // item in trader inventory selected (BUY)
- 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");
-
- std::ostringstream str;
- 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();
- menu_sellbutton->hide();
+ // item in trader inventory selected (BUY)
- } else {
- menu_traderlistview->deselect();
menu_inventorylistview->deselect();
-
- menu_buyallbutton->hide();
- menu_buybutton->hide();
-
- menu_sellallbutton->hide();
- menu_sellbutton->hide();
- }
+
+ if (menu_inventorylistview->inventory()) {
+
+ const long item_unit_price = item->item()->price();
+ const float item_unit_volume = item->info()->volume();
+ long max_amount = core::localcontrol()->inventory()->max_amount(core::localplayer()->credits(), item_unit_price, item_unit_volume);
+
+ if (item->item()->amount() >= 0) {
+ max_amount = math::min(max_amount, item->item()->amount());
+ }
+
+ if (max_amount > 0) {
+ menu_slider->set_range(1, max_amount);
+ menu_slider->show();
+ amount = menu_slider->value();
+
+ std::ostringstream commandstr;
+ commandstr << "remote buy " << item->info()->type()->label() << " " << item->info()->label() << " " << amount;
+ menu_buybutton->set_command(commandstr.str());
+ menu_buybutton->set_text("Buy");
+ menu_buybutton->show();
+ }
- if (item->info()) {
- for (core::Info::Text::const_iterator it = item->info()->text().begin(); it != item->info()->text().end(); it++) {
- menu_infotext.push_back((*it));
+ if (amount < 1) {
+ menu_buybutton->set_command("");
+ menu_buybutton->set_text("^1Can not buy");
+ menu_buybutton->show();
+ }
+
+ std::ostringstream str;
+ str << "Price: " << std::setw(12) << (amount > 0 ? amount : 1) * item->item()->price() << '\n'
+ << "Volume: " << std::setw(12) << std::setprecision(2) << (float) (amount > 0 ? amount : 1) * item->info()->volume();
+
+ menu_tradertext->set_text(str.str());
}
- menu_scrollpane->show();
- menu_modelview->set_modelname(item->info()->modelname());
- menu_modelview->show();
+ std::ostringstream labelstr;
+ labelstr << "Buy " << item->info()->name();
+ if (amount > 0)
+ labelstr << " (" << amount << ")";
+ menu_namelabel->set_text(labelstr.str());
+
+ } else {
+ menu_traderlistview->deselect();
+ menu_inventorylistview->deselect();
}
}
@@ -210,26 +262,17 @@ void TradeMenu::resize()
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);
- menu_inventorytext->set_size(menu_inventorylistview->width(), 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 buttons
- menu_buyallbutton->set_size(fontmargin, fontmargin);
- menu_buyallbutton->set_location(0, menu_modelview->height() - fontmargin);
+ // resize slider
+ menu_slider->set_size(menu_modelview->width(), fontmargin);
+ menu_slider->set_location(menu_modelview->left(), menu_modelview->bottom() - menu_slider->height());
- menu_buybutton->set_size(fontmargin, fontmargin);
- menu_buybutton->set_location(2.0f * fontmargin, menu_modelview->height() - fontmargin);
-
- menu_sellallbutton->set_size(fontmargin, fontmargin);
- menu_sellallbutton->set_location(menu_modelview->width() - fontmargin, menu_modelview->height() - fontmargin);
-
- menu_sellbutton->set_size(fontmargin, fontmargin);
- menu_sellbutton->set_location(menu_modelview->width() - 3.0f * fontmargin, menu_modelview->height() - fontmargin);
-
// 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());
@@ -238,18 +281,34 @@ void TradeMenu::resize()
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);
+ menu_tradertext->set_size(menu_traderlistview->width(), fontmargin * 2.0f);
menu_tradertext->set_location(menu_traderlistview->left(), menu_traderlistview->bottom() + fontmargin);
- // resize close button
+ // 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(0.5f * (menu_tradewindow->width() - ui::UI::elementsize.width()), menu_tradewindow->height() - smallmargin * 1.5f );
+ 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)
{
- if (event == ui::Widget::EventListItemClicked) {
- set_item(static_cast<ui::ListItem *>(sender));
+ if (event == ui::Widget::EventSliderChanged) {
+ // slider value changed
+ if (menu_traderlistview->selected()) {
+ set_item(menu_traderlistview->selected());
+ } else {
+ set_item(menu_inventorylistview->selected());
+ }
+ return true;
+ } else if (event == ui::Widget::EventListViewChanged) {
+ // listview changed
+ if (sender == menu_traderlistview) {
+ set_item(menu_traderlistview->selected());
+ } else if (sender == menu_inventorylistview) {
+ set_item(menu_inventorylistview->selected());
+ }
return true;
}
@@ -265,12 +324,15 @@ void TradeMenu::draw()
}
std::stringstream str;
- str << "Credit: " << std::setw(8) << core::localplayer()->credits();
-
+ str << "Credits: " << std::setw(12) << core::localplayer()->credits();
+
if (core::localcontrol() && core::localcontrol()->inventory()) {
core::Inventory *inventory = core::localcontrol()->inventory();
- str << '\n';
- str << "Cargo: " << std::setprecision(2) << std::setw(6) << inventory->capacity_used() << " of " << inventory->capacity();
+
+ std::stringstream cargostr;
+ cargostr << inventory->capacity_used() << " of " << inventory->capacity();
+
+ str << '\n' << "Cargo: " << aux::pad_left(cargostr.str(),12);
}
menu_inventorytext->set_text(str.str());
diff --git a/src/client/trademenu.h b/src/client/trademenu.h
index 4682ce7..e835043 100644
--- a/src/client/trademenu.h
+++ b/src/client/trademenu.h
@@ -13,6 +13,7 @@
#include "ui/listitem.h"
#include "ui/modelview.h"
#include "ui/plaintext.h"
+#include "ui/slider.h"
#include "ui/scrollpane.h"
#include "ui/widget.h"
#include "client/inventorylistview.h"
@@ -44,24 +45,23 @@ private:
void set_item(ui::ListItem *item);
ui::Window *menu_tradewindow;
- ui::Button *menu_closebutton;
ui::Label *menu_namelabel;
ui::PlainText *menu_inventorytext;
ui::PlainText *menu_tradertext;
ui::ModelView *menu_modelview;
ui::ScrollPane *menu_scrollpane;
+ ui::Slider *menu_slider;
- ui::Button *menu_buyallbutton;
+ ui::Button *menu_closebutton;
ui::Button *menu_buybutton;
- ui::Button *menu_sellallbutton;
- ui::Button *menu_sellbutton;
-
+
InventoryListView *menu_inventorylistview;
InventoryListView *menu_traderlistview;
ui::Text menu_infotext;
core::InfoType *menu_itemtype;
+ ui::ListItem *menu_listitem;
};
}