4 // Copyright (C) 2004 Tobas Glaesser <tobi.web@gmx.de>
5 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "options_menu.hpp"
23 #include "gui/menu.hpp"
24 #include "audio/sound_manager.hpp"
25 #include "control/joystickkeyboardcontroller.hpp"
27 #include "gettext.hpp"
28 #include "gameconfig.hpp"
30 Menu* options_menu = 0;
38 class LanguageMenu : public Menu
42 add_label(_("Language"));
44 add_entry(0, std::string("(")+_("auto-detect language")+")");
45 add_entry(1, "English");
48 std::set<std::string> languages = dictionary_manager.get_languages();
49 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
50 std::string locale_name = *i;
51 TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name);
52 std::string locale_fullname = locale_name;
53 if (std::string(ldef.code) == locale_name) {
54 locale_fullname = ldef.name;
56 add_entry(mnid++, locale_fullname);
63 virtual void menu_action(MenuItem* item) {
66 dictionary_manager.set_language(config->locale);
70 else if (item->id == 1) {
71 config->locale = "en";
72 dictionary_manager.set_language(config->locale);
77 std::set<std::string> languages = dictionary_manager.get_languages();
78 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
79 std::string locale_name = *i;
80 if (item->id == mnid++) {
81 config->locale = locale_name;
82 dictionary_manager.set_language(config->locale);
91 class OptionsMenu : public Menu
95 virtual ~OptionsMenu();
97 virtual void menu_action(MenuItem* item);
100 std::auto_ptr<LanguageMenu> language_menu;
104 OptionsMenu::OptionsMenu()
106 language_menu.reset(new LanguageMenu());
108 add_label(_("Options"));
110 add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen);
111 add_submenu(_("Language"), language_menu.get());
112 if (sound_manager->is_audio_enabled()) {
113 add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled);
114 add_toggle(MNID_MUSIC, _("Music"), config->music_enabled);
116 add_deactive(MNID_SOUND, _("Sound (disabled)"));
117 add_deactive(MNID_SOUND, _("Music (disabled)"));
119 add_submenu(_("Setup Keyboard"), main_controller->get_key_options_menu());
120 add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu());
125 OptionsMenu::~OptionsMenu()
130 OptionsMenu::menu_action(MenuItem* item)
133 case MNID_FULLSCREEN:
134 if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
135 config->use_fullscreen = !config->use_fullscreen;
141 if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
142 config->sound_enabled = !config->sound_enabled;
143 sound_manager->enable_sound(config->sound_enabled);
148 if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
149 config->music_enabled = !config->music_enabled;
150 sound_manager->enable_music(config->music_enabled);
159 Menu* get_options_menu()
161 //static OptionsMenu menu;
162 options_menu = new OptionsMenu();
166 void free_options_menu()