From fed29d9ddc3b8372b9c3fe8bffe221a5a55e5ce9 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 5 Oct 2010 14:38:14 +0000 Subject: updated inventory window, listview seletion sounds, modelview zoom factor --- src/client/inventory.cc | 108 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 7 deletions(-) (limited to 'src/client/inventory.cc') diff --git a/src/client/inventory.cc b/src/client/inventory.cc index 5837a17..c6e86da 100644 --- a/src/client/inventory.cc +++ b/src/client/inventory.cc @@ -19,6 +19,13 @@ Inventory::Inventory(ui::Widget *parent) : ui::Window(parent) { menu_infotimestamp = 0; menu_inventorytimestamp = 0; + menu_inforecord = 0; + menu_amount = 0; + + menu_modelview = new ui::ModelView(this); + menu_modelview->set_label("modelview"); + menu_modelview->set_background(false); + menu_modelview->set_border(false); menu_namelabel = new ui::Label(this); menu_namelabel->set_label("label"); @@ -39,6 +46,13 @@ Inventory::Inventory(ui::Widget *parent) : ui::Window(parent) menu_inventorytext->set_border(false); menu_inventorytext->set_font(ui::root()->font_small()); + menu_scrollpane = new ui::ScrollPane(this, menu_infotext); + menu_scrollpane->set_background(false); + menu_scrollpane->set_border(false); + menu_scrollpane->set_alignment(ui::AlignTop); + + menu_shipbutton = new ui::IconButton(this, "bitmaps/icons/button_ship"); + hide(); } @@ -56,12 +70,13 @@ void Inventory::toggle() void Inventory::update_inventory() { menu_listview->clear(); - menu_infotimestamp = 0; menu_inventorytimestamp = 0; + menu_infotimestamp = 0; if (!core::localcontrol() || !core::localcontrol()->inventory()) { return; } + const core::Item *selecteditem = (menu_listview->selected() ? menu_listview->selected()->item() : 0); for (core::Inventory::Items::const_iterator it = core::localcontrol()->inventory()->items().begin(); it != core::localcontrol()->inventory()->items().end(); it++) { @@ -97,18 +112,29 @@ void Inventory::update_inventory() } } } - menu_listview->event_resize(); + + // request ship info + if (core::localcontrol()->info()) { + core::game()->request_info(core::localcontrol()->info()->id()); + if (core::localcontrol()->info()->timestamp() > menu_infotimestamp) + menu_infotimestamp = core::localcontrol()->info()->timestamp(); + } + menu_inventorytimestamp = core::localcontrol()->inventory()->timestamp(); -} -void Inventory::update_selection() -{ + if (menu_listview->selected()) { + set_info(menu_listview->selected()->info(), menu_listview->selected()->item()->amount()); + } else if (menu_inforecord != core::localcontrol()->info()) { + set_info(0, 0); + } + + menu_listview->event_resize(); } bool Inventory::verify() const { if (!core::localcontrol() || !core::localcontrol()->inventory()) { - + return true; } if (menu_inventorytimestamp != core::localcontrol()->inventory()->timestamp()) { @@ -132,6 +158,7 @@ void Inventory::resize() { const float smallmargin = ui::UI::elementsize.height(); const float fontmargin = ui::root()->font_large()->height(); + const float icon_size = 48.0f; // resize label menu_namelabel->set_size(width() - fontmargin * 2.0f, menu_namelabel->font()->height()); @@ -143,12 +170,27 @@ void Inventory::resize() menu_inventorytext->set_size(menu_listview->width(), fontmargin * 2.0f); menu_inventorytext->set_location(menu_listview->left(), menu_listview->bottom() + fontmargin); + + menu_shipbutton->set_size(icon_size, icon_size); + menu_shipbutton->set_location(menu_inventorytext->left(), height() - icon_size - fontmargin); + + // resize modelview + menu_modelview->set_size( width() - menu_listview->right() - fontmargin * 2.0f ,ui::UI::elementsize.width()); + menu_modelview->set_location(menu_listview->right() + fontmargin, fontmargin * 3.0f); + + // resize infotext + menu_scrollpane->set_size(menu_modelview->width(), height() - menu_modelview->bottom() - 2.0f * fontmargin); + menu_scrollpane->set_location(menu_modelview->left(), menu_modelview->bottom() + fontmargin); } void Inventory::draw() { if (!verify()) { - update_inventory(); + update_inventory(); + } + + if (menu_inforecord && (menu_inforecord->timestamp() > menu_infotimestamp)) { + set_info(menu_inforecord, menu_amount); } std::stringstream str; @@ -167,8 +209,60 @@ void Inventory::draw() Window::draw(); } +void Inventory::show() +{ + menu_listview->deselect(); + set_info(0, 0); + Window::show(); +} + +void Inventory::set_info(const core::Info *info, const int amount) +{ + menu_inforecord = info; + menu_infotext.clear(); + menu_amount = amount; + + if (!info) { + menu_modelview->set_modelname(0); + menu_namelabel->set_text("Inventory"); + } else { + std::stringstream titlestr; + titlestr << info->name(); + if (amount > 0) { + titlestr << " (" << amount << ")"; + } + menu_namelabel->set_text(titlestr.str().c_str()); + core::game()->request_info(info->id()); + menu_modelview->set_modelname(info->modelname()); + + for (core::Info::Text::const_iterator it = menu_inforecord->text().begin(); it != menu_inforecord->text().end(); it++) { + menu_infotext.push_back((*it)); + } + if (info->timestamp() > menu_infotimestamp) { + menu_infotimestamp = info->timestamp(); + } + } + +} + bool Inventory::on_emit(Widget *sender, const Event event, void *data) { + if (event == ui::Widget::EventButtonClicked) { + + if (sender == menu_shipbutton) { + menu_listview->deselect(); + set_info(core::localcontrol() ? core::localcontrol()->info() : 0, 0); + } + return true; + + } else if (event == ui::Widget::EventListViewChanged) { + + if (sender == menu_listview) { + set_info(menu_listview->selected() ? menu_listview->selected()->info() : 0, menu_listview->selected()->item()->amount()); + } + return true; + } + return Window::on_emit(sender, event, data); } -- cgit v1.2.3