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-26 22:12:04 +0000
committerStijn Buys <ingar@osirion.org>2009-01-26 22:12:04 +0000
commit76a49efdf62a53a54e2deeb559422f11c1e955dd (patch)
tree883d335f03dcd24002b749456d05db1602b09fd5 /src/ui/ui.cc
parent8ee6f0c6effeffd6fa3322149435c9a5aba7120f (diff)
read main menus from menu.ini
Diffstat (limited to 'src/ui/ui.cc')
-rw-r--r--src/ui/ui.cc159
1 files changed, 134 insertions, 25 deletions
diff --git a/src/ui/ui.cc b/src/ui/ui.cc
index e9036c5..ff6810f 100644
--- a/src/ui/ui.cc
+++ b/src/ui/ui.cc
@@ -44,7 +44,8 @@ void func_list_ui(std::string const &args)
void func_ui_restart(std::string const &args)
{
if (global_ui) {
- global_ui->load();
+ global_ui->load_menus();
+ global_ui->load_settings();
global_ui->apply_render_options();
}
}
@@ -94,7 +95,8 @@ void func_ui(std::string const &args)
} else if (command.compare("list") == 0) {
global_ui->list();
} else if (command.compare("restart") == 0) {
- global_ui->load();
+ global_ui->load_menus();
+ global_ui->load_settings();
global_ui->apply_render_options();
} else {
help();
@@ -170,8 +172,9 @@ void init()
con_warn << "User interface already initialized!" << std::endl;
return;
}
-
- global_ui->load();
+
+ 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");
@@ -245,10 +248,7 @@ UI::~UI()
delete ui_font_large;
}
-/*
- remove all existing child windows and load ini/ui.ini
-*/
-void UI::load()
+void UI::load_menus()
{
Menus::iterator it;
for (it = ui_menus.begin(); it != ui_menus.end(); it++) {
@@ -257,15 +257,138 @@ void UI::load()
}
ui_menus.clear();
+ // add specia view menu
add_menu(new MenuView(this, "view"));
+ 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;
ui_active_menu = 0;
std::string filename("ui");
-
filesystem::IniFile ini;
-
ini.open(filename);
if (!ini.is_open()) {
@@ -275,7 +398,6 @@ void UI::load()
std::string strval;
math::Color color;
- Menu *menu = 0;
float w = elementsize.width();
float h = elementsize.height();
@@ -285,9 +407,6 @@ void UI::load()
while (ini.getline()) {
if (ini.got_section()) {
-
- //con_debug << " " << ini.name() << " [" << ini.section() << "]" << std::endl;
-
if (ini.got_section("ui")) {
continue;
@@ -307,17 +426,8 @@ void UI::load()
} 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());
- add_menu(menu);
- menu->load();
- continue;
- } else if (ini.got_key_float("elementwidth", w)) {
+ if (ini.got_key_float("elementwidth", w)) {
elementsize.assign(w, h);
continue;
} else if (ini.got_key_float("elementheight", h)) {
@@ -389,7 +499,6 @@ void UI::load()
}
}
- con_debug << " " << ini.name() << " " << ui_menus.size() << " menus" << std::endl;
ini.close();
// fallback main menu