From 787002ec11bf41bba01b899c53a38830768fc260 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 25 Oct 2010 12:40:53 +0000 Subject: directory prefix is no required for ini files, merge ui.ini and menu.ini --- src/ui/ui.cc | 283 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 142 insertions(+), 141 deletions(-) (limited to 'src/ui/ui.cc') diff --git a/src/ui/ui.cc b/src/ui/ui.cc index 5faf9fd..de881cb 100644 --- a/src/ui/ui.cc +++ b/src/ui/ui.cc @@ -48,9 +48,6 @@ void init() con_warn << "User interface already initialized!" << std::endl; return; } - - global_ui->load_menus(); - global_ui->load_settings(); } void shutdown() @@ -100,144 +97,21 @@ UI::~UI() delete ui_font_large; } -void UI::load_menus() +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(); - - std::string filename("menu"); - filesystem::IniFile ini; - ini.open(filename); - if (!ini.is_open()) { - con_error << "Could not open " << ini.name() << std::endl; - } else { - std::string strval; - Button *button = 0; - Label *label = 0; - Menu *menu = 0; - - while (ini.getline()) { - if (ini.got_section()) { - if (ini.got_section("menu")) { - menu = new Menu(this); - add_menu(menu); - continue; - } else if (menu) { - if (ini.got_section("button")) { - button = menu->add_button(); - - } else if (ini.got_section("label")) { - label = menu->add_label(); - - } else { - ini.unknown_section(); - } - } else { - ini.unknown_section(); - } - } else if (menu && ini.got_key()) { - 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.unkown_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.unkown_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.unkown_key(); - } - } - - } - } - - con_debug << " " << ini.name() << " " << ui_menus.size() << " menus" << std::endl; - ini.close(); - } - - // 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"); - } -} - - -void UI::load_settings() -{ - - ui_mouse_focus = this; - - std::string filename("ui"); + + // open ui.ini + std::string filename("ini/ui"); filesystem::IniFile ini; ini.open(filename); @@ -248,6 +122,10 @@ 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(); @@ -257,18 +135,53 @@ void UI::load_settings() while (ini.getline()) { 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; @@ -349,24 +262,112 @@ void UI::load_settings() } else if (ini.got_key_color("error", color)) { 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.unkown_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.unkown_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.unkown_key(); + } + } + } } } - - ini.close(); -} - -void UI::apply_render_options() -{ - //con_debug << " initializing text colors" << std::endl; - // apply palette colors + + // apply palette colors to the render subsystem Paint::assign_system_color('N', palette()->text()); Paint::assign_system_color('D', palette()->debug()); Paint::assign_system_color('B', palette()->bold()); Paint::assign_system_color('F', palette()->fancy()); 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(); } void UI::list() const -- cgit v1.2.3