Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-01-27 18:53:24 +0000
committerStijn Buys <ingar@osirion.org>2009-01-27 18:53:24 +0000
commit9c2d1a1c867bbd7eea083dbc03c0acf1edace8c2 (patch)
tree51b0f6e52d4dc368fc8358aa86cca395b6d2506b /src/client/entitymenu.cc
parent76a49efdf62a53a54e2deeb559422f11c1e955dd (diff)
moves docking menus from ui to client,
allow map and chat window while docked
Diffstat (limited to 'src/client/entitymenu.cc')
-rw-r--r--src/client/entitymenu.cc93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/client/entitymenu.cc b/src/client/entitymenu.cc
new file mode 100644
index 0000000..c7df7ab
--- /dev/null
+++ b/src/client/entitymenu.cc
@@ -0,0 +1,93 @@
+/*
+ client/entitymenu.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#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)
+{
+ set_border(false);
+ set_background(false);
+ set_label(label);
+
+ menu_container = new ui::Container(this);
+ hide();
+}
+
+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;
+
+ if (!menulabel)
+ return;
+
+ //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++) {
+ if ((*it)->label().compare(menulabel) == 0) {
+ menudescr = (*it);
+ }
+ }
+
+ if (!menudescr) {
+ menu_container->event_resize();
+ 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);
+ label->set_font(ui::root()->font_large());
+ }
+
+ for (core::MenuDescription::Buttons::iterator it = menudescr->buttons().begin(); it != menudescr->buttons().end(); it++) {
+ core::ButtonDescription *buttondescr = (*it);
+ Button *button = new Button(menu_container, buttondescr->text().c_str(), buttondescr->command().c_str());
+ switch (buttondescr->alignment()) {
+ case core::ButtonDescription::Center:
+ button->set_alignment(AlignCenter);
+ break;
+ case core::ButtonDescription::Left:
+ button->set_alignment(AlignLeft | AlignVCenter);
+ break;
+ case core::ButtonDescription::Right:
+ button->set_alignment(AlignRight | AlignVCenter);
+ break;
+ }
+ }
+
+ menu_container->event_resize();
+ resize();
+}
+
+}