From 69eed715f80c24c2435c82bb9fa1954697bf3af0 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 4 Sep 2011 17:54:51 +0000 Subject: Moved main menu infrastructure into client namespace, removed ui::Container and ui::Menu classes. --- src/client/buttonmenu.cc | 36 ++---- src/client/buttonmenu.h | 10 +- src/client/buymenu.h | 1 - src/client/client.cc | 91 ++++++-------- src/client/client.h | 2 + src/client/entitymenu.cc | 3 +- src/client/hud.cc | 3 +- src/client/input.cc | 2 +- src/client/mainmenu.cc | 314 ++++++++++++++++++++++++++++++++++++++++++++++- src/client/mainmenu.h | 54 ++++++-- src/client/mainwindow.cc | 23 ++-- src/client/mapwindow.cc | 169 +------------------------ src/client/mapwindow.h | 2 +- src/ui/Makefile.am | 4 - src/ui/container.cc | 45 ------- src/ui/container.h | 33 ----- src/ui/menu.cc | 82 ------------- src/ui/menu.h | 54 -------- src/ui/ui.cc | 242 ------------------------------------ src/ui/ui.h | 27 ---- src/ui/widget.cc | 14 ++- src/ui/widget.h | 2 +- 22 files changed, 446 insertions(+), 767 deletions(-) delete mode 100644 src/ui/container.cc delete mode 100644 src/ui/container.h delete mode 100644 src/ui/menu.cc delete mode 100644 src/ui/menu.h diff --git a/src/client/buttonmenu.cc b/src/client/buttonmenu.cc index ed15223..18139d0 100644 --- a/src/client/buttonmenu.cc +++ b/src/client/buttonmenu.cc @@ -19,6 +19,7 @@ ButtonMenu::ButtonMenu(ui::Widget *parent, const char *label) : ui::Window(paren set_background(false); buttonmenu_container = new ui::Window(this); + buttonmenu_compact = false; hide(); } @@ -44,11 +45,10 @@ ui::Button *ButtonMenu::add_button(char const *text, char const *command) void ButtonMenu::resize() { - // resize container widget - buttonmenu_container->set_geometry(0, 0, ui::UI::elementsize.width() * 1.5f, height()); - + const float padding = ui::UI::elementsize.height(); + // reposition all children within the container - const float x = ui::UI::elementsize.width() * 0.25f; + const float x = padding; float y = ui::UI::elementsize.height() * 0.5f; for (Children::iterator it = buttonmenu_container->children().begin(); it != buttonmenu_container->children().end(); it++) { @@ -60,6 +60,15 @@ void ButtonMenu::resize() y += ui::UI::elementsize.height() + ui::UI::elementmargin; } + // resize container widget + if (!buttonmenu_compact) { + buttonmenu_container->set_geometry(0, 0, ui::UI::elementsize.width() + 2.0f * padding, height()); + } else { + y += ui::UI::elementsize.height() * 0.5f; + buttonmenu_container->set_geometry(0, (height() - y) * 0.5f, ui::UI::elementsize.width() + 2.0f * padding, y); + } + + } void ButtonMenu::clear() @@ -70,23 +79,4 @@ void ButtonMenu::clear() } -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 index 2c3dd87..fbd7797 100644 --- a/src/client/buttonmenu.h +++ b/src/client/buttonmenu.h @@ -28,6 +28,11 @@ public: /// add a button with a command ui::Button *add_button(char const *text = 0, char const *command = 0); + + /// set compact mode + inline void set_compact(const bool compact = true) { + buttonmenu_compact = compact; + } protected: /// remove container children @@ -36,11 +41,10 @@ protected: /// resize event virtual void resize(); - /// keypress event - virtual bool on_keypress(const int key, const unsigned int modifier); - private: ui::Window *buttonmenu_container; + + bool buttonmenu_compact; }; } diff --git a/src/client/buymenu.h b/src/client/buymenu.h index 7f19ebf..d4bc45c 100644 --- a/src/client/buymenu.h +++ b/src/client/buymenu.h @@ -8,7 +8,6 @@ #define __INCLUDED_CLIENT_BUYMENU_H__ #include "core/info.h" -#include "ui/container.h" #include "ui/button.h" #include "ui/label.h" #include "ui/modelview.h" diff --git a/src/client/client.cc b/src/client/client.cc index 69f36b6..706634a 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -224,44 +224,34 @@ void Client::frame() core::Application::frame(); if (!connected()) { + const std::string module_label(core::Loader::label()); + + if (!ui::console()->visible()) { - // load the intro if nothing is running - if (load("intro")) { - connect(""); - if (module_label.size()) - load(module_label); + // load the intro if nothing is running + if (load("intro")) { + connect(""); + if (module_label.size()) + load(module_label); + } else { + ui::console()->toggle(); + } } - // show the console if everything fails - if (!connected() && !ui::console()->visible()) { - ui::console()->toggle(); + + if (client_mainwindow->visible()) { + client_mainwindow->hide(); } - } else if (!ui::root()->active()) { - - // show the main menu on non-interactive modules - if (!core::game()->interactive()) { - ui::root()->show_menu("main"); - - // show the join menu when player does not control an entity - } else if (core::game()->time() && !core::localcontrol()) { - ui::root()->show_menu("join"); + + } else { + if (client_mainwindow->hidden()) { + client_mainwindow->show(); } - if (testmodelwindow()->visible()) { - testmodelwindow()->raise(); - } if (ui::console()->visible()) { ui::console()->raise(); ui::console()->set_focus(); } - } else { - if (core::localcontrol()) { - - // hide join menu - if (ui::root()->active()->label().compare("join") == 0) { - ui::root()->hide_menu(); - } - } } const float now = timestamp(); @@ -310,9 +300,6 @@ void Client::notify_connect() video::frame_loader(); mainwindow()->clear(); - ui::root()->hide_menu(); - - //video::set_caption(); } void Client::notify_disconnect() @@ -322,8 +309,6 @@ void Client::notify_disconnect() input::reset(); mainwindow()->clear(); - - //video::set_caption(); } void Client::notify_zonechange() @@ -444,7 +429,7 @@ void Client::func_ui_restart(std::string const &args) void Client::func_list_menu(std::string const &args) { if (ui::root()) { - ui::root()->list_menus(); + // FIXME ui::root()->list_menus(); } } @@ -500,14 +485,12 @@ void Client::func_ui(std::string const &args) void Client::func_menu_help() { con_print << "^Bmenu functions" << std::endl; - con_print << " menu help show this help" << std::endl; - con_print << " menu list list available menus" << std::endl; - con_print << " menu [name] show a menu" << std::endl; - con_print << " menu back return to the previous menu" << std::endl; - con_print << " menu previous return to the previous menu" << std::endl; - con_print << " menu close close the current menu" << std::endl; - con_print << " menu hide hide the current menu" << std::endl; - ui::root()->list_menus(); + con_print << "^RTODO" << std::endl; +} + +void Client::show_menu(const char *menu) +{ + client()->client_mainwindow->mainmenu()->show_menu(menu); } // global menu fuctions @@ -528,28 +511,24 @@ void Client::func_menu(std::string const &args) argstr >> command; aux::to_label(command); - if (command.compare("help") == 0) { func_menu_help(); } else if (command.compare("hide") == 0) { - ui::root()->hide_menu(); + client()->client_mainwindow->mainmenu()->hide(); } else if (command.compare("close") == 0) { - ui::root()->hide_menu(); - - } else if (command.compare("back") == 0) { - ui::root()->previous_menu(); + client()->client_mainwindow->mainmenu()->hide(); - } else if (command.compare("previous") == 0) { - ui::root()->previous_menu(); + } else if (command.compare("default") == 0) { + client()->client_mainwindow->mainmenu()->show_default(); } else if (command.compare("list") == 0) { - ui::root()->list_menus(); + // TODO client_mainwindow->mainmenu()->list(); } else { - ui::root()->show_menu(command.c_str()); + show_menu(command.c_str()); } } @@ -557,14 +536,14 @@ void Client::func_menu(std::string const &args) void Client::func_ui_menu(std::string const &args) { if (client()->connected()) { - if (ui::root()->active()) { - ui::root()->hide_menu(); + if (client()->client_mainwindow->mainmenu()->visible()) { + client()->client_mainwindow->mainmenu()->hide(); } else { // show the main menu on non-interactive modules if (!core::game()->interactive()) { - ui::root()->show_menu("main"); + show_menu("main"); } else { - ui::root()->show_menu("game"); + show_menu("game"); } } } else { diff --git a/src/client/client.h b/src/client/client.h index ff7ac98..e89abfa 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -75,6 +75,8 @@ public: func_say(text); } + static void show_menu(const char *menu); + protected: /// run a client frame virtual void frame(); diff --git a/src/client/entitymenu.cc b/src/client/entitymenu.cc index ee1d373..f9a5edc 100644 --- a/src/client/entitymenu.cc +++ b/src/client/entitymenu.cc @@ -6,6 +6,7 @@ #include "client/entitymenu.h" +#include "client/client.h" #include "ui/ui.h" #include "ui/paint.h" @@ -171,7 +172,7 @@ bool EntityMenu::on_keypress(const int key, const unsigned int modifier) generate(menu_generated_entity, "main"); } else { this->hide(); - ui::root()->show_menu("game"); + Client::show_menu("game"); } return true; } diff --git a/src/client/hud.cc b/src/client/hud.cc index 423bf58..c3a6a71 100644 --- a/src/client/hud.cc +++ b/src/client/hud.cc @@ -6,6 +6,7 @@ #include "core/core.h" +#include "client/client.h" #include "client/hud.h" #include "client/input.h" #include "client/targets.h" @@ -224,7 +225,7 @@ bool HUD::on_keypress(const int key, const unsigned int modifier) if (targets::current()) { targets::reset(); } else { - ui::root()->show_menu("game"); + Client::show_menu("game"); } return true; } diff --git a/src/client/input.cc b/src/client/input.cc index 8672284..69be2ab 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -851,7 +851,7 @@ void frame() mouse_control = false; if (core::application()->connected() && core::localcontrol()) { - mouse_control = ui::console()->hidden() && !ui::root()->active() && ((input_mousecontrol->value() > 0) || (mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))); + mouse_control = ui::console()->hidden() && ((input_mousecontrol->value() > 0) || (mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))); if (mouse_control && joystick_control && ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit))) { if (!(mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))) { diff --git a/src/client/mainmenu.cc b/src/client/mainmenu.cc index 6a4f97a..cfebade 100644 --- a/src/client/mainmenu.cc +++ b/src/client/mainmenu.cc @@ -4,15 +4,27 @@ the terms and conditions of the GNU General Public License version 2 */ +#include "client/buttonmenu.h" #include "client/mainmenu.h" +#include "core/core.h" +#include "core/gameinterface.h" +#include "core/application.h" +#include "filesystem/inifile.h" #include "ui/paint.h" #include "ui/ui.h" +#include "ui/label.h" +#include "ui/button.h" namespace client { -MainMenu::MainMenu(ui::Widget *parent) : ui::Window(parent) +MainMenu::MainMenu(ui::Widget *parent) : + ui::Window(parent), + mainmenu_background("bitmaps/banner") { + // acive menu + mainmenu_activemenu = 0; + // default main menus mainmenu_mainmenu = 0; mainmenu_gamemenu = 0; @@ -23,31 +35,273 @@ MainMenu::MainMenu(ui::Widget *parent) : ui::Window(parent) mainmenu_loadmenu = 0; mainmenu_savemenu = 0; mainmenu_connectmenu = 0; - + + set_border(false); set_background(true); set_label("mainmenu"); + + load(); } MainMenu::~MainMenu() { } +void MainMenu::load_definitions() +{ + // load custom menu definitions from ini/menu.ini + std::string filename("ini/menu"); + filesystem::IniFile ini; + ini.open(filename); + + if (!ini.is_open()) { + con_error << "Could not open " << ini.name() << std::endl; + return; + } + + con_debug << " Loading menu definitions..." << std::endl; + + ui::Label *label = 0; + ui::Button *button = 0; + ButtonMenu *menu = 0; + std::string strval; + + while (ini.getline()) { + + if (ini.got_section()) { + + if (ini.got_section("menu")) { + menu = 0; + continue; + + // menu button + } else if (ini.got_section("button")) { + + if (!menu) { + ini.unknown_error("button section without menu defintion"); + } else { + button = menu->add_button(); + } + + // menu label + } else if (ini.got_section("label")) { + + if (!menu) { + ini.unknown_error("label section without menu defintion"); + } else { + label = menu->add_label(); + } + + } else { + ini.unknown_section(); + continue; + } + + } else if (ini.got_key()) { + + if (ini.in_section("menu")) { + + if (ini.got_key_string("label", strval)) { + aux::to_label(strval); + + for (ui::Widget::Children::iterator child = children().begin(); child != children().end(); ++child) { + if ((*child)->label().compare(strval) == 0) { + menu = static_cast((*child)); + } + } + + if (!menu) { + menu = new ButtonMenu(this, strval.c_str()); + } + } else { + ini.unknown_key(); + } + + } else if (menu) { + + if (ini.in_section("button")) { + + if (ini.got_key_string("text", strval)) { + aux::strip_quotes(strval); + button->set_text(strval); + + } else if (ini.got_key_string("command", strval)) { + for (size_t i = 0; i <= strval.size(); i++) { + if (strval[i] == ',') strval[i] = ';'; + } + aux::strip_quotes(strval); + button->set_command(strval); + + } else if (ini.got_key_string("align", strval)) { + aux::to_label(strval); + if (strval.compare("left") == 0) { + button->set_alignment(ui::AlignLeft | ui::AlignVCenter); + } else if (strval.compare("center") == 0) { + button->set_alignment(ui::AlignCenter); + } else if (strval.compare("right") == 0) { + button->set_alignment(ui::AlignRight | ui::AlignVCenter); + } else { + ini.unknown_value(); + } + } else { + ini.unknown_key(); + } + + } else if (ini.in_section("label")) { + + if (ini.got_key_string("text", strval)) { + label->set_text(strval); + } else if (ini.got_key_string("align", strval)) { + aux::to_label(strval); + if (strval.compare("left") == 0) { + label->set_alignment(ui::AlignLeft | ui::AlignHCenter); + } else if (strval.compare("center") == 0) { + label->set_alignment(ui::AlignCenter); + } else if (strval.compare("right") == 0) { + label->set_alignment(ui::AlignRight | ui::AlignHCenter); + } else { + ini.unknown_value(); + } + } else { + ini.unknown_key(); + } + } + } + } + } + + ini.close(); +} + +void MainMenu::load() +{ + remove_children(); + + // main menu when not connected + mainmenu_mainmenu = (ui::Widget *) new ButtonMenu(this, "main"); + static_cast(mainmenu_mainmenu)->set_compact(); + + // main menu when connected + mainmenu_gamemenu = (ui::Widget *) new ButtonMenu(this, "game"); + static_cast(mainmenu_gamemenu)->set_compact(); + + // menu to join a game + mainmenu_joinmenu = (ui::Widget *) new ButtonMenu(this, "join"); + static_cast(mainmenu_joinmenu)->set_compact(); + + // load custom menus, this needs to be done before the + // non-buttonmenu child widgets are created + load_definitions(); + + // options menu + mainmenu_optionsmenu = 0; + + // menu to connect to remote servers + mainmenu_connectmenu = 0; + + // load game menu + mainmenu_loadmenu = 0; + + // save game menu + mainmenu_savemenu = 0; + + show_menu(); +} + +void MainMenu::show_menu() +{ + mainmenu_activemenu = 0; + + if (core::application()->connected()) { + + // show the main menu on non-interactive modules + if (!core::game()->interactive()) { + mainmenu_activemenu = mainmenu_mainmenu; + + // show the join menu if player does not control an entity + } else if (!core::localcontrol()) { + mainmenu_activemenu = mainmenu_joinmenu; + + } else { + mainmenu_activemenu = mainmenu_gamemenu; + } + + } else { + mainmenu_activemenu = mainmenu_mainmenu; + } + + // show the requested menu and hide all other children + for (ui::Widget::Children::iterator child = children().begin(); child != children().end(); child++) { + if ((*child) == mainmenu_activemenu) { + (*child)->show(); + } else { + (*child)->hide(); + } + } +} + +void MainMenu::show_default() +{ + if (core::application()->connected() && core::game()->interactive()) { + show_menu(mainmenu_gamemenu); + } else { + show_menu(mainmenu_mainmenu); + } + +} +void MainMenu::show_menu(const Widget *widget) +{ + mainmenu_activemenu = 0; + + // show the requested menu and hide all other children + for (ui::Widget::Children::iterator child = children().begin(); child != children().end(); child++) { + if ((*child)== widget) { + (*child)->show(); + mainmenu_activemenu = (*child); + } else { + (*child)->hide(); + } + } + + show(); +} + +void MainMenu::show_menu(const char * label) +{ + mainmenu_activemenu = 0; + + for (ui::Widget::Children::iterator child = children().begin(); child != children().end(); ++child) { + if ((*child)->label().compare(label) == 0) { + (*child)->show(); + mainmenu_activemenu = (*child); + } else { + (*child)->hide(); + } + } + + show(); +} + void MainMenu::show() { - ui::Widget::show(); + if (!mainmenu_activemenu) + show_menu(); + ui::Window::show(); } void MainMenu::hide() { - ui::Widget::hide(); + ui::Window::hide(); + mainmenu_activemenu = 0; } void MainMenu::resize() -{ +{ // resize and reposition all child windows const float smallmargin = ui::UI::elementsize.height(); + for (ui::Widget::Children::iterator child = children().begin(); child != children().end(); ++child) { - (*child)->set_size(width() - smallmargin * 2, height() - smallmargin * 4); + (*child)->set_size(width() - smallmargin * 2, height() - smallmargin * 4); (*child)->set_location(smallmargin, smallmargin * 2); } } @@ -61,4 +315,52 @@ void MainMenu::draw_background() } } +void MainMenu::draw() +{ + if (mainmenu_activemenu == mainmenu_mainmenu) { + if (core::game()->interactive()) { + hide(); + return; + } + + } else if (mainmenu_activemenu == mainmenu_joinmenu) { + if (core::localcontrol()) { + hide(); + return; + } + + } else if (mainmenu_activemenu == mainmenu_gamemenu) { + if (!core::game()->interactive()) { + hide(); + return; + } + } + + ui::Window::draw(); +} + +bool MainMenu::on_keypress(const int key, const unsigned int modifier) +{ + if (key == SDLK_ESCAPE) { + if (mainmenu_activemenu == mainmenu_mainmenu) { + return true; + + } else if (mainmenu_activemenu == mainmenu_joinmenu) { + show_menu(mainmenu_gamemenu); + return true; + + } else if (mainmenu_activemenu == mainmenu_gamemenu) { + if (core::localcontrol()) { + hide(); + } else { + show_menu(mainmenu_joinmenu); + } + } else { + show_menu(); + } + } + + return true; +} + } // namespace client diff --git a/src/client/mainmenu.h b/src/client/mainmenu.h index 9320668..0a0354c 100644 --- a/src/client/mainmenu.h +++ b/src/client/mainmenu.h @@ -27,27 +27,65 @@ public: virtual void show(); virtual void hide(); + + /** + * @brief show the main or game menu, depending on the application state + * */ + void show_default(); + + /// show a submenu + void show_menu(const char * label); + + inline void show_menu(const std::string & label) { + show_menu(label.c_str()); + } + + /// load menu definitions + void load(); + protected: + + virtual void draw(); + virtual void draw_background(); virtual void resize(); - + + virtual bool on_keypress(const int key, const unsigned int modifier); + private: + /// load menu definitions + void load_definitions(); + + /// show the main, game or join menu + void show_menu(); + + void show_menu(const Widget *widget); + + /// the current active menu + ui::Widget *mainmenu_activemenu; + /// the menu to show if the application is not connected - ui::Window *mainmenu_mainmenu; + ui::Widget *mainmenu_mainmenu; + /// the menu to show if the application is connected but the player has not joined yet - ui::Window *mainmenu_joinmenu; + ui::Widget *mainmenu_joinmenu; + /// the menu the show if the application is connected and the player has joined - ui::Window *mainmenu_gamemenu; + ui::Widget *mainmenu_gamemenu; + /// the options menu - ui::Window *mainmenu_optionsmenu; + ui::Widget *mainmenu_optionsmenu; + /// the load game menu - ui::Window *mainmenu_loadmenu; + ui::Widget *mainmenu_loadmenu; + /// the save game menu - ui::Window *mainmenu_savemenu; + ui::Widget *mainmenu_savemenu; + /// the connect to server menu - ui::Window *mainmenu_connectmenu; + ui::Widget *mainmenu_connectmenu; std::string mainmenu_background; }; diff --git a/src/client/mainwindow.cc b/src/client/mainwindow.cc index 607e503..8e7b2af 100644 --- a/src/client/mainwindow.cc +++ b/src/client/mainwindow.cc @@ -79,6 +79,9 @@ void MainWindow::resize() // resize game window mainwindow_gamewindow->set_size(size()); + + // resize mainmenu window + mainwindow_mainmenu->set_size(size()); } void MainWindow::clear() @@ -114,14 +117,20 @@ void MainWindow::draw() } else { mainwindow_clockwidget->set_mode(ClockInfoWidget::Clock24Hours); } - - // FIXME - either draw one of the menus or draw the playerview - if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol() || (core::localplayer()->view() && !core::localplayer()->view()->menus().size())) { - if (mainwindow_gamewindow->visible()) - mainwindow_gamewindow->hide(); - } else { - if (!mainwindow_gamewindow->visible()) + + if (!mainwindow_mainmenu->visible()) { + + if (!core::game()->interactive() || !core::localcontrol()) { + mainwindow_mainmenu->show(); + + } else if (mainwindow_gamewindow->hidden()) { mainwindow_gamewindow->show(); + } + + } else { + if (mainwindow_gamewindow->visible()) { + mainwindow_gamewindow->hide(); + } } } diff --git a/src/client/mapwindow.cc b/src/client/mapwindow.cc index f1de585..244056b 100644 --- a/src/client/mapwindow.cc +++ b/src/client/mapwindow.cc @@ -151,173 +151,6 @@ void MapWindow::draw() set_target(mapwindow_target); } } - - /* - const float fontmargin = mapwindow_targetlabel->font()->height(); - const float s = ui::UI::elementsize.width() * 1.5f; - - const float blue = 0.8f; - const float gridsize = 16; - - const core::Entity *entity; - const core::Entity *current_target = mapwindow_target; - mapwindow_target = 0; - - math::Color color; - - math::Vector2f v(global_location()); - math::Vector2f l; - - v[0] += fontmargin; - v[1] += fontmargin + (height() - s) * 0.5f; - mapwindow_hover = 0; - - gl::color(0, 0, blue); - - gl::begin(gl::Lines); - for (int i = 0; i <= gridsize; i++) { - gl::vertex(v.x(), v.y() + s / gridsize * i); - gl::vertex(v.x() + s, v.y() + s / gridsize * i); - - gl::vertex(v.x() + s / gridsize * i, v.y()); - gl::vertex(v.x() + s / gridsize * i, v.y() + s); - } - gl::end(); - - const size_t texture_entity = render::Textures::load("bitmaps/icons/entity_default"); - const size_t texture_globe = render::Textures::load("bitmaps/icons/entity_globe"); - const size_t texture_bright = render::Textures::load("bitmaps/icons/entity_bright"); - - size_t texture_current = render::Textures::bind(texture_entity); - - v[0] += s * 0.5f; - v[1] += s * 0.5f; - - core::Zone *zone = core::localplayer()->zone(); - - mapwindow_maplabel->set_text(zone->name()); - - const math::Vector2f cursor(input::mouse_position_x(), input::mouse_position_y()); - - const float r = 12.0f; - float scale = 2048.0f; - scale *= 2; - - gl::enable(GL_TEXTURE_2D); - gl::begin(gl::Quads); - - // draw map icons - for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { - entity = (*it); - - bool draw_icon = false; - l.assign(v); - - if (targets::is_valid_map_target(entity)) { - draw_icon = true; - l[0] -= s / scale * entity->location().y(); - l[1] -= s / scale * entity->location().x(); - - if (math::distancesquared(cursor, l) < (r*r)) { - mapwindow_hover = entity->id(); - } - - if (entity == current_target) { - mapwindow_target = entity; - if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { - draw_icon = false; - } - } - } - - if (draw_icon) { - if (entity->type() == core::Entity::Globe) { - if (entity->flag_is_set(core::Entity::Bright)) { - if (texture_current != texture_bright) { - gl::end(); - texture_current = render::Textures::bind(texture_bright); - gl::begin(gl::Quads); - } - } else { - if (texture_current != texture_globe) { - gl::end(); - texture_current = render::Textures::bind(texture_globe); - gl::begin(gl::Quads); - } - } - } else { - if (texture_current != texture_entity) { - gl::end(); - texture_current = render::Textures::bind(texture_entity); - gl::begin(gl::Quads); - } - } - - if (entity == core::localplayer()->mission_target()) { - color.assign(palette()->mission()); - } else { - color.assign(entity->color()); - } - color.a = 1.0f; - - gl::color(color); - glTexCoord2f(0.0f, 0.0f); - gl::vertex(l.x() - r, l.y() - r); - - glTexCoord2f(1.0f, 0.0f); - gl::vertex(l.x() + r, l.y() - r); - - glTexCoord2f(1.0f, 1.0f); - gl::vertex(l.x() + r, l.y() + r); - - glTexCoord2f(0.0f, 1.0f); - gl::vertex(l.x() - r, l.y() + r); - } - - } - - // draw localcontrol icon - entity = core::localcontrol(); - - //if (core::localcontrol()->state() != core::Entity::Docked) { - l.assign(v); - l[0] -= s / scale * entity->location().y(); - l[1] -= s / scale * entity->location().x(); - if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { - if (texture_current != texture_entity) { - gl::end(); - texture_current = render::Textures::bind(texture_entity); - gl::begin(gl::Quads); - } - - math::Color color(entity->color()); - color.a = 1.0f; - gl::color(color); - glTexCoord2f(0.0f, 0.0f); - gl::vertex(l.x() - r, l.y() - r); - - glTexCoord2f(1.0f, 0.0f); - gl::vertex(l.x() + r, l.y() - r); - - glTexCoord2f(1.0f, 1.0f); - gl::vertex(l.x() + r, l.y() + r); - - glTexCoord2f(0.0f, 1.0f); - gl::vertex(l.x() - r, l.y() + r); - } - //} - - gl::end(); - gl::disable(GL_TEXTURE_2D); - - if (mapwindow_target != current_target ) { - // this makes sure the map target exists - set_target(current_target); - - } else if (mapwindow_inforecord && (mapwindow_infotimestamp != mapwindow_inforecord->timestamp())) { - set_target(mapwindow_target); - } - */ } void MapWindow::set_target(const core::Entity *entity) { @@ -385,7 +218,7 @@ bool MapWindow::on_keypress(const int key, const unsigned int modifier) return false; } -bool MapWindow::on_emit(Widget *sender, const Event event, void *data) +bool MapWindow::on_emit(ui::Widget *sender, const ui::Widget::Event event, void *data) { if (sender == mapwindow_closebutton) { if (event == ui::Widget::EventButtonClicked) { diff --git a/src/client/mapwindow.h b/src/client/mapwindow.h index 46fd8b1..66f8f45 100644 --- a/src/client/mapwindow.h +++ b/src/client/mapwindow.h @@ -40,7 +40,7 @@ protected: virtual bool on_keypress(const int key, const unsigned int modifier); /// called if the widget receives an emit evet - virtual bool on_emit(Widget *sender, const Event event, void *data); + virtual bool on_emit(ui::Widget *sender, const ui::Widget::Event event, void *data); virtual void resize(); diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index 36a1ac1..c753408 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -12,7 +12,6 @@ noinst_HEADERS = \ bitmap.h \ button.h \ console.h \ - container.h \ definitions.h \ font.h \ iconbutton.h \ @@ -20,7 +19,6 @@ noinst_HEADERS = \ label.h \ listitem.h \ listview.h \ - menu.h \ modelview.h \ paint.h \ palette.h \ @@ -36,14 +34,12 @@ libui_la_SOURCES = \ bitmap.cc \ button.cc \ console.cc \ - container.cc \ font.cc \ iconbutton.cc \ inputbox.cc \ label.cc \ listitem.cc \ listview.cc \ - menu.cc \ modelview.cc \ paint.cc \ palette.cc \ diff --git a/src/ui/container.cc b/src/ui/container.cc deleted file mode 100644 index ebe2821..0000000 --- a/src/ui/container.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* - ui/container.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/container.h" -#include "ui/paint.h" -#include "ui/ui.h" - -namespace ui -{ - -// TODO Container::direction -Container::Container(Widget *parent) : Window(parent) -{ - set_label("container"); - set_border(true); - set_background(true); -} - -Container::~Container() -{ -} - -void Container::resize() -{ - float w = UI::elementsize.width() * 1.5f; - float h = children().size() * (UI::elementsize.height() + UI::elementmargin) + UI::elementsize.height(); - set_size(w, h); - - const float x = UI::elementsize.width() * 0.25f; - float y = UI::elementsize.height() * 0.5f; - - // reposition all children within the container - for (Children::iterator it = children().begin(); it != children().end(); it++) { - Widget *w = (*it); - w->set_size(UI::elementsize); - w->set_location(x, y); - y += UI::elementsize.height() + UI::elementmargin; - } -} - -} diff --git a/src/ui/container.h b/src/ui/container.h deleted file mode 100644 index 4dbf150..0000000 --- a/src/ui/container.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - ui/container.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_UI_CONTAINER_H__ -#define __INCLUDED_UI_CONTAINER_H__ - -#include - -#include "ui/window.h" - -namespace ui -{ - -/// a widget containing childs of equal size -class Container : public Window -{ -public: - Container(Widget *parent); - ~Container(); - -protected: - - virtual void resize(); -}; - -} - -#endif // __INCLUDED_UI_CONTAINER_H__ - - diff --git a/src/ui/menu.cc b/src/ui/menu.cc deleted file mode 100644 index c4dc214..0000000 --- a/src/ui/menu.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* - 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 "filesystem/filesystem.h" -#include "ui/label.h" -#include "ui/button.h" -#include "ui/menu.h" -#include "ui/ui.h" - -namespace ui -{ - -Menu::Menu(Window *parent, const char *label) : Window(parent) -{ - set_label(label); - set_border(false); - set_background(false); - - menu_background = new Bitmap(this); - menu_container = new Container(this); - - hide(); -} - -Menu::~Menu() -{ - // menu_container and menu_background are deleted by Widget::~Widget() -} - -void Menu::set_background_texture(const char *texture) -{ - menu_background->set_texture(texture); -} - -void Menu::set_background_texture(const std::string &texture) -{ - menu_background->set_texture(texture); -} - -Label *Menu::add_label(char const * text) -{ - Label *label = new Label(menu_container, text); - label->set_alignment(AlignCenter); - label->set_border(false); - label->set_font(ui::root()->font_large()); - return label; -} - -Button *Menu::add_button(char const *text, char const *command) -{ - return new Button(menu_container, text, command); -} - -void Menu::resize() -{ - set_size(parent()->size()); - menu_background->set_size(size()); - menu_container->set_location(ui::UI::elementsize.height(), (height() - menu_container->height()) / 2.0f); -} - -bool Menu::on_keypress(const int key, const unsigned int modifier) -{ - switch (key) { - - case SDLK_ESCAPE: - if (visible()) { - this->hide(); - return true; - } - break; - - default: - break; - } - - return Window::on_keypress(key, modifier); -} - -} diff --git a/src/ui/menu.h b/src/ui/menu.h deleted file mode 100644 index 7fd211c..0000000 --- a/src/ui/menu.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - ui/menu.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_UI_MENU_H__ -#define __INCLUDED_UI_MENU_H__ - -#include "ui/bitmap.h" -#include "ui/container.h" -#include "ui/button.h" -#include "ui/label.h" -#include "ui/window.h" - -namespace ui -{ - -/// a menu container -class Menu : public Window -{ - -public: - /// create a new menu - Menu(Window *parent, const char * label = 0); - ~Menu(); - - /// set the background bitmap - void set_background_texture(const char *texture); - - /// set the background bitmap - void set_background_texture(const std::string &texture); - - /// add a label - Label *add_label(char const * text = 0); - - /// add a button with a command - Button *add_button(char const *text = 0, char const *command = 0); - -protected: - /// resize event - virtual void resize(); - - /// keypress event - virtual bool on_keypress(const int key, const unsigned int modifier); - -private: - Bitmap *menu_background; - Container *menu_container; -}; - -} - -#endif // __INCLUDED_UI_MENU_H__ diff --git a/src/ui/ui.cc b/src/ui/ui.cc index 93b5e16..4977d03 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -16,7 +16,6 @@ #include "sys/sys.h" #include "ui/button.h" #include "ui/label.h" -#include "ui/menu.h" #include "ui/paint.h" #include "ui/ui.h" #include "ui/widget.h" @@ -100,17 +99,8 @@ UI::~UI() void UI::load_settings() { - ui_active_menu = 0; ui_mouse_focus = this; - // clear any existing menus - Menus::iterator it; - for (it = ui_menus.begin(); it != ui_menus.end(); it++) { - Window *menu = (*it); - remove_child(menu); - } - ui_menus.clear(); - // open ui.ini std::string filename("ini/ui"); filesystem::IniFile ini; @@ -124,10 +114,6 @@ void UI::load_settings() std::string strval; math::Color color; - Button *button = 0; - Label *label = 0; - Menu *menu = 0; - float w = elementsize.width(); float h = elementsize.height(); float m = elementmargin; @@ -138,51 +124,20 @@ void UI::load_settings() if (ini.got_section()) { if (ini.got_section("ui")) { - menu = 0; continue; // section default colors } else if (ini.got_section("colors")) { - menu = 0; continue; // section hud configuration } else if (ini.got_section("hud")) { - menu = 0; continue; // section text colors } else if (ini.got_section("text")) { - menu = 0; - continue; - - // section menu - } else if (ini.got_section("menu")) { - label = 0; - button = 0; - menu = new Menu(this); - add_menu(menu); continue; - - // menu button - } else if (ini.got_section("button")) { - - if (!menu) { - ini.unknown_error("button section outside menu defintion"); - } else { - button = menu->add_button(); - } - - // menu label - } else if (ini.got_section("label")) { - - if (!menu) { - ini.unknown_error("label section outside menu defintion"); - } else { - label = menu->add_label(); - } - } else { ini.unknown_section(); continue; @@ -264,69 +219,6 @@ void UI::load_settings() ui_palette->set_error(color); } - // menu definitions - - } else if (menu) { - - if (ini.in_section("menu")) { - - if (ini.got_key_string("label", strval)) { - aux::to_label(strval); - menu->set_label(strval); - } else if (ini.got_key_string("background", strval)) { - menu->set_background_texture(strval); - } else { - ini.unknown_key(); - } - - } else if (ini.in_section("button")) { - - if (ini.got_key_string("text", strval)) { - aux::strip_quotes(strval); - button->set_text(strval); - - } else if (ini.got_key_string("command", strval)) { - for (size_t i = 0; i <= strval.size(); i++) { - if (strval[i] == ',') strval[i] = ';'; - } - aux::strip_quotes(strval); - button->set_command(strval); - - } else if (ini.got_key_string("align", strval)) { - aux::to_label(strval); - if (strval.compare("left") == 0) { - button->set_alignment(AlignLeft | AlignVCenter); - } else if (strval.compare("center") == 0) { - button->set_alignment(AlignCenter); - } else if (strval.compare("right") == 0) { - button->set_alignment(AlignRight | AlignVCenter); - } else { - ini.unknown_value(); - } - } else { - ini.unknown_key(); - } - - } else if (ini.in_section("label")) { - - if (ini.got_key_string("text", strval)) { - label->set_text(strval); - } else if (ini.got_key_string("align", strval)) { - aux::to_label(strval); - if (strval.compare("left") == 0) { - label->set_alignment(AlignLeft | AlignHCenter); - } else if (strval.compare("center") == 0) { - label->set_alignment(AlignCenter); - } else if (strval.compare("right") == 0) { - label->set_alignment(AlignRight | AlignHCenter); - } else { - ini.unknown_value(); - } - } else { - ini.unknown_key(); - } - } - } } } @@ -339,35 +231,6 @@ void UI::load_settings() Paint::assign_system_color('W', palette()->warning()); Paint::assign_system_color('E', palette()->error()); - con_debug << " " << ini.name() << " " << ui_menus.size() << " menus" << std::endl; - - // fallback main menu - if (!find_menu("main")) { - con_warn << "menu 'main' not found, using default" << std::endl; - Menu *menu = new Menu(this, "main"); - menu->add_label("Main Menu"); - menu->add_button("Connect", "connect"); - menu->add_button("Quit", "quit"); - } - - // fallback game menu - if (!find_menu("game")) { - con_warn << "menu 'game' not found, using default" << std::endl; - Menu *menu = new Menu(this, "game"); - menu->add_label("Game Menu"); - menu->add_button("Disconnect", "disconnect"); - menu->add_button("Quit", "quit"); - } - - // fallback join menu - if (!find_menu("join")) { - con_warn << "menu 'join' not found, using default" << std::endl; - Menu *menu = new Menu(this, "join"); - menu->add_label("Join Menu"); - menu->add_button("Join", "join; menu hide"); - menu->add_button("Game menu", "menu game"); - } - ini.close(); } @@ -383,100 +246,8 @@ void UI::list_visible() const con_print << n << " visible user interface widgets" << std::endl; } -UI::Menus::iterator UI::find_menu(Window *menu) -{ - Menus::iterator it; - for (it = ui_menus.begin(); it != ui_menus.end(); it++) { - if ((*it) == menu) - return it; - } - - return it; -} - -Window *UI::find_menu(const char *label) -{ - for (Menus::const_iterator it = ui_menus.begin(); it != ui_menus.end(); it++) { - if ((*it)->label().compare(label) == 0) { - return (*it); - } - } - - return 0; -} - -void UI::list_menus() const -{ - for (Menus::const_iterator it = ui_menus.begin(); it != ui_menus.end(); it++) { - const Window *menu = (*it); - con_print << " " << menu->label() << std::endl; - } - con_print << ui_menus.size() << " menus" << std::endl; -} - -void UI::add_menu(Window *menu) -{ - Menus::iterator it = find_menu(menu); - if (it == ui_menus.end()) { - ui_menus.push_back(menu); - } - -} - -void UI::show_menu(const char *label) -{ - Window *menu = find_menu(label); - - if (menu) { - if (ui_active_menu) { - ui_active_menu->hide(); - menu->set_previous(ui_active_menu); - } else { - menu->clear_previous(); - } - ui_mouse_focus = this; - ui_input_focus = this; - - ui_active_menu = menu; - ui_active_menu->event_resize(); - ui_active_menu->show(); - - set_pointer("pointer"); - - // raise console if it is visible - if (ui_console->visible()) - ui_console->show(); - - } else { - con_warn << "Unknown window '" << label << "'" << std::endl; - } -} - -void UI::hide_menu() -{ - if (ui_active_menu) { - ui_active_menu->hide(); - ui_active_menu = 0; - } -} - -void UI::previous_menu() -{ - if (ui_active_menu) { - if (ui_active_menu->previous().size()) { - show_menu(ui_active_menu->previous().c_str()); - } else { - hide_menu(); - } - } -} - void UI::frame() { - if (ui_active_menu && !ui_active_menu->visible()) { - ui_active_menu = 0; - } - ui_input_focus = find_input_focus(); Widget *f = find_mouse_focus(mouse_cursor); if (f) { @@ -532,19 +303,6 @@ bool UI::input_key(const bool pressed, const int key, const unsigned int modifie bool UI::on_keypress(const int key, const unsigned int modifier) { - switch (key) { - - case SDLK_ESCAPE: - if (active()) { - hide_menu(); - //audio::play("ui/menu"); - } - return true; - break; - default: - break; - } - return false; } diff --git a/src/ui/ui.h b/src/ui/ui.h index b3bb43b..cd2e38c 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -31,28 +31,11 @@ public: /// list visible widgets void list_visible() const; - /// list meus - void list_menus() const; - - /// make a window the active window - void show_menu(const char *label); - - /// hide the active window - void hide_menu(); - - /// show previous window - void previous_menu(); - /// the console inline Console *console() { return ui_console; } - /// return the active menu - Window *active() { - return ui_active_menu; - } - /// return the widget with global mouse focus inline Widget *mouse_focus() const { return ui_mouse_focus; @@ -108,13 +91,6 @@ public: static math::Vector2f elementsize; protected: - typedef std::list Menus; - - Menus::iterator find_menu(Window *menu); - Window *find_menu(const char *label); - - void add_menu(Window *window); - /* -- event handlers --------------------------------------- */ /// handle keypress events @@ -131,14 +107,11 @@ private: Font *ui_font_small; Font *ui_font_large; - Window *ui_active_menu; Widget *ui_mouse_focus; Widget *ui_input_focus; Console *ui_console; - Menus ui_menus; - /// TODO move to separate object to handle mouse cursor drawing math::Vector2f mouse_cursor; std::string mouse_pointer_bitmap; diff --git a/src/ui/widget.cc b/src/ui/widget.cc index 709731e..6d0fb84 100644 --- a/src/ui/widget.cc +++ b/src/ui/widget.cc @@ -76,10 +76,18 @@ void Widget::print(const size_t indent) const { if (indent) { std::string marker; - if (widget_focus) - marker.assign("^B* ^N"); - else + if (!widget_enabled) { + marker.assign("^B- "); + } else if (widget_focus) { + marker.assign("^B* "); + } else { marker.assign(" "); + } + if (widget_visible) { + marker.append("^N"); + } else { + marker.append("^D"); + } con_print << aux::pad_left(marker, indent*2) << label() << std::endl; } } diff --git a/src/ui/widget.h b/src/ui/widget.h index 9aae10e..77a84c2 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -291,7 +291,7 @@ protected: /// find the widget that has input focus virtual Widget *find_input_focus(); - /// find widget that has mosue focus + /// find widget that has mouse focus /** @param cursor mouse cursor position relative to this widget's location */ Widget *find_mouse_focus(const math::Vector2f & cursor); -- cgit v1.2.3