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")+")");
47 std::set<std::string> languages = dictionary_manager.get_languages();
48 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
49 std::string locale_name = *i;
50 TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name);
51 std::string locale_fullname = locale_name;
52 if (std::string(ldef.code) == locale_name) {
53 locale_fullname = ldef.name;
55 add_entry(mnid++, locale_fullname);
62 virtual void menu_action(MenuItem* item) {
65 dictionary_manager.set_language(config->locale);
70 std::set<std::string> languages = dictionary_manager.get_languages();
71 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
72 std::string locale_name = *i;
73 if (item->id == mnid++) {
74 config->locale = locale_name;
75 dictionary_manager.set_language(config->locale);
84 class OptionsMenu : public Menu
88 virtual ~OptionsMenu();
90 virtual void menu_action(MenuItem* item);
93 std::auto_ptr<LanguageMenu> language_menu;
97 OptionsMenu::OptionsMenu()
99 language_menu.reset(new LanguageMenu());
101 add_label(_("Options"));
103 add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen);
104 add_submenu(_("Language"), language_menu.get());
105 if (sound_manager->is_audio_enabled()) {
106 add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled);
107 add_toggle(MNID_MUSIC, _("Music"), config->music_enabled);
109 add_deactive(MNID_SOUND, _("Sound (disabled)"));
110 add_deactive(MNID_SOUND, _("Music (disabled)"));
112 add_submenu(_("Setup Keyboard"), main_controller->get_key_options_menu());
113 add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu());
118 OptionsMenu::~OptionsMenu()
123 OptionsMenu::menu_action(MenuItem* item)
126 case MNID_FULLSCREEN:
127 if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
128 config->use_fullscreen = !config->use_fullscreen;
134 if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
135 config->sound_enabled = !config->sound_enabled;
136 sound_manager->enable_sound(config->sound_enabled);
141 if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
142 config->music_enabled = !config->music_enabled;
143 sound_manager->enable_music(config->music_enabled);
152 Menu* get_options_menu()
154 //if(options_menu == NULL)
155 options_menu = new OptionsMenu();
160 void free_options_menu()