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,
39 MNID_STRETCH_TO_WINDOW,
45 class LanguageMenu : public Menu
49 add_label(_("Language"));
51 add_entry(0, std::string("<")+_("auto-detect")+">");
52 add_entry(1, "English");
55 std::set<std::string> languages = dictionary_manager.get_languages();
56 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
57 std::string locale_name = *i;
58 TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name);
59 std::string locale_fullname = locale_name;
60 if (std::string(ldef.code) == locale_name) {
61 locale_fullname = ldef.name;
63 add_entry(mnid++, locale_fullname);
70 virtual void menu_action(MenuItem* item) {
73 dictionary_manager.set_language(config->locale);
77 else if (item->id == 1) {
78 config->locale = "en";
79 dictionary_manager.set_language(config->locale);
84 std::set<std::string> languages = dictionary_manager.get_languages();
85 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
86 std::string locale_name = *i;
87 if (item->id == mnid++) {
88 config->locale = locale_name;
89 dictionary_manager.set_language(config->locale);
98 class OptionsMenu : public Menu
102 virtual ~OptionsMenu();
104 virtual void menu_action(MenuItem* item);
107 std::auto_ptr<LanguageMenu> language_menu;
111 OptionsMenu::OptionsMenu()
113 language_menu.reset(new LanguageMenu());
115 add_label(_("Options"));
118 // Language change should only be possible in the main menu, since elsewhere it might not always work fully
119 // FIXME: Implement me: if (get_parent() == main_menu)
120 add_submenu(_("Select Language"), language_menu.get())
121 ->set_help(_("Select a different language to display text in"));
123 add_submenu(_("Select Profile"), get_profile_menu())
124 ->set_help(_("Select a profile to play with"));
126 add_toggle(MNID_PROFILES, _("Profile on Startup"), config->sound_enabled)
127 ->set_help(_("Select your profile immediately after start-up"));
129 add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen)
130 ->set_help(_("Fill the entire screen"));
132 MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Resolution"));
133 fullscreen_res->set_help(_("Determine the resolution used in fullscreen mode (you must toggle fullscreen to complete the change)"));
135 MenuItem* magnification = add_string_select(MNID_MAGNIFICATION, _("Magnification"));
136 magnification->set_help(_("Change the magnification of the game area"));
138 // These values go from screen:640/projection:1600 to
139 // screen:1600/projection:640 (i.e. 640, 800, 1024, 1280, 1600)
140 magnification->list.push_back("auto");
141 magnification->list.push_back("40%");
142 magnification->list.push_back("50%");
143 magnification->list.push_back("62.5%");
144 magnification->list.push_back("80%");
145 magnification->list.push_back("100%");
146 magnification->list.push_back("125%");
147 magnification->list.push_back("160%");
148 magnification->list.push_back("200%");
149 magnification->list.push_back("250%");
151 add_toggle(MNID_STRETCH_TO_WINDOW, _("Stretch to Window"), config->stretch_to_window)
152 ->set_help(_("Use the fullscreen resolution and stretch SuperTux to fill the given window"));
154 SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
156 if (modes == (SDL_Rect **)0)
157 { // No resolutions at all available, bad
160 else if(modes == (SDL_Rect **)-1)
161 { // All resolutions should work, so we fall back to hardcoded defaults
162 fullscreen_res->list.push_back("640x480");
163 fullscreen_res->list.push_back("800x600");
164 fullscreen_res->list.push_back("1024x768");
165 fullscreen_res->list.push_back("1152x864");
166 fullscreen_res->list.push_back("1280x960");
167 fullscreen_res->list.push_back("1280x1024");
168 fullscreen_res->list.push_back("1440x900");
169 fullscreen_res->list.push_back("1680x1050");
170 fullscreen_res->list.push_back("1600x1200");
171 fullscreen_res->list.push_back("1920x1080");
172 fullscreen_res->list.push_back("1920x1200");
176 for(int i = 0; modes[i]; ++i)
178 std::ostringstream out;
179 out << modes[i]->w << "x" << modes[i]->h;
180 fullscreen_res->list.push_back(out.str());
184 MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
185 aspect->set_help(_("Adjust the aspect ratio"));
187 aspect->list.push_back("auto");
188 aspect->list.push_back("5:4");
189 aspect->list.push_back("4:3");
190 aspect->list.push_back("16:10");
191 aspect->list.push_back("16:9");
192 aspect->list.push_back("1368:768");
194 std::ostringstream out;
195 out << config->aspect_width << ":" << config->aspect_height;
196 std::string aspect_ratio = out.str();
197 for(std::vector<std::string>::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i)
199 if(*i == aspect_ratio)
201 aspect_ratio.clear();
206 if (!aspect_ratio.empty())
208 aspect->selected = aspect->list.size();
209 aspect->list.push_back(aspect_ratio);
212 if (sound_manager->is_audio_enabled()) {
213 add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled)
214 ->set_help(_("Disable all sound effects"));
215 add_toggle(MNID_MUSIC, _("Music"), config->music_enabled)
216 ->set_help(_("Disable all music"));
218 add_deactive(MNID_SOUND, _("Sound (disabled)"));
219 add_deactive(MNID_MUSIC, _("Music (disabled)"));
222 add_submenu(_("Setup Keyboard"), main_controller->get_key_options_menu())
223 ->set_help(_("Configure key-action mappings"));
225 add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu())
226 ->set_help(_("Configure joystick control-action mappings"));
231 OptionsMenu::~OptionsMenu()
236 OptionsMenu::menu_action(MenuItem* item)
239 case MNID_ASPECTRATIO:
241 if (item->list[item->selected] == "auto")
243 config->aspect_width = 0; // Magic values
244 config->aspect_height = 0;
245 Renderer::instance()->apply_config();
248 else if(sscanf(item->list[item->selected].c_str(), "%d:%d", &config->aspect_width, &config->aspect_height) == 2)
250 Renderer::instance()->apply_config();
255 assert(!"This must not be reached");
260 case MNID_MAGNIFICATION:
261 if (item->list[item->selected] == "auto")
263 config->magnification = 0.0f; // Magic value
265 else if(sscanf(item->list[item->selected].c_str(), "%f", &config->magnification) == 1)
267 config->magnification /= 100.0f;
269 Renderer::instance()->apply_config();
273 case MNID_FULLSCREEN_RESOLUTION:
274 if(sscanf(item->list[item->selected].c_str(), "%dx%d", &config->fullscreen_width, &config->fullscreen_height) == 2)
276 // do nothing, changes are only applied when toggling fullscreen mode
280 case MNID_FULLSCREEN:
281 if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
282 config->use_fullscreen = !config->use_fullscreen;
289 if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
290 config->sound_enabled = !config->sound_enabled;
291 sound_manager->enable_sound(config->sound_enabled);
297 if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
298 config->music_enabled = !config->music_enabled;
299 sound_manager->enable_music(config->music_enabled);
309 Menu* get_options_menu()
311 //static OptionsMenu menu;
312 options_menu = new OptionsMenu();
316 void free_options_menu()