diff options
author | Stijn Buys <ingar@osirion.org> | 2010-10-05 14:38:14 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-10-05 14:38:14 +0000 |
commit | fed29d9ddc3b8372b9c3fe8bffe221a5a55e5ce9 (patch) | |
tree | 659096f4412e6ad9a0f47e70a620da327195e67a /src | |
parent | 312b9bcb81748032ff21e3d3f1d5fd36405fb713 (diff) |
updated inventory window, listview seletion sounds, modelview zoom factor
Diffstat (limited to 'src')
-rw-r--r-- | src/client/inventory.cc | 108 | ||||
-rw-r--r-- | src/client/inventory.h | 20 | ||||
-rw-r--r-- | src/ui/button.cc | 4 | ||||
-rw-r--r-- | src/ui/iconbutton.cc | 9 | ||||
-rw-r--r-- | src/ui/listitem.cc | 8 | ||||
-rw-r--r-- | src/ui/listitem.h | 2 | ||||
-rwxr-xr-x | src/ui/modelview.cc | 4 |
7 files changed, 139 insertions, 16 deletions
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); } diff --git a/src/client/inventory.h b/src/client/inventory.h index f66ec56..00b3b51 100644 --- a/src/client/inventory.h +++ b/src/client/inventory.h @@ -9,7 +9,10 @@ #include "core/info.h" #include "core/inventory.h" +#include "ui/iconbutton.h" #include "ui/listview.h" +#include "ui/modelview.h" +#include "ui/scrollpane.h" #include "ui/plaintext.h" #include "ui/window.h" @@ -25,6 +28,8 @@ public: ~Inventory(); void toggle(); + + virtual void show(); protected: /// resize event handler virtual void resize(); @@ -41,15 +46,26 @@ protected: private: void update_inventory(); - void update_selection(); + void set_info(const core::Info *info, const int amount); bool verify() const; unsigned long menu_inventorytimestamp; unsigned long menu_infotimestamp; - ui::ListView *menu_listview; + + int menu_amount; + + ui::Text menu_infotext; + + const core::Info *menu_inforecord; + + ui::ModelView *menu_modelview; + ui::Label *menu_namelabel; + ui::ListView *menu_listview; ui::PlainText *menu_inventorytext; + ui::ScrollPane *menu_scrollpane; + ui::IconButton *menu_shipbutton; }; // class Inventory diff --git a/src/ui/button.cc b/src/ui/button.cc index ddcc72d..6cbb51e 100644 --- a/src/ui/button.cc +++ b/src/ui/button.cc @@ -85,7 +85,9 @@ bool Button::on_keypress(const int key, const unsigned int modifier) { if (key == 512 + SDL_BUTTON_LEFT) { if (enabled()) { - core::cmd() << button_command << std::endl; + if (button_command.size()) { + core::cmd() << button_command << std::endl; + } audio::play("ui/button"); emit(EventButtonClicked); diff --git a/src/ui/iconbutton.cc b/src/ui/iconbutton.cc index 204918e..5f16e71 100644 --- a/src/ui/iconbutton.cc +++ b/src/ui/iconbutton.cc @@ -81,7 +81,7 @@ void IconButton::draw() Paint::set_color(palette()->foreground()); } - Paint::draw_bitmap(location(), size(), icon()); + Paint::draw_bitmap(global_location(), size(), icon()); } void IconButton::draw_border() @@ -101,9 +101,12 @@ void IconButton::draw_border() bool IconButton::on_keypress(const int key, const unsigned int modifier) { if (key == 512 + SDL_BUTTON_LEFT) { - if (enabled() && iconbutton_command.size()) { - core::cmd() << iconbutton_command << std::endl; + if (enabled()) { + if (iconbutton_command.size()) { + core::cmd() << iconbutton_command << std::endl; + } audio::play("ui/button"); + emit(EventButtonClicked); } return true; } diff --git a/src/ui/listitem.cc b/src/ui/listitem.cc index ff9ad18..8702757 100644 --- a/src/ui/listitem.cc +++ b/src/ui/listitem.cc @@ -51,10 +51,16 @@ void ListItem::draw() Paint::draw_label(global_location(), size(), font(), text(), alignment()); } +void ListItem::on_mouseover(const math::Vector2f &cursor) +{ + if (enabled()) + audio::play("ui/select"); +} + bool ListItem::on_keypress(const int key, const unsigned int modifier) { if (key == 512 + SDL_BUTTON_LEFT) { - audio::play("ui/select"); + audio::play("ui/button"); emit(EventListItemClicked); diff --git a/src/ui/listitem.h b/src/ui/listitem.h index 6fad3e9..3c9efea 100644 --- a/src/ui/listitem.h +++ b/src/ui/listitem.h @@ -52,6 +52,8 @@ protected: /// draw the button border virtual void draw_border(); + virtual void on_mouseover(const math::Vector2f &cursor); + virtual void draw(); private: diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc index b247213..9542b5f 100755 --- a/src/ui/modelview.cc +++ b/src/ui/modelview.cc @@ -69,12 +69,12 @@ void ModelView::set_zoom(const float zoom) bool ModelView::on_keypress(const int key, const unsigned int modifier) { if (key == 512 + SDL_BUTTON_WHEELUP) { - modelview_zoom -= 0.1f; + modelview_zoom -= 0.5f; if (modelview_zoom < 1.0f) modelview_zoom = 1.0f; return true; } else if (key == 512 + SDL_BUTTON_WHEELDOWN) { - modelview_zoom += 0.1f; + modelview_zoom += 0.5f; if (modelview_zoom > 10.0f) modelview_zoom = 10.0f; return true; |