diff options
author | Stijn Buys <ingar@osirion.org> | 2011-08-28 18:19:48 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2011-08-28 18:19:48 +0000 |
commit | 5afce7d29a2d852446b58b4410c43d7bf2063b11 (patch) | |
tree | 9a8f6652d5c65e5ccac0abdeac9dfc2f7aa1b3b0 /src/client | |
parent | 3b75614be6d9f6e84a1b5818c5827dbc0ab5d516 (diff) |
Added client::ButtonMenu base class, refactored client::EntityMenu as a ButtonMenu child.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/Makefile.am | 2 | ||||
-rw-r--r-- | src/client/buttonmenu.cc | 92 | ||||
-rw-r--r-- | src/client/buttonmenu.h | 48 | ||||
-rw-r--r-- | src/client/entitymenu.cc | 61 | ||||
-rw-r--r-- | src/client/entitymenu.h | 13 | ||||
-rw-r--r-- | src/client/gamewindow.cc | 43 | ||||
-rw-r--r-- | src/client/gamewindow.h | 2 |
7 files changed, 181 insertions, 80 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 9915d0e..c46d885 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -10,6 +10,7 @@ endif noinst_HEADERS = \ action.h \ + buttonmenu.h \ buymenu.h \ chat.h \ client.h \ @@ -38,6 +39,7 @@ noinst_HEADERS = \ libclient_la_SOURCES = \ action.cc \ + buttonmenu.cc \ buymenu.cc \ chat.cc \ client.cc \ diff --git a/src/client/buttonmenu.cc b/src/client/buttonmenu.cc new file mode 100644 index 0000000..ed15223 --- /dev/null +++ b/src/client/buttonmenu.cc @@ -0,0 +1,92 @@ +/* + ui/menu.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "client/buttonmenu.h" + +#include "filesystem/filesystem.h" +#include "ui/ui.h" + +namespace client +{ + +ButtonMenu::ButtonMenu(ui::Widget *parent, const char *label) : ui::Window(parent) +{ + set_label(label); + set_border(false); + set_background(false); + + buttonmenu_container = new ui::Window(this); + + hide(); +} + +ButtonMenu::~ButtonMenu() +{ +} + + +ui::Label *ButtonMenu::add_label(char const * text) +{ + ui::Label *label = new ui::Label(buttonmenu_container, text); + label->set_alignment(ui::AlignCenter); + label->set_border(false); + label->set_font(ui::root()->font_large()); + return label; +} + +ui::Button *ButtonMenu::add_button(char const *text, char const *command) +{ + return new ui::Button(buttonmenu_container, text, command); +} + +void ButtonMenu::resize() +{ + // resize container widget + buttonmenu_container->set_geometry(0, 0, ui::UI::elementsize.width() * 1.5f, height()); + + // reposition all children within the container + const float x = ui::UI::elementsize.width() * 0.25f; + float y = ui::UI::elementsize.height() * 0.5f; + + for (Children::iterator it = buttonmenu_container->children().begin(); it != buttonmenu_container->children().end(); it++) { + Widget *w = (*it); + + w->set_size(ui::UI::elementsize); + w->set_location(x, y); + + y += ui::UI::elementsize.height() + ui::UI::elementmargin; + } + +} + +void ButtonMenu::clear() +{ + remove_child(buttonmenu_container); + + buttonmenu_container = new ui::Window(this); + +} + +bool ButtonMenu::on_keypress(const int key, const unsigned int modifier) +{ + switch (key) { + + case SDLK_ESCAPE: + // close window on ESC + if (visible()) { + this->hide(); + return true; + } + break; + + default: + break; + } + + return Window::on_keypress(key, modifier); +} + +} diff --git a/src/client/buttonmenu.h b/src/client/buttonmenu.h new file mode 100644 index 0000000..2c3dd87 --- /dev/null +++ b/src/client/buttonmenu.h @@ -0,0 +1,48 @@ +/* + client/buttonmenu.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CLIENT_BUTTONMENU_H__ +#define __INCLUDED_CLIENT_BUTTONMENU_H__ + +#include "ui/label.h" +#include "ui/button.h" +#include "ui/window.h" + +namespace client +{ + +/// a menu container +class ButtonMenu : public ui::Window +{ + +public: + /// create a new menu + ButtonMenu(ui::Widget *parent, const char * label = 0); + ~ButtonMenu(); + + /// add a label + ui::Label *add_label(char const * text = 0); + + /// add a button with a command + ui::Button *add_button(char const *text = 0, char const *command = 0); + +protected: + /// remove container children + void clear(); + + /// resize event + virtual void resize(); + + /// keypress event + virtual bool on_keypress(const int key, const unsigned int modifier); + +private: + ui::Window *buttonmenu_container; +}; + +} + +#endif // __INCLUDED_CLIENT_BUTTONMENU_H__ diff --git a/src/client/entitymenu.cc b/src/client/entitymenu.cc index d2b3f27..ee1d373 100644 --- a/src/client/entitymenu.cc +++ b/src/client/entitymenu.cc @@ -4,24 +4,18 @@ the terms of the GNU General Public License version 2 */ +#include "client/entitymenu.h" + #include "ui/ui.h" -#include "ui/button.h" #include "ui/paint.h" -#include "client/entitymenu.h" namespace client { -EntityMenu::EntityMenu(ui::Widget *parent, const char * label) : ui::Window(parent) +EntityMenu::EntityMenu(ui::Widget *parent, const char * label) : ButtonMenu(parent, label) { set_border(false); set_background(false); - if (label) - set_label(label); - else - set_label("entitymenu"); - - menu_container = new ui::Container(this); menu_generated_entity = 0; hide(); } @@ -30,21 +24,8 @@ EntityMenu::~EntityMenu() { } -void EntityMenu::resize() -{ - set_size(parent()->size()); - menu_container->set_location(ui::UI::elementsize.height(), (height() - menu_container->height()) / 2.0f); -} - -void EntityMenu::clear() -{ - remove_children(); -} - void EntityMenu::generate(core::Entity *entity, const char *menulabel) { - using namespace ui; - menu_generated_menu.clear(); menu_generated_entity = entity; @@ -62,7 +43,6 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel) //con_debug << "generating menu " << entity->label() << " " << menulabel << std::endl; clear(); - menu_container = new Container(this); core::MenuDescription *menudescr = 0; for (core::Entity::Menus::iterator it = entity->menus().begin(); it != entity->menus().end(); it++) { @@ -72,17 +52,27 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel) } if (!menudescr) { - menu_container->event_resize(); - resize(); + event_resize(); return; } - if (menudescr->text().size()) { - Label *label = new Label(menu_container); - label->set_text(menudescr->text()); - label->set_alignment(AlignCenter); - label->set_border(false); + if (menudescr->text().size()) { + std:: string title (entity->name()); + aux::to_uppercase(title); + ui::Label *label; + + label = add_label(title.c_str()); + label->set_alignment(ui::AlignCenter); label->set_font(ui::root()->font_large()); + label->set_border(false); + label->set_border(false); + + label = add_label(menudescr->text().c_str()); + label->set_alignment(ui::AlignCenter); + label->set_font(ui::root()->font_small()); + label->set_border(false); + label->set_border(false); + } for (core::MenuDescription::Buttons::iterator it = menudescr->buttons().begin(); it != menudescr->buttons().end(); it++) { @@ -153,23 +143,22 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel) } - Button *button = new Button(menu_container, buttondescr->text().c_str(), result.c_str()); + ui::Button *button = add_button(buttondescr->text().c_str(), result.c_str()); switch (buttondescr->alignment()) { case core::ButtonDescription::Center: - button->set_alignment(AlignCenter); + button->set_alignment(ui::AlignCenter); break; case core::ButtonDescription::Left: - button->set_alignment(AlignLeft | AlignVCenter); + button->set_alignment(ui::AlignLeft | ui::AlignVCenter); break; case core::ButtonDescription::Right: - button->set_alignment(AlignRight | AlignVCenter); + button->set_alignment(ui::AlignRight | ui::AlignVCenter); break; } } - menu_container->event_resize(); - resize(); + event_resize(); } bool EntityMenu::on_keypress(const int key, const unsigned int modifier) diff --git a/src/client/entitymenu.h b/src/client/entitymenu.h index 0285879..5bea94e 100644 --- a/src/client/entitymenu.h +++ b/src/client/entitymenu.h @@ -8,15 +8,13 @@ #define __INCLUDED_CLIENT_ENTITYMENU_H__ #include "core/entity.h" -#include "ui/container.h" -#include "ui/label.h" -#include "ui/window.h" +#include "client/buttonmenu.h" namespace client { /// entity menu -class EntityMenu : public ui::Window +class EntityMenu : public ButtonMenu { public: /// create a new menu @@ -40,18 +38,11 @@ public: /// generate a menu from menu descriptions void generate(core::Entity *entity, const char *menulabel); - /// clear the current menu - void clear(); - protected: - /// resize event - virtual void resize(); - /// keypress event handler virtual bool on_keypress(const int key, const unsigned int modifier); private: - ui::Container *menu_container; core::Entity *menu_generated_entity; std::string menu_generated_menu; }; diff --git a/src/client/gamewindow.cc b/src/client/gamewindow.cc index 3404703..a2693e1 100644 --- a/src/client/gamewindow.cc +++ b/src/client/gamewindow.cc @@ -24,15 +24,15 @@ GameWindow::GameWindow(ui::Widget *parent) : ui::Window(parent) gamewindow_hud = new HUD(this); - label_viewname = new ui::Label(this); - label_viewname->set_label("viewnamelabel"); - label_viewname->set_alignment(ui::AlignCenter); - label_viewname->set_background(true); - label_viewname->set_font(ui::root()->font_large()); + //label_viewname = new ui::Label(this); + //label_viewname->set_label("viewnamelabel"); + //label_viewname->set_alignment(ui::AlignCenter); + //label_viewname->set_background(true); + //label_viewname->set_font(ui::root()->font_large()); // sub menus gamewindow_map = new MapWindow(this); - gamewindow_entitymenu = new EntityMenu(this); + gamewindow_entitymenu = new EntityMenu(this, "entitymenu"); gamewindow_buymenu = new BuyMenu(this); gamewindow_trademenu = new TradeMenu(this); gamewindow_inventory = new InventoryWindow(this); @@ -282,6 +282,7 @@ void GameWindow::resize() // reposition buy menu gamewindow_buymenu->event_resize(); + // reposition trade menu gamewindow_trademenu->event_resize(); @@ -289,6 +290,10 @@ void GameWindow::resize() gamewindow_hud->set_geometry(0, 0, width(), height()); gamewindow_hud->event_resize(); + // reposition entity menus + gamewindow_entitymenu->set_size(width() - smallmargin * 2, height() - smallmargin * 4); + gamewindow_entitymenu->set_location(smallmargin, smallmargin * 2); + // reposition map gamewindow_map->set_size(width() - smallmargin * 2, height() - smallmargin * 4); gamewindow_map->set_location(smallmargin, smallmargin * 2); @@ -296,10 +301,6 @@ void GameWindow::resize() // reposition inventory gamewindow_inventory->set_size(width() - smallmargin * 2, height() - smallmargin * 4); gamewindow_inventory->set_location(smallmargin, smallmargin * 2); - - // reposition labels - label_viewname->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height()); - label_viewname->set_location(width() - label_viewname->width() - smallmargin, height() - label_viewname->height() - smallmargin * 0.5f); } void GameWindow::draw() @@ -324,16 +325,6 @@ void GameWindow::draw() // docking view if (core::localplayer()->view()->menus().size()) { - // entity with menus - - if (map()->visible()) { - label_viewname->set_text(core::localplayer()->zone()->name()); - } else { - label_viewname->set_text(core::localplayer()->view()->name()); - } - - label_viewname->show(); - if (gamewindow_entitymenu->generated_entity() != core::localplayer()->view()) { // initially show the menu show_menu("main"); @@ -351,10 +342,7 @@ void GameWindow::draw() // show the menu if there's no other window open gamewindow_entitymenu->show(); } - - //gamewindow_notify->set_size(width() - smallmargin * 3.0f - ui::UI::elementsize.width() * 1.5f, height() - smallmargin * 4.0f); - //gamewindow_notify->set_location(smallmargin * 2.0f + ui::UI::elementsize.width() * 1.5f, smallmargin * 2.0f); - + gamewindow_homebutton->enable(); } else { @@ -381,13 +369,6 @@ void GameWindow::draw() if (gamewindow_trademenu->visible()) { gamewindow_trademenu->hide(); } - - if (map()->visible()) { - label_viewname->set_text(core::localplayer()->zone()->name()); - label_viewname->show(); - } else { - label_viewname->hide(); - } if (!map()->visible() && !chat()->visible() && !inventory()->visible()) { gamewindow_hud->set_focus(); diff --git a/src/client/gamewindow.h b/src/client/gamewindow.h index 6c1ee83..d6e36db 100644 --- a/src/client/gamewindow.h +++ b/src/client/gamewindow.h @@ -91,8 +91,6 @@ private: BuyMenu *gamewindow_buymenu; TradeMenu *gamewindow_trademenu; - ui::Label *label_viewname; - ui::IconButton *gamewindow_menubutton; ui::IconButton *gamewindow_dockbutton; ui::IconButton *gamewindow_launchbutton; |