diff options
author | Stijn Buys <ingar@osirion.org> | 2013-11-08 23:24:51 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2013-11-08 23:24:51 +0000 |
commit | cf4deaa44bebafc829e21704f186e01faa2f940d (patch) | |
tree | 28197eb15173adac890abd077083c7586fb2ce45 /src/client | |
parent | 566cd41a05579a51a58c6969304297d5951223be (diff) |
More inventory and trade menu fancyfication.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/inventorywindow.cc | 55 | ||||
-rw-r--r-- | src/client/inventorywindow.h | 2 | ||||
-rw-r--r-- | src/client/trademenu.cc | 231 | ||||
-rw-r--r-- | src/client/trademenu.h | 55 |
4 files changed, 189 insertions, 154 deletions
diff --git a/src/client/inventorywindow.cc b/src/client/inventorywindow.cc index 459d7c5..de27d13 100644 --- a/src/client/inventorywindow.cc +++ b/src/client/inventorywindow.cc @@ -56,11 +56,12 @@ InventoryWindow::InventoryWindow(ui::Widget *parent) : ui::Window(parent) //inventorywindow_listview->set_background(true); //inventorywindow_listview->set_border(true); - inventorywindow_inventorytext = new ui::PlainText(this); + inventorywindow_inventorytext = new ui::Label(this); inventorywindow_inventorytext->set_label("inventorytext"); inventorywindow_inventorytext->set_background(true); inventorywindow_inventorytext->set_border(true); inventorywindow_inventorytext->set_font(ui::root()->font_small()); + inventorywindow_inventorytext->set_alignment(ui::AlignLeft | ui::AlignTop); inventorywindow_shipbutton = new ui::IconButton(this, "bitmaps/icons/button_ship"); inventorywindow_ejectbutton = new ui::IconButton(this, "bitmaps/icons/button_eject"); @@ -82,9 +83,7 @@ InventoryWindow::InventoryWindow(ui::Widget *parent) : ui::Window(parent) inventorywindow_ejectconfirmbutton = new ui::Button(inventorywindow_scrollpane, "Eject"); inventorywindow_ejectcancelbutton = new ui::Button(inventorywindow_scrollpane, "Cancel"); inventorywindow_ejectslider = new ui::Slider(inventorywindow_scrollpane); - - - + hide(); } @@ -226,7 +225,7 @@ void InventoryWindow::resize() inventorywindow_closebutton->set_location(inventorywindow_titlelabel->width() - inventorywindow_closebutton->width(), 0); // resize inventory text - inventorywindow_inventorytext->set_size(ui::UI::elementsize.width(), padding * 2.0f); + inventorywindow_inventorytext->set_size(ui::UI::elementsize.width(), inventorywindow_inventorytext->font()->height() * 3.0f); inventorywindow_inventorytext->set_location(inventorywindow_titlelabel->left(), inventorywindow_titlelabel->bottom() + padding); // resize inventory listview @@ -263,27 +262,28 @@ void InventoryWindow::resize() // resize target info text inventorywindow_scrollpane->set_size(inventorywindow_modeltitlelabel->width(), pane->height() - inventorywindow_modeltitlelabel->bottom() - margin_vertical * 2.0f); inventorywindow_scrollpane->set_location(inventorywindow_modelview->left(), inventorywindow_modeltitlelabel->bottom() + margin_vertical); - } - // 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.0f - ); - 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 - ); + // eject dialog buttons + inventorywindow_ejectslider->set_size( + math::min(inventorywindow_scrollpane->width() - padding * 2.0f, ui::UI::elementsize.width() * 2.5f), + inventorywindow_ejectslider->font()->height() + ); + inventorywindow_ejectslider->set_location( + (inventorywindow_scrollpane->width() - inventorywindow_ejectslider->width()) * 0.5f, + padding - margin_vertical + ); + 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 + ); + + } } @@ -298,7 +298,7 @@ void InventoryWindow::draw() } std::stringstream str; - str << "Credits: " << std::setw(12) << core::localplayer()->credits(); + str << "Credits: " << std::setw(10) << core::localplayer()->credits(); if (core::localcontrol() && core::localcontrol()->inventory()) { core::Inventory *inventory = core::localcontrol()->inventory(); @@ -306,7 +306,7 @@ void InventoryWindow::draw() std::stringstream cargostr; cargostr << inventory->capacity_used() << " of " << inventory->capacity(); - str << '\n' << "Cargo: " << aux::pad_left(cargostr.str(),12); + str << '\n' << "Cargo: " << aux::pad_left(cargostr.str(), 12); } inventorywindow_inventorytext->set_text(str.str()); @@ -455,6 +455,7 @@ bool InventoryWindow::on_emit(Widget *sender, const Event event, void *data) show_eject_dialog(inventorywindow_listview->selected()->info(), inventorywindow_listview->selected()->item()->amount()); } } else if (sender == inventorywindow_ejectcancelbutton) { + inventorywindow_modelnamelabel->set_text("Cargo Info"); show_item_info(inventorywindow_listview->selected()); } else if (sender == inventorywindow_ejectconfirmbutton) { act_eject(); diff --git a/src/client/inventorywindow.h b/src/client/inventorywindow.h index b3f81e2..400754c 100644 --- a/src/client/inventorywindow.h +++ b/src/client/inventorywindow.h @@ -81,7 +81,7 @@ private: ui::Label *inventorywindow_modeltitlelabel; ui::Label *inventorywindow_modelnamelabel; - ui::PlainText *inventorywindow_inventorytext; + ui::Label *inventorywindow_inventorytext; ui::ScrollPane *inventorywindow_scrollpane; ui::IconButton *inventorywindow_shipbutton; diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc index 0023f1b..a16c5c4 100644 --- a/src/client/trademenu.cc +++ b/src/client/trademenu.cc @@ -21,62 +21,74 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent { set_border(false); set_background(false); - if (label) + if (label) { set_label(label); - else + } else { set_label("trademenu"); + } + // container window menu_tradewindow = new ui::Window(this); menu_tradewindow->set_label("tradewindow"); menu_tradewindow->set_border(true); menu_tradewindow->set_background(true); - menu_modelview = new ui::ModelView(menu_tradewindow); + // ---- center pane pane + menu_pane_center = new ui::Widget(menu_tradewindow); + menu_pane_center->set_background(true); + menu_pane_center->set_border(true); + + // modelview, add it first so it gets rendered before anything else + menu_modelview = new ui::ModelView(menu_pane_center); menu_modelview->set_label("modelview"); menu_modelview->set_background(false); menu_modelview->set_border(false); - - menu_slider = new ui::Slider(menu_modelview); - //menu_slider->set_background(false); - //menu_slider->set_border(true); - - menu_modellabel = new ui::Label(menu_modelview); + + menu_modellabel = new ui::Label(menu_pane_center); 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 = new ui::Label(menu_pane_center); menu_msgtext->set_label("label"); menu_msgtext->set_background(false); menu_msgtext->set_border(false); menu_msgtext->set_alignment(ui::AlignCenter); + + menu_slider = new ui::Slider(menu_pane_center); + menu_slider->set_background(false); + menu_slider->set_border(true); + + menu_buybutton = new ui::Button(menu_pane_center, "Buy"); + + menu_scrollpane = new ui::ScrollPane(menu_pane_center, menu_infotext); + menu_scrollpane->set_background(false); + menu_scrollpane->set_border(false); + menu_scrollpane->set_alignment(ui::AlignTop); - menu_namelabel = new ui::Label(menu_tradewindow); - menu_namelabel->set_label("label"); - menu_namelabel->set_background(false); - menu_namelabel->set_border(false); - menu_namelabel->set_font(ui::root()->font_large()); - menu_namelabel->set_alignment(ui::AlignCenter); - menu_namelabel->show(); + // window title lable + menu_titlelabel = new ui::Label(menu_tradewindow); + menu_titlelabel->set_label("label"); + menu_titlelabel->set_background(false); + menu_titlelabel->set_border(false); + menu_titlelabel->set_font(ui::root()->font_large()); + menu_titlelabel->set_alignment(ui::AlignCenter); + menu_titlelabel->show(); // close button - menu_closebutton = new ui::IconButton(menu_namelabel, "bitmaps/icons/window_close"); + menu_closebutton = new ui::IconButton(menu_titlelabel, "bitmaps/icons/window_close"); menu_inventorylistview = new InventoryListView(menu_tradewindow); menu_inventorylistview->set_label("inventorylistview"); //menu_inventorylistview->set_background(false); //menu_inventorylistview->set_border(true); - menu_inventorytext = new ui::PlainText(menu_tradewindow); + menu_inventorytext = new ui::Label(menu_tradewindow); menu_inventorytext->set_label("inventorytext"); 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); - menu_scrollpane->set_background(false); - menu_scrollpane->set_border(false); - menu_scrollpane->set_alignment(ui::AlignTop); + menu_inventorytext->set_alignment(ui::AlignLeft | ui::AlignTop); menu_traderlistview = new InventoryListView(menu_tradewindow); menu_traderlistview->set_label("traderlistview"); @@ -84,13 +96,12 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent //menu_traderlistview->set_border(true); menu_traderlistview->set_showempty(true); - menu_tradertext = new ui::PlainText(menu_tradewindow); + menu_tradertext = new ui::Label(menu_tradewindow); menu_tradertext->set_label("tradertext"); menu_tradertext->set_background(true); menu_tradertext->set_border(true); menu_tradertext->set_font(ui::root()->font_small()); - - menu_buybutton = new ui::Button(menu_tradewindow, "Buy"); + menu_inventorytext->set_alignment(ui::AlignLeft | ui::AlignTop); menu_listitem = 0; @@ -137,9 +148,10 @@ void TradeMenu::set_item(ui::ListItem *item) title.append ("TRADER"); aux::to_uppercase(title); - menu_namelabel->set_text(title); + menu_titlelabel->set_text(title); - menu_tradertext->set_text("TRADER"); + menu_tradertext->set_text(aux::pad_left("TRADER", 19)); + menu_modellabel->clear(); menu_msgtext->clear(); menu_msgtext->hide(); menu_slider->hide(); @@ -155,13 +167,27 @@ void TradeMenu::set_item(ui::ListItem *item) if (!item || !item->info()) { menu_traderlistview->deselect(); - menu_inventorylistview->deselect(); - - menu_scrollpane->hide(); + menu_inventorylistview->deselect(); menu_modelview->hide(); + menu_buybutton->hide(); + menu_slider->set_range(0, 2); menu_slider->set_value(1); + + if (core::localplayer()->view() && core::localplayer()->view()->info()) { + for (core::Info::Text::const_iterator it = core::localplayer()->view()->info()->text().begin(); it != core::localplayer()->view()->info()->text().end(); it++) { + menu_infotext.push_back((*it)); + } + menu_scrollpane->show(); + + menu_msgtext->set_text(core::localplayer()->view()->info()->name()); + menu_msgtext->show(); + } else { + menu_scrollpane->hide(); + } return; + } else { + menu_buybutton->show(); } long amount = 0; @@ -208,9 +234,9 @@ 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(); + str << aux::pad_left("TRADER", 19) << '\n' << '\n'; + str << "Price: " << std::setw(11) << (amount > 0 ? amount : 1) * trader_item->price() << '\n'; + str << "Volume: " << std::setw(11) << (float)(amount > 0 ? amount : 1) * trader_item->info()->volume(); menu_tradertext->set_text(str.str()); } else { menu_msgtext->set_text("^1Can not sell here"); @@ -262,10 +288,9 @@ void TradeMenu::set_item(ui::ListItem *item) } std::ostringstream str; - 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'; + str << aux::pad_left("TRADER", 19) << '\n' << '\n'; + str << "Price: " << std::setw(11) << (amount > 0 ? (float) amount : 1.0f) * item->item()->price() << '\n'; + str << "Volume: " << std::setw(11) << (amount > 0 ? (float) amount : 1.0f) * item->info()->volume() << '\n'; menu_tradertext->set_text(str.str()); } @@ -281,94 +306,82 @@ void TradeMenu::set_item(ui::ListItem *item) void TradeMenu::resize() { const float smallmargin = ui::UI::elementsize.height(); - const float fontmargin = ui::root()->font_large()->height(); + const float padding = ui::root()->font_large()->height(); // this menu takes the entire screen set_size(parent()->size()); - // resize the subwindow + // resize the container window menu_tradewindow->set_size(width() - smallmargin * 2.0f, height()- smallmargin * 4.0f); menu_tradewindow->set_location(smallmargin, smallmargin * 2.0f); + // ---- window title + // resize label - menu_namelabel->set_size(menu_tradewindow->width() - fontmargin * 2.0f, menu_namelabel->font()->height()); - menu_namelabel->set_location(fontmargin, fontmargin); + menu_titlelabel->set_size(menu_tradewindow->width() - padding * 2.0f, menu_titlelabel->font()->height()); + menu_titlelabel->set_location(padding, padding); // resize close button - menu_closebutton->set_size(menu_namelabel->font()->height(), menu_namelabel->font()->height()); - menu_closebutton->set_location(menu_namelabel->width() - menu_closebutton->width(), 0); + menu_closebutton->set_size(menu_titlelabel->font()->height(), menu_titlelabel->font()->height()); + menu_closebutton->set_location(menu_titlelabel->width() - menu_closebutton->width(), 0.0f); + + // ---- left // resize player inventory text - menu_inventorytext->set_size( - ui::UI::elementsize.width(), - fontmargin * 3.0f - ); - menu_inventorytext->set_location(fontmargin, menu_namelabel->bottom() + fontmargin); + menu_inventorytext->set_size(ui::UI::elementsize.width(), menu_inventorytext->font()->height() * 5.0f); + menu_inventorytext->set_location(padding, menu_titlelabel->bottom() + padding); // 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_inventorylistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - menu_inventorytext->bottom() - 2.0f * padding); + menu_inventorylistview->set_location(padding, menu_inventorytext->bottom() + padding); + // ---- right - // 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 trader inventory text + menu_tradertext->set_size(ui::UI::elementsize.width(), menu_inventorytext->font()->height() * 5.0f); + menu_tradertext->set_location(menu_tradewindow->width() - ui::UI::elementsize.width() - padding, menu_titlelabel->bottom() + padding); + + // resize trader inventory listview + menu_traderlistview->set_size(ui::UI::elementsize.width(), menu_tradewindow->height() - menu_tradertext->bottom() - 2.0f * padding); + menu_traderlistview->set_location(menu_tradewindow->width() - ui::UI::elementsize.width() - padding, menu_tradertext->bottom() + padding); + + // ---- center pane - // resize modelview title label - menu_modellabel->set_location(0, 0); - menu_modellabel->set_size(menu_modelview->width(), menu_modellabel->font()->height()); + menu_pane_center->set_size(menu_tradertext->left() - menu_inventorytext->right() - 2.0f * padding, menu_tradewindow->height() - menu_titlelabel->bottom() - 2.0f * padding); + menu_pane_center->set_location(menu_inventorytext->right() + padding, menu_titlelabel->bottom() + padding); - // resize slider - menu_slider->set_size(menu_modelview->width(), menu_slider->font()->height()); - menu_slider->set_location(0, menu_modelview->height() - menu_slider->height()); + { + const ui::Widget *pane = menu_pane_center; + const float margin_horizontal = pane->font()->width(); + const float margin_vertical = pane->font()->height() * 0.5f; + + // resize modelview title label + menu_modellabel->set_size(pane->width() - 2.0f * margin_horizontal, menu_modellabel->font()->height()); + menu_modellabel->set_location(margin_horizontal, margin_vertical); - // warning text - menu_msgtext->set_size(menu_slider->size()); - menu_msgtext->set_location(menu_slider->location()); - - // 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 modelview + menu_modelview->set_size(pane->width() - 2.0f * margin_horizontal, ui::UI::elementsize.width()); + menu_modelview->set_location(margin_horizontal, menu_modellabel->bottom() + margin_vertical); + + // warning text + menu_msgtext->set_size(pane->width() - 2.0f * margin_horizontal, menu_msgtext->font()->height()); + menu_msgtext->set_location(margin_horizontal, menu_modelview->bottom() + margin_vertical); - // 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_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 - ); + // resize slider + menu_slider->set_size( + math::min(pane->width() - padding * 2.0f - margin_horizontal * 2.0f, ui::UI::elementsize.width() * 2.5f), + menu_slider->font()->height() + ); + menu_slider->set_location((pane->width() - menu_slider->width()) * 0.5f, menu_msgtext->top()); + + // resize button + menu_buybutton->set_size(ui::UI::elementsize); + menu_buybutton->set_location((pane->width() - menu_buybutton->width()) * 0.5f, menu_msgtext->bottom() + padding); + + // resize infotext scrollpane + menu_scrollpane->set_size(pane->width() - 2.0f * margin_horizontal, pane->height() - menu_buybutton->bottom() - margin_vertical - padding); + menu_scrollpane->set_location(margin_horizontal, menu_buybutton->bottom() + padding); + } } bool TradeMenu::on_emit(Widget *sender, const Event event, void *data) @@ -417,7 +430,7 @@ void TradeMenu::draw() str << "INVENTORY" << '\n' << '\n'; - str << "Credits: " << aux::pad_left(creditstr.str(),12); + str << "Credits: " << aux::pad_left(creditstr.str(), 10); if (core::localcontrol() && core::localcontrol()->inventory()) { core::Inventory *inventory = core::localcontrol()->inventory(); @@ -425,7 +438,7 @@ void TradeMenu::draw() std::stringstream cargostr; cargostr << inventory->capacity_used() << " of " << inventory->capacity(); - str << '\n' << "Cargo: " << aux::pad_left(cargostr.str(),12); + 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 3dc83c0..a2a95fd 100644 --- a/src/client/trademenu.h +++ b/src/client/trademenu.h @@ -21,51 +21,72 @@ namespace client { -/// trade menu +/** + * @brief a trade menu window + */ class TradeMenu : public ui::Window { public: - /// create a new trade menu + /** + * @brief constructor + */ TradeMenu(ui::Widget *parent, const char * label = 0); + + /** + * @brief destructor + */ ~TradeMenu(); - /// set the item type to trade + /** + * @brief set the item type to trade + * */ void set_itemtype(core::InfoType *item_type); protected: - /// resize event handler + /** + * @brief resize event handler + * */ virtual void resize(); - /// draw event handler + /** + * @brief draw event handler + * */ virtual void draw(); - /// emit event handler - virtual bool on_emit(Widget *sender, const Event event, void *data); + /** + * @brief emit event handler + * */ + virtual bool on_emit(ui::Widget *sender, const Event event, void *data); - /// keypress event handler + /** + * @brief keypress event handler + * */ virtual bool on_keypress(const int key, const unsigned int modifier); - private: void set_item(ui::ListItem *item); - ui::Window *menu_tradewindow; - ui::Label *menu_namelabel; - ui::PlainText *menu_inventorytext; - ui::PlainText *menu_tradertext; + ui::Text menu_infotext; + + ui::Window *menu_tradewindow; + + ui::Label *menu_titlelabel; + ui::IconButton *menu_closebutton; + + ui::Widget *menu_pane_center; ui::ModelView *menu_modelview; ui::Label *menu_modellabel; ui::ScrollPane *menu_scrollpane; ui::Slider *menu_slider; ui::Label *menu_msgtext; - ui::IconButton *menu_closebutton; ui::Button *menu_buybutton; - + + ui::Label *menu_inventorytext; InventoryListView *menu_inventorylistview; - InventoryListView *menu_traderlistview; - ui::Text menu_infotext; + InventoryListView *menu_traderlistview; + ui::Label *menu_tradertext; core::InfoType *menu_itemtype; ui::ListItem *menu_listitem; |