Permalink
Browse files

Added language selection dialog (ugly)

Need to fix:
  Layout of the pause game dialog
  Layout of the language dialog
  Missing characters for the label "Chinese"
  • Loading branch information...
1 parent 8c1b17f commit a924fb25acc6ca19c2042faa188f87320226ace2 @hagabaka hagabaka committed Jan 3, 2013
Showing with 87 additions and 0 deletions.
  1. +1 −0 Makefile.common
  2. +16 −0 data/languages.cfg
  3. +63 −0 src/language_dialog.cpp
  4. +2 −0 src/language_dialog.hpp
  5. +5 −0 src/pause_game_dialog.cpp
View
@@ -94,6 +94,7 @@ objects = \
key.o \
key_button.o \
label.o \
+ language_dialog.o \
level.o \
level_logic.o \
level_object.o \
View
@@ -0,0 +1,16 @@
+{
+ "de": "Deutsch",
+// "el": "Ελληνικά (Ellinika)",
+ "en": "English",
+// "eo": "Esperanto",
+ "es": "Español",
+ "fr": "Français",
+ "gd": "Gàidhlig",
+ "it": "Italiano",
+// "ja": "日本語 (Nihongo)",
+// "pl": "Polski",
+ "pt_BR": "Português (Brasil)",
+// "ru": "Русский (Russkij)",
+// "sk": "Slovenčina",
+ "zh_CN": "简体中文 (Jiăntĭ Zhōngwén)",
+}
View
@@ -0,0 +1,63 @@
+
+#include <boost/bind.hpp>
+
+#include "button.hpp"
+#include "language_dialog.hpp"
+#include "dialog.hpp"
+#include "draw_scene.hpp"
+#include "graphical_font_label.hpp"
+#include "i18n.hpp"
+#include "level.hpp"
+#include "preferences.hpp"
+#include "json_parser.hpp"
+#include "foreach.hpp"
+
+namespace {
+void end_dialog(gui::dialog* d)
+{
+
+ d->close();
+}
+
+void do_draw_scene() {
+ draw_scene(level::current(), last_draw_position());
+}
+
+void set_locale(const std::string& value) {
+ preferences::set_locale(value);
+ i18n::init();
+ graphical_font::init_for_locale(i18n::get_locale());
+}
+}
+
+void show_language_dialog()
+{
+ using namespace gui;
+ int height = preferences::virtual_screen_height() - 20;
+ if (preferences::virtual_screen_height() > 480)
+ height -= 100;
+ dialog d(50, (preferences::virtual_screen_height() > 480) ? 60 : 10, preferences::virtual_screen_width()-100, height);
+ d.set_background_frame("empty_window");
+ d.set_draw_background_fn(do_draw_scene);
+
+ typedef std::map<variant, variant> variant_map;
+ variant_map languages = json::parse_from_file("data/languages.cfg").as_map();
+ foreach(variant_map::value_type pair, languages) {
+ widget_ptr b(new button(
+ widget_ptr(new graphical_font_label(pair.second.as_string(), "door_label", 2)),
+ boost::bind(set_locale, pair.first.as_string()),
+ BUTTON_STYLE_NORMAL, BUTTON_SIZE_DOUBLE_RESOLUTION));
+ d.add_widget(b);
+ }
+
+ widget_ptr system_button(new button(
+ widget_ptr(new graphical_font_label(_("Use system language"), "door_label", 2)),
+ boost::bind(set_locale, "system"),
+ BUTTON_STYLE_NORMAL, BUTTON_SIZE_DOUBLE_RESOLUTION));
+ d.add_widget(system_button);
+
+ widget_ptr back_button(new button(widget_ptr(new graphical_font_label(_("Back"), "door_label", 2)), boost::bind(end_dialog, &d), BUTTON_STYLE_DEFAULT, BUTTON_SIZE_DOUBLE_RESOLUTION));
+ d.add_widget(back_button);
+
+ d.show_modal();
+}
View
@@ -0,0 +1,2 @@
+void show_language_dialog();
+
@@ -13,6 +13,7 @@
#include "preferences.hpp"
#include "sound.hpp"
#include "of_bridge.h"
+#include "language_dialog.hpp"
namespace {
void end_dialog(gui::dialog* d, PAUSE_GAME_RESULT* result, PAUSE_GAME_RESULT value)
@@ -72,6 +73,7 @@ PAUSE_GAME_RESULT show_pause_game_dialog()
widget_ptr b1(new button(widget_ptr(new graphical_font_label(_("Resume"), "door_label", 2)), boost::bind(end_dialog, &d, &result, PAUSE_GAME_CONTINUE), BUTTON_STYLE_NORMAL, BUTTON_SIZE_DOUBLE_RESOLUTION));
widget_ptr b2(new button(widget_ptr(new graphical_font_label(_("Controls..."), "door_label", 2)), show_controls_dialog, BUTTON_STYLE_NORMAL, BUTTON_SIZE_DOUBLE_RESOLUTION));
+ widget_ptr language_button(new button(widget_ptr(new graphical_font_label(_("Language..."), "door_label", 2)), show_language_dialog, BUTTON_STYLE_NORMAL, BUTTON_SIZE_DOUBLE_RESOLUTION));
widget_ptr b3(new button(widget_ptr(new graphical_font_label(_("Return to Titlescreen"), "door_label", 2)), boost::bind(end_dialog, &d, &result, PAUSE_GAME_GO_TO_TITLESCREEN), BUTTON_STYLE_NORMAL, BUTTON_SIZE_DOUBLE_RESOLUTION));
widget_ptr b4(new button(widget_ptr(new graphical_font_label(_("Exit Game"), "door_label", 2)), boost::bind(end_dialog, &d, &result, PAUSE_GAME_QUIT), BUTTON_STYLE_DEFAULT, BUTTON_SIZE_DOUBLE_RESOLUTION));
widget_ptr b5(new checkbox(_("Reverse A and B"), preferences::reverse_ab(), boost::bind(preferences::set_reverse_ab, _1), BUTTON_SIZE_DOUBLE_RESOLUTION));
@@ -84,6 +86,7 @@ PAUSE_GAME_RESULT show_pause_game_dialog()
b3->set_dim(button_width, button_height);
b4->set_dim(button_width, button_height);
b5->set_dim(button_width, button_height);
+ language_button->set_dim(button_width, button_height);
#ifdef ENABLE_OPENFEINT
b6->set_dim(button_width, button_height);
#endif
@@ -105,6 +108,7 @@ PAUSE_GAME_RESULT show_pause_game_dialog()
#ifdef ENABLE_OPENFEINT
if (show_of) d.add_widget(b6);
#endif
+ d.add_widget(language_button);
d.add_widget(b3);
if (show_exit) d.add_widget(b4);
} else {
@@ -116,6 +120,7 @@ PAUSE_GAME_RESULT show_pause_game_dialog()
d.set_padding(padding+16);
d.add_widget(s2);
d.set_padding(padding);
+ d.add_widget(language_button);
d.add_widget(b3);
if (show_exit) d.add_widget(b4);
}

0 comments on commit a924fb2

Please sign in to comment.