Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-10-25 12:40:53 +0000
committerStijn Buys <ingar@osirion.org>2010-10-25 12:40:53 +0000
commit787002ec11bf41bba01b899c53a38830768fc260 (patch)
tree5a4b4e60617b0167a9e32a3882342a85f0fde4ab /src/ui
parent6a86e7f0f9e021498c1df44653a42643bd79dfbf (diff)
directory prefix is no required for ini files, merge ui.ini and menu.ini
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/ui.cc283
-rw-r--r--src/ui/ui.h14
2 files changed, 146 insertions, 151 deletions
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
diff --git a/src/ui/ui.h b/src/ui/ui.h
index c340eb8..c611a26 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -34,15 +34,6 @@ public:
/// list meus
void list_menus() const;
- /// load menus from menu.ini
- void load_menus();
-
- /// load settings from ui.ini
- void load_settings();
-
- /// apply UI options to the render engine
- void apply_render_options();
-
/// make a window the active window
void show_menu(const char *label);
@@ -81,6 +72,9 @@ public:
/// run a user interface frame
void frame();
+ /// load settings from ui.ini
+ void load_settings();
+
/* -- fonts ------------------------------------------------ */
/// default small font
@@ -121,7 +115,7 @@ protected:
/// handle key release events
virtual bool on_keyrelease(const int key, const unsigned int modifier);
-private:
+private:
void draw_pointer();
Palette *ui_palette;