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 "video/renderer.hpp"
30 #include "gameconfig.hpp"
32 Menu* options_menu = 0;
36 MNID_FULLSCREEN_RESOLUTION,
43 class LanguageMenu : public Menu
47 add_label(_("Language"));
49 add_entry(0, std::string("(")+_("auto-detect language")+")");
50 add_entry(1, "English");
53 std::set<std::string> languages = dictionary_manager.get_languages();
54 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
55 std::string locale_name = *i;
56 TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name);
57 std::string locale_fullname = locale_name;
58 if (std::string(ldef.code) == locale_name) {
59 locale_fullname = ldef.name;
61 add_entry(mnid++, locale_fullname);
68 virtual void menu_action(MenuItem* item) {
71 dictionary_manager.set_language(config->locale);
75 else if (item->id == 1) {
76 config->locale = "en";
77 dictionary_manager.set_language(config->locale);
82 std::set<std::string> languages = dictionary_manager.get_languages();
83 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
84 std::string locale_name = *i;
85 if (item->id == mnid++) {
86 config->locale = locale_name;
87 dictionary_manager.set_language(config->locale);
96 class OptionsMenu : public Menu
100 virtual ~OptionsMenu();
102 virtual void menu_action(MenuItem* item);
105 std::auto_ptr<LanguageMenu> language_menu;
109 OptionsMenu::OptionsMenu()
111 language_menu.reset(new LanguageMenu());
113 add_label(_("Options"));
116 add_submenu(_("Select Language"), language_menu.get())
117 ->set_help(_("Switch to another language"));
119 add_submenu(_("Select Profile"), get_profile_menu())
120 ->set_help(_("Switch between different savegames"));
122 add_toggle(MNID_SOUND, _("Profile on Startup"), config->sound_enabled)
123 ->set_help(_("Display the profile menu when the game is newly started"));
125 add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen)
126 ->set_help(_("Let the game cover the whole screen"));
128 MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Resolution"));
129 fullscreen_res->set_help(_("Change the Resolution to be used in Fullscreen Mode, you have to toggle fullscreen mode to let this change take effect"));
131 MenuItem* maginfication = add_string_select(MNID_MAGINFICATION, _("Maginfication"));
132 maginfication->set_help(_("Change the magnification, to small values will result in a black border around the screen"));
134 maginfication->list.push_back("0.5");
135 maginfication->list.push_back("0.625");
136 maginfication->list.push_back("0.8");
137 maginfication->list.push_back("1.0");
138 maginfication->list.push_back("1.25");
139 maginfication->list.push_back("1.6");
140 maginfication->list.push_back("2.0");
142 SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
144 if (modes == (SDL_Rect **)0)
145 { // No resolutions at all available, bad
148 else if(modes == (SDL_Rect **)-1)
149 { // All resolutions sould work, so we fall back to hardcoded defaults
150 fullscreen_res->list.push_back("640x480");
151 fullscreen_res->list.push_back("800x600");
152 fullscreen_res->list.push_back("1024x768");
153 fullscreen_res->list.push_back("1152x864");
154 fullscreen_res->list.push_back("1280x960");
155 fullscreen_res->list.push_back("1280x1024");
156 fullscreen_res->list.push_back("1440x900");
157 fullscreen_res->list.push_back("1680x1050");
158 fullscreen_res->list.push_back("1600x1200");
159 fullscreen_res->list.push_back("1920x1080");
160 fullscreen_res->list.push_back("1920x1200");
164 for(int i = 0; modes[i]; ++i)
166 std::ostringstream out;
167 out << modes[i]->w << "x" << modes[i]->h;
168 fullscreen_res->list.push_back(out.str());
172 MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
173 aspect->set_help(_("Adjust the aspect ratio"));
175 aspect->list.push_back("4:3");
176 aspect->list.push_back("5:4");
177 aspect->list.push_back("16:10");
178 aspect->list.push_back("16:9");
180 std::ostringstream out;
181 out << config->aspect_width << ":" << config->aspect_height;
182 std::string aspect_ratio = out.str();
183 for(std::vector<std::string>::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i)
185 if(*i == aspect_ratio)
187 aspect_ratio.clear();
192 if (!aspect_ratio.empty())
194 aspect->selected = aspect->list.size();
195 aspect->list.push_back(aspect_ratio);
198 if (sound_manager->is_audio_enabled()) {
199 add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled)
200 ->set_help(_("Disable all sound effects in the game"));
201 add_toggle(MNID_MUSIC, _("Music"), config->music_enabled)
202 ->set_help(_("Disable all music in the game"));
204 add_deactive(MNID_SOUND, _("Sound (disabled)"));
205 add_deactive(MNID_SOUND, _("Music (disabled)"));
208 add_submenu(_("Setup Keyboard"), main_controller->get_key_options_menu())
209 ->set_help(_("Configure how your keyboard maps to the game"));
211 add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu())
212 ->set_help(_("Configure how your joystick maps to the game"));
217 OptionsMenu::~OptionsMenu()
222 OptionsMenu::menu_action(MenuItem* item)
225 case MNID_ASPECTRATIO:
227 if(sscanf(item->list[item->selected].c_str(), "%d:%d", &config->aspect_width, &config->aspect_height) == 2)
229 Renderer::instance()->apply_config();
235 case MNID_MAGINFICATION:
236 if(sscanf(item->list[item->selected].c_str(), "%f", &config->magnification) == 1)
238 Renderer::instance()->apply_config();
243 case MNID_FULLSCREEN_RESOLUTION:
244 if(sscanf(item->list[item->selected].c_str(), "%dx%d", &config->fullscreen_width, &config->fullscreen_height) == 2)
246 Renderer::instance()->apply_config();
251 case MNID_FULLSCREEN:
252 if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
253 config->use_fullscreen = !config->use_fullscreen;
259 if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
260 config->sound_enabled = !config->sound_enabled;
261 sound_manager->enable_sound(config->sound_enabled);
266 if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
267 config->music_enabled = !config->music_enabled;
268 sound_manager->enable_music(config->music_enabled);
277 Menu* get_options_menu()
279 //static OptionsMenu menu;
280 options_menu = new OptionsMenu();
284 void free_options_menu()