From 9c2d1a1c867bbd7eea083dbc03c0acf1edace8c2 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 27 Jan 2009 18:53:24 +0000 Subject: moves docking menus from ui to client, allow map and chat window while docked --- src/ui/ui.cc | 207 ++++++----------------------------------------------------- 1 file changed, 19 insertions(+), 188 deletions(-) (limited to 'src/ui/ui.cc') diff --git a/src/ui/ui.cc b/src/ui/ui.cc index ff6810f..f96f692 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -17,7 +17,6 @@ #include "ui/button.h" #include "ui/label.h" #include "ui/menu.h" -#include "ui/menuview.h" #include "ui/paint.h" #include "ui/ui.h" #include "ui/widget.h" @@ -34,129 +33,6 @@ math::Vector2f UI::elementsize(256, 48); UI *global_ui = 0; -void func_list_ui(std::string const &args) -{ - if (global_ui) { - global_ui->list(); - } -} - -void func_ui_restart(std::string const &args) -{ - if (global_ui) { - global_ui->load_menus(); - global_ui->load_settings(); - global_ui->apply_render_options(); - } -} - - -void func_ui_console(std::string const &args) -{ - console()->toggle(); -} - -void func_list_menu(std::string const &args) -{ - if (global_ui) { - global_ui->list_menus(); - } -} - -void help() -{ - con_print << "^BUser interface functions" << std::endl; - con_print << " ui help show this help" << std::endl; - con_print << " ui debug toggle debug mode" << std::endl; - con_print << " ui list list widgets" << std::endl; - con_print << " ui restart reload user interface files" << std::endl; -} - -void func_ui(std::string const &args) -{ - if (!global_ui) { - con_warn << "User Interface not available!" << std::endl; - return; - } - - if (!args.size()) { - help(); - return; - } - std::stringstream argstr(args); - std::string command; - argstr >> command; - aux::to_label(command); - - if (command.compare("help") == 0) { - help(); - } else if (command.compare("debug") == 0) { - UI::ui_debug = !UI::ui_debug; - } else if (command.compare("list") == 0) { - global_ui->list(); - } else if (command.compare("restart") == 0) { - global_ui->load_menus(); - global_ui->load_settings(); - global_ui->apply_render_options(); - } else { - help(); - } -} - -void help_menu() -{ - 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; - root()->list_menus(); -} - -void func_menu(std::string const &args) -{ - if (!global_ui) { - con_warn << "User Interface not available!" << std::endl; - return; - } - - if (!args.size()) { - return; - } - std::stringstream argstr(args); - std::string command; - argstr >> command; - - aux::to_label(command); - - if (command.compare("hide") == 0) { - root()->hide_menu(); - - } else if (command.compare("close") == 0) { - root()->hide_menu(); - - } else if (command.compare("back") == 0) { - root()->previous_menu(); - - } else if (command.compare("previous") == 0) { - root()->previous_menu(); - - } else if (command.compare("list") == 0) { - root()->list_menus(); - } else if (command.compare("view") == 0) { - std::string label; - if (!(argstr >> label)) { - label.assign("main"); - } - root()->show_menuview(label); - } else { - root()->show_menu(command.c_str()); - } -} - UI *root() { return global_ui; @@ -175,36 +51,12 @@ void init() global_ui->load_menus(); global_ui->load_settings(); - - core::Func *func = core::Func::add("list_ui", func_list_ui); - func->set_info("list user interface widgets"); - - func = core::Func::add("list_menu", func_list_menu); - func->set_info("list available menus"); - - func = core::Func::add("ui", func_ui); - func->set_info("[command] user interface functions"); - - func = core::Func::add("ui_restart", func_ui_restart); - func->set_info("reload user interface files"); - - func = core::Func::add("ui_console", func_ui_console); - func->set_info("toggle console on or off"); - - func = core::Func::add("menu", func_menu); - func->set_info("[command] menu functions"); } void shutdown() { con_print << "^BShutting down user interface..." << std::endl; - - core::Func::remove("list_ui"); - core::Func::remove("list_menu"); - core::Func::remove("menu"); - core::Func::remove("ui_console"); - core::Func::remove("ui"); - + if (global_ui) { delete global_ui; global_ui = 0; @@ -257,9 +109,6 @@ void UI::load_menus() } ui_menus.clear(); - // add specia view menu - add_menu(new MenuView(this, "view")); - std::string filename("menu"); filesystem::IniFile ini; ini.open(filename); @@ -588,20 +437,6 @@ void UI::add_menu(Window *menu) } -void UI::show_menuview(const std::string &label) -{ - if (!core::localplayer()->view()) - return; - - if (!core::localplayer()->view()->menus().size()) - return; - - MenuView *menuview = static_cast(find_menu("view")); - menuview->generate(core::localplayer()->view(), label.c_str()); - - show_menu("view"); -} - void UI::show_menu(const char *label) { Window *menu = find_menu(label); @@ -655,7 +490,14 @@ 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) { + f->event_mouse(mouse_cursor); + } + ui_mouse_focus = f; + event_draw(); if (visible()) @@ -670,11 +512,6 @@ void UI::frame() void UI::input_mouse(const float x, const float y) { mouse_cursor.assign(x, y); - Widget *f = find_mouse_focus(mouse_cursor); - if (f) { - f->event_mouse(mouse_cursor); - } - ui_mouse_focus = f; } bool UI::input_key(const bool pressed, const int key, const unsigned int modifier) @@ -688,7 +525,13 @@ bool UI::input_key(const bool pressed, const int key, const unsigned int modifie } ui_input_focus = f; } else { - // mosue buttons + // mouse buttons + Widget *f = find_mouse_focus(mouse_cursor); + if (f) { + f->event_mouse(mouse_cursor); + } + ui_mouse_focus = f; + if (ui_mouse_focus) handled = ui_mouse_focus->event_key(pressed, key, modifier); } @@ -701,21 +544,9 @@ bool UI::on_keypress(const int key, const unsigned int modifier) case SDLK_ESCAPE: if (active()) { - if (active()->label().compare("view") == 0) { - if (core::application()->connected()) { - show_menu("game"); - audio::play("ui/menu"); - } - } else { - hide_menu(); - audio::play("ui/menu"); - } - } else { - if (core::application()->connected()) { - show_menu("game"); - audio::play("ui/menu"); - } - } + hide_menu(); + audio::play("ui/menu"); + } return true; break; default: -- cgit v1.2.3