2 // Copyright (C) 2004 Tobas Glaesser <tobi.web@gmx.de>
3 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "supertux/menu/options_menu.hpp"
20 #include "audio/sound_manager.hpp"
21 #include "gui/menu_manager.hpp"
22 #include "supertux/gameconfig.hpp"
23 #include "supertux/menu/joystick_menu.hpp"
24 #include "supertux/menu/keyboard_menu.hpp"
25 #include "supertux/menu/language_menu.hpp"
26 #include "supertux/menu/menu_storage.hpp"
27 #include "supertux/menu/profile_menu.hpp"
28 #include "video/renderer.hpp"
32 MNID_FULLSCREEN_RESOLUTION,
40 OptionsMenu::OptionsMenu() :
43 language_menu.reset(new LanguageMenu());
45 add_label(_("Options"));
48 // Language change should only be possible in the main menu, since elsewhere it might not always work fully
49 // FIXME: Implement me: if (get_parent() == main_menu)
50 add_submenu(_("Select Language"), language_menu.get())
51 ->set_help(_("Select a different language to display text in"));
53 add_submenu(_("Select Profile"), MenuStorage::get_profile_menu())
54 ->set_help(_("Select a profile to play with"));
56 add_toggle(MNID_PROFILES, _("Profile on Startup"), g_config->sound_enabled)
57 ->set_help(_("Select your profile immediately after start-up"));
59 add_toggle(MNID_FULLSCREEN,_("Fullscreen"), g_config->use_fullscreen)
60 ->set_help(_("Fill the entire screen"));
62 MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Resolution"));
63 fullscreen_res->set_help(_("Determine the resolution used in fullscreen mode (you must toggle fullscreen to complete the change)"));
65 MenuItem* magnification = add_string_select(MNID_MAGNIFICATION, _("Magnification"));
66 magnification->set_help(_("Change the magnification of the game area"));
68 // These values go from screen:640/projection:1600 to
69 // screen:1600/projection:640 (i.e. 640, 800, 1024, 1280, 1600)
70 magnification->list.push_back("auto");
71 magnification->list.push_back("40%");
72 magnification->list.push_back("50%");
73 magnification->list.push_back("62.5%");
74 magnification->list.push_back("80%");
75 magnification->list.push_back("100%");
76 magnification->list.push_back("125%");
77 magnification->list.push_back("160%");
78 magnification->list.push_back("200%");
79 magnification->list.push_back("250%");
81 SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
83 if (modes == (SDL_Rect **)0)
84 { // No resolutions at all available, bad
87 else if(modes == (SDL_Rect **)-1)
88 { // All resolutions should work, so we fall back to hardcoded defaults
89 fullscreen_res->list.push_back("640x480");
90 fullscreen_res->list.push_back("800x600");
91 fullscreen_res->list.push_back("1024x768");
92 fullscreen_res->list.push_back("1152x864");
93 fullscreen_res->list.push_back("1280x960");
94 fullscreen_res->list.push_back("1280x1024");
95 fullscreen_res->list.push_back("1440x900");
96 fullscreen_res->list.push_back("1680x1050");
97 fullscreen_res->list.push_back("1600x1200");
98 fullscreen_res->list.push_back("1920x1080");
99 fullscreen_res->list.push_back("1920x1200");
103 for(int i = 0; modes[i]; ++i)
105 std::ostringstream out;
106 out << modes[i]->w << "x" << modes[i]->h;
107 fullscreen_res->list.push_back(out.str());
111 MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
112 aspect->set_help(_("Adjust the aspect ratio"));
114 aspect->list.push_back("auto");
115 aspect->list.push_back("5:4");
116 aspect->list.push_back("4:3");
117 aspect->list.push_back("16:10");
118 aspect->list.push_back("16:9");
119 aspect->list.push_back("1368:768");
121 if (g_config->aspect_size != Size(0, 0))
123 std::ostringstream out;
124 out << g_config->aspect_size.width << ":" << g_config->aspect_size.height;
125 std::string aspect_ratio = out.str();
126 for(std::vector<std::string>::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i)
128 if(*i == aspect_ratio)
130 aspect_ratio.clear();
135 if (!aspect_ratio.empty())
137 aspect->selected = aspect->list.size();
138 aspect->list.push_back(aspect_ratio);
142 if (sound_manager->is_audio_enabled()) {
143 add_toggle(MNID_SOUND, _("Sound"), g_config->sound_enabled)
144 ->set_help(_("Disable all sound effects"));
145 add_toggle(MNID_MUSIC, _("Music"), g_config->music_enabled)
146 ->set_help(_("Disable all music"));
148 add_inactive(MNID_SOUND, _("Sound (disabled)"));
149 add_inactive(MNID_MUSIC, _("Music (disabled)"));
152 add_submenu(_("Setup Keyboard"), MenuStorage::get_key_options_menu())
153 ->set_help(_("Configure key-action mappings"));
155 add_submenu(_("Setup Joystick"), MenuStorage::get_joystick_options_menu())
156 ->set_help(_("Configure joystick control-action mappings"));
161 OptionsMenu::~OptionsMenu()
166 OptionsMenu::menu_action(MenuItem* item)
169 case MNID_ASPECTRATIO:
171 if (item->list[item->selected] == "auto")
173 g_config->aspect_size = Size(0, 0); // Magic values
174 Renderer::instance()->apply_config();
175 MenuManager::recalc_pos();
177 else if (sscanf(item->list[item->selected].c_str(), "%d:%d",
178 &g_config->aspect_size.width, &g_config->aspect_size.height) == 2)
180 Renderer::instance()->apply_config();
181 MenuManager::recalc_pos();
185 assert(!"This must not be reached");
190 case MNID_MAGNIFICATION:
191 if (item->list[item->selected] == "auto")
193 g_config->magnification = 0.0f; // Magic value
195 else if(sscanf(item->list[item->selected].c_str(), "%f", &g_config->magnification) == 1)
197 g_config->magnification /= 100.0f;
199 Renderer::instance()->apply_config();
200 MenuManager::recalc_pos();
203 case MNID_FULLSCREEN_RESOLUTION:
204 if(sscanf(item->list[item->selected].c_str(), "%dx%d",
205 &g_config->fullscreen_size.width, &g_config->fullscreen_size.height) == 2)
207 // do nothing, changes are only applied when toggling fullscreen mode
211 case MNID_FULLSCREEN:
212 if(g_config->use_fullscreen != is_toggled(MNID_FULLSCREEN)) {
213 g_config->use_fullscreen = !g_config->use_fullscreen;
214 Renderer::instance()->apply_config();
215 MenuManager::recalc_pos();
221 if(g_config->sound_enabled != is_toggled(MNID_SOUND)) {
222 g_config->sound_enabled = !g_config->sound_enabled;
223 sound_manager->enable_sound(g_config->sound_enabled);
229 if(g_config->music_enabled != is_toggled(MNID_MUSIC)) {
230 g_config->music_enabled = !g_config->music_enabled;
231 sound_manager->enable_music(g_config->music_enabled);
242 OptionsMenu::check_menu()