From a14d80f83aebe75241bf63b4f3ffca3a5d952577 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 6 Oct 2008 18:22:32 +0000 Subject: libui updates, support menu .ini files --- src/ui/ui.cc | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 108 insertions(+), 12 deletions(-) (limited to 'src/ui/ui.cc') diff --git a/src/ui/ui.cc b/src/ui/ui.cc index be75f11..ac5c0b8 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -9,6 +9,7 @@ #include "auxiliary/functions.h" #include "core/core.h" +#include "filesystem/filesystem.h" #include "sys/sys.h" #include "ui/button.h" #include "ui/label.h" @@ -28,6 +29,14 @@ void func_list_ui(std::string const &args) } } + +void func_list_menu(std::string const &args) +{ + if (global_ui) { + global_ui->list_menus(); + } +} + void help() { con_print << "^BUser interface functions" << std::endl; @@ -35,6 +44,7 @@ void help() con_print << " ui list list widgets" << std::endl; con_print << " ui show show user interface" << std::endl; con_print << " ui hide hide user interface" << std::endl; + con_print << " ui restart reload menu files" << std::endl; } void func_ui(std::string const &args) @@ -61,6 +71,8 @@ void func_ui(std::string const &args) global_ui->show(); } else if (command.compare("hide") == 0) { global_ui->hide(); + } else if (command.compare("restart") == 0) { + global_ui->load(); } else { help(); } @@ -89,7 +101,7 @@ void func_menu(std::string const &args) root()->hide_window(); } else if (command.compare("list") == 0) { - + root()->list_menus(); } else { root()->show_window(command.c_str()); } @@ -109,6 +121,9 @@ void init() 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] [options] user interface subcommands"); @@ -121,6 +136,7 @@ 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"); @@ -143,23 +159,87 @@ UI::UI() : Window(0) set_size(1024, 768); set_border(false); + load(); +} + +void UI::load() +{ + Windows::iterator it; + for (it = window_children.begin(); it != window_children.end(); it++) { + Window *window = (*it); + remove_child(window); + } + window_children.clear(); ui_active_window = 0; + std::string filename("ui"); + + filesystem::IniFile ini; + + ini.open(filename); + + if (!ini.is_open()) { + con_error << "Could not open " << ini.name() << std::endl; + return; + } + + std::string strval; + math::Color color; Menu *menu = 0; + + while (ini.getline()) { + + if (ini.got_section()) { - menu = new Menu(this, "main"); - menu->add_label("Main menu"); - menu->add_button("New Game", "connect"); - menu->add_button("Connect to...", "menu connect"); - menu->add_button("Options...", "menu options"); - menu->add_button("Quit", "quit"); + //con_debug << " " << ini.name() << " [" << ini.section() << "]" << std::endl; - menu = new Menu(this, "options"); - menu->add_label("Options menu"); + if (ini.got_section("ui")) { + continue; + + } else if (ini.got_section("colors")) { + continue; + + } else { + ini.unknown_section(); + continue; + } + + } else if (ini.got_key()) { + + //con_debug << " " << ini.name() << " " << ini.key() << "=" << ini.value() << std::endl; + + if (ini.in_section("ui")) { + + if (ini.got_key_string("menu", strval)) { + aux::to_label(strval); + menu = new Menu(this, strval.c_str()); + menu->load(); + continue; + } else { + ini.unkown_key(); + } + + } else if (ini.in_section("colors")) { + + if (ini.got_key_color("foreground", color)) { + widget_palette->set_foreground(color); + continue; + } else if (ini.got_key_color("background", color)) { + widget_palette->set_background(color); + continue; + } else if (ini.got_key_color("border", color)) { + widget_palette->set_border(color); + continue; + } else { + ini.unkown_key(); + } + } + } + } - menu = new Menu(this, "connect"); - menu->add_label("Connect to..."); -} + con_debug << " " << ini.name() << " " << window_children.size() << " menus" << std::endl; + ini.close(); +} UI::~UI() { @@ -173,6 +253,16 @@ void UI::list() con_print << n << " user interface widgets" << std::endl; } +void UI::list_menus() +{ + Windows::iterator it; + for (it = window_children.begin(); it != window_children.end(); it++) { + Window *window = (*it); + con_print << " " << window->label() << std::endl; + } + con_print << window_children.size() << " menus" << std::endl; +} + void UI::add_window(Window *window) { Window::add_window(window); @@ -183,6 +273,7 @@ void UI::remove_window(Window *window) { if (ui_active_window == window) ui_active_window = 0; + Window::remove_window(window); } @@ -211,4 +302,9 @@ void UI::hide_window() } } +void UI::set_mouse_cursor(float x, float y) +{ + mouse_cursor.assign(x, y); +} + } -- cgit v1.2.3