Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/inventorywindow.cc127
-rw-r--r--src/client/inventorywindow.h15
2 files changed, 138 insertions, 4 deletions
diff --git a/src/client/inventorywindow.cc b/src/client/inventorywindow.cc
index f22a36d..0d78025 100644
--- a/src/client/inventorywindow.cc
+++ b/src/client/inventorywindow.cc
@@ -66,7 +66,13 @@ InventoryWindow::InventoryWindow(ui::Widget *parent) : ui::Window(parent)
inventorywindow_scrollpane->set_border(false);
inventorywindow_scrollpane->set_alignment(ui::AlignTop);
- inventorywindow_shipbutton = new ui::IconButton(this, "bitmaps/icons/button_ship");
+ inventorywindow_shipbutton = new ui::IconButton(this, "bitmaps/icons/button_ship");
+ inventorywindow_ejectbutton = new ui::IconButton(this, "bitmaps/icons/button_eject");
+
+ // eject dialog
+ inventorywindow_ejectconfirmbutton = new ui::Button(inventorywindow_scrollpane, "Eject");
+ inventorywindow_ejectcancelbutton = new ui::Button(inventorywindow_scrollpane, "Cancel");
+ inventorywindow_ejectslider = new ui::Slider(inventorywindow_scrollpane);
hide();
}
@@ -200,6 +206,9 @@ void InventoryWindow::resize()
inventorywindow_shipbutton->set_size(icon_size, icon_size);
inventorywindow_shipbutton->set_location(inventorywindow_inventorytext->left(), height() - icon_size - padding);
+ inventorywindow_ejectbutton->set_size(icon_size, icon_size);
+ inventorywindow_ejectbutton->set_location(inventorywindow_inventorytext->right() - icon_size, height() - icon_size - padding);
+
// resize modelview
inventorywindow_modelview->set_size( width() - inventorywindow_listview->right() - padding * 2.0f ,ui::UI::elementsize.width());
inventorywindow_modelview->set_location(inventorywindow_listview->right() + padding, padding * 3.0f);
@@ -215,6 +224,27 @@ void InventoryWindow::resize()
// resize infotext
inventorywindow_scrollpane->set_size(inventorywindow_modelview->width(), height() - inventorywindow_modelview->bottom() - 2.0f * padding);
inventorywindow_scrollpane->set_location(inventorywindow_modelview->left(), inventorywindow_modelview->bottom() + padding);
+
+ // eject dialog buttons
+ inventorywindow_ejectslider->set_size(
+ inventorywindow_scrollpane->width() - ui::UI::elementsize.width(),
+ inventorywindow_ejectslider->font()->height()
+ );
+ inventorywindow_ejectslider->set_location(
+ (inventorywindow_scrollpane->width() - inventorywindow_ejectslider->width()) * 0.5f,
+ 0
+ );
+ inventorywindow_ejectconfirmbutton->set_size(ui::UI::elementsize);
+ inventorywindow_ejectconfirmbutton->set_location(
+ (inventorywindow_scrollpane->width() - ui::UI::elementsize.width() * 2.0f - padding) * 0.5f,
+ inventorywindow_ejectslider->bottom() + padding
+ );
+ inventorywindow_ejectcancelbutton->set_size(ui::UI::elementsize);
+ inventorywindow_ejectcancelbutton->set_location(
+ inventorywindow_ejectconfirmbutton->right() + padding,
+ inventorywindow_ejectslider->bottom() + padding
+ );
+
}
void InventoryWindow::draw()
@@ -251,18 +281,90 @@ void InventoryWindow::show()
Window::show();
}
+void InventoryWindow::show_eject_dialog(const core::Info *info, const int amount)
+{
+ if (!info || amount < 0)
+ return;
+
+ inventorywindow_modeltitlelabel->set_text("Eject Cargo");
+ inventorywindow_infotext.clear();
+
+ inventorywindow_ejectconfirmbutton->show();
+ inventorywindow_ejectcancelbutton->show();
+
+ inventorywindow_ejectslider->set_range(1, amount);
+ inventorywindow_ejectslider->set_value(amount);
+ inventorywindow_ejectslider->show();
+ show_eject_amount(amount);
+
+ //std::string text("Select amount to eject");
+ //inventorywindow_infotext.push_back(text);
+
+}
+
+void InventoryWindow::show_eject_amount(const int amount)
+{
+ std::ostringstream str;
+ str << "Eject Cargo";
+
+ if (amount > 0) {
+ str << " (";
+ str << inventorywindow_ejectslider->value();
+ str << ")";
+ }
+ inventorywindow_modeltitlelabel->set_text(str.str());
+}
+
+void InventoryWindow::act_eject()
+{
+ if (!inventorywindow_listview->selected()) {
+ return;
+ }
+ if (!inventorywindow_listview->selected()->item()) {
+ return;
+ }
+
+ std::ostringstream cmdstr;
+
+ cmdstr << "remote eject ";
+ cmdstr << inventorywindow_listview->selected()->item()->info()->type()->label() << " ";
+ cmdstr << inventorywindow_listview->selected()->item()->info()->label() << " ";
+ cmdstr << inventorywindow_ejectslider->value();
+
+ con_debug "Executing command '" << cmdstr.str() << "'" << std::endl;
+ core::CommandBuffer::exec(cmdstr.str());
+
+ show_item_info(0);
+}
+
+void InventoryWindow::show_item_info(const ui::ListItem *listitem)
+{
+ if (listitem) {
+ set_info(listitem->info(), listitem->item()->amount());
+ if (listitem->item()->amount()) {
+ inventorywindow_ejectbutton->enable();
+ }
+ } else {
+ set_info(0, 0);
+ }
+}
+
void InventoryWindow::set_info(const core::Info *info, const int amount)
{
inventorywindow_inforecord = info;
inventorywindow_infotext.clear();
inventorywindow_amount = amount;
+ inventorywindow_ejectbutton->disable();
+
+ inventorywindow_ejectconfirmbutton->hide();
+ inventorywindow_ejectcancelbutton->hide();
+ inventorywindow_ejectslider->hide();
if (!info) {
inventorywindow_modelview->set_modelname(0);
inventorywindow_modeltitlelabel->set_text("");
inventorywindow_modelnamelabel->set_text("");
} else {
-
core::game()->request_info(info->id());
inventorywindow_modelview->set_modelname(info->modelname());
inventorywindow_modelnamelabel->set_text(info->name());
@@ -286,6 +388,15 @@ bool InventoryWindow::on_emit(Widget *sender, const Event event, void *data)
inventorywindow_listview->deselect();
set_info(core::localcontrol() ? core::localcontrol()->info() : 0, 0);
inventorywindow_modeltitlelabel->set_text("Ship Info");
+ } else if (sender == inventorywindow_ejectbutton) {
+ if (inventorywindow_listview->selected()) {
+ show_eject_dialog(inventorywindow_listview->selected()->info(), inventorywindow_listview->selected()->item()->amount());
+ }
+ } else if (sender == inventorywindow_ejectcancelbutton) {
+ show_item_info(inventorywindow_listview->selected());
+ } else if (sender == inventorywindow_ejectconfirmbutton) {
+ // TODO do actual eject
+ act_eject();
} else if (sender == inventorywindow_closebutton) {
hide();
}
@@ -296,10 +407,18 @@ bool InventoryWindow::on_emit(Widget *sender, const Event event, void *data)
if (sender == inventorywindow_listview) {
inventorywindow_modeltitlelabel->set_text("Cargo Info");
- set_info(inventorywindow_listview->selected() ? inventorywindow_listview->selected()->info() : 0, inventorywindow_listview->selected()->item()->amount());
+ show_item_info(inventorywindow_listview->selected());
}
+
return true;
- }
+
+ } else if (event == ui::Widget::EventSliderChanged) {
+
+ if (sender == inventorywindow_ejectslider) {
+ show_eject_amount(inventorywindow_ejectslider->value());
+ }
+ return true;
+ }
return Window::on_emit(sender, event, data);
}
diff --git a/src/client/inventorywindow.h b/src/client/inventorywindow.h
index 32175b1..e32bf44 100644
--- a/src/client/inventorywindow.h
+++ b/src/client/inventorywindow.h
@@ -9,10 +9,12 @@
#include "core/info.h"
#include "core/inventory.h"
+#include "ui/button.h"
#include "ui/iconbutton.h"
#include "ui/listview.h"
#include "ui/modelview.h"
#include "ui/scrollpane.h"
+#include "ui/slider.h"
#include "ui/plaintext.h"
#include "ui/window.h"
@@ -49,6 +51,14 @@ private:
void set_info(const core::Info *info, const int amount);
+ void show_eject_dialog(const core::Info *info, const int amount);
+
+ void show_eject_amount(const int amount);
+
+ void act_eject();
+
+ void show_item_info(const ui::ListItem *listitem);
+
bool verify() const;
unsigned long inventorywindow_inventorytimestamp;
@@ -73,6 +83,11 @@ private:
ui::ScrollPane *inventorywindow_scrollpane;
ui::IconButton *inventorywindow_shipbutton;
+ ui::IconButton *inventorywindow_ejectbutton;
+ ui::Button *inventorywindow_ejectconfirmbutton;
+ ui::Button *inventorywindow_ejectcancelbutton;
+ ui::Slider *inventorywindow_ejectslider;
+
}; // class InventoryWindow
}