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 "profile_menu.hpp"
23 #include "options_menu.hpp"
24 #include "gui/menu.hpp"
25 #include "audio/sound_manager.hpp"
26 #include "control/joystickkeyboardcontroller.hpp"
28 #include "gettext.hpp"
29 #include "gameconfig.hpp"
31 Menu* options_menu = 0;
40 class LanguageMenu : public Menu
44 add_label(_("Language"));
46 add_entry(0, std::string("(")+_("auto-detect language")+")");
47 add_entry(1, "English");
50 std::set<std::string> languages = dictionary_manager.get_languages();
51 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
52 std::string locale_name = *i;
53 TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name);
54 std::string locale_fullname = locale_name;
55 if (std::string(ldef.code) == locale_name) {
56 locale_fullname = ldef.name;
58 add_entry(mnid++, locale_fullname);
65 virtual void menu_action(MenuItem* item) {
68 dictionary_manager.set_language(config->locale);
72 else if (item->id == 1) {
73 config->locale = "en";
74 dictionary_manager.set_language(config->locale);
79 std::set<std::string> languages = dictionary_manager.get_languages();
80 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
81 std::string locale_name = *i;
82 if (item->id == mnid++) {
83 config->locale = locale_name;
84 dictionary_manager.set_language(config->locale);
93 class OptionsMenu : public Menu
97 virtual ~OptionsMenu();
99 virtual void menu_action(MenuItem* item);
102 std::auto_ptr<LanguageMenu> language_menu;
106 OptionsMenu::OptionsMenu()
108 language_menu.reset(new LanguageMenu());
110 add_label(_("Options"));
113 add_submenu(_("Select Language"), language_menu.get())
114 ->set_help(_("Switch to another language"));
116 add_submenu(_("Select Profile"), get_profile_menu())
117 ->set_help(_("Switch between different savegames"));
119 add_toggle(MNID_SOUND, _("Profile on Startup"), config->sound_enabled)
120 ->set_help(_("Display the profile menu when the game is newly started"));
122 // FIXME: Implement me: if (get_parent() == main_menu)
123 add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen)
124 ->set_help(_("Let the game cover the whole screen"));
126 MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ration"));
127 aspect->set_help(_("Adjust the aspect ratio"));
128 aspect->list.push_back("16:9");
129 aspect->list.push_back("16:10");
130 aspect->list.push_back("4:3");
131 aspect->list.push_back("5:4");
133 if (sound_manager->is_audio_enabled()) {
134 add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled)
135 ->set_help(_("Disable all sound effects in the game"));
136 add_toggle(MNID_MUSIC, _("Music"), config->music_enabled)
137 ->set_help(_("Disable all music in the game"));
139 add_deactive(MNID_SOUND, _("Sound (disabled)"));
140 add_deactive(MNID_SOUND, _("Music (disabled)"));
143 add_submenu(_("Setup Keyboard"), main_controller->get_key_options_menu())
144 ->set_help(_("Configure how your keyboard maps to the game"));
146 add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu())
147 ->set_help(_("Configure how your joystick maps to the game"));
152 OptionsMenu::~OptionsMenu()
157 OptionsMenu::menu_action(MenuItem* item)
160 case MNID_ASPECTRATIO:
161 { // FIXME: Really crude and ugly here, move to video or so
165 if(sscanf(item->list[item->selected].c_str(), "%d:%d", &aspect_width, &aspect_height) == 2)
167 config->aspect_ratio = static_cast<double>(aspect_width) /
168 static_cast<double>(aspect_height);
170 if (config->aspect_ratio > 1) {
171 SCREEN_WIDTH = static_cast<int> (600 * config->aspect_ratio + 0.5);
175 SCREEN_HEIGHT = static_cast<int> (600 * 1/config->aspect_ratio + 0.5);
178 glMatrixMode(GL_PROJECTION);
180 glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0);
181 std::cout << __FILE__ << ":" << __LINE__ << ": change aspect ratio to " << item->list[item->selected] << std::endl;
186 case MNID_FULLSCREEN:
187 if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
188 config->use_fullscreen = !config->use_fullscreen;
194 if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
195 config->sound_enabled = !config->sound_enabled;
196 sound_manager->enable_sound(config->sound_enabled);
201 if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
202 config->music_enabled = !config->music_enabled;
203 sound_manager->enable_music(config->music_enabled);
212 Menu* get_options_menu()
214 //static OptionsMenu menu;
215 options_menu = new OptionsMenu();
219 void free_options_menu()