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 "audio/sound_manager.hpp"
19 #include "control/joystickkeyboardcontroller.hpp"
20 #include "gui/menu.hpp"
21 #include "supertux/gameconfig.hpp"
22 #include "supertux/main.hpp"
23 #include "supertux/profile_menu.hpp"
24 #include "util/gettext.hpp"
25 #include "video/renderer.hpp"
27 Menu* options_menu = 0;
31 MNID_FULLSCREEN_RESOLUTION,
39 class LanguageMenu : public Menu
43 add_label(_("Language"));
45 add_entry(0, std::string("<")+_("auto-detect")+">");
46 add_entry(1, "English");
49 std::set<std::string> languages = dictionary_manager.get_languages();
50 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
51 std::string locale_name = *i;
52 TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name);
53 std::string locale_fullname = locale_name;
54 if (std::string(ldef.code) == locale_name) {
55 locale_fullname = ldef.name;
57 add_entry(mnid++, locale_fullname);
64 virtual void menu_action(MenuItem* item) {
66 g_config->locale = "";
67 dictionary_manager.set_language(g_config->locale);
71 else if (item->id == 1) {
72 g_config->locale = "en";
73 dictionary_manager.set_language(g_config->locale);
78 std::set<std::string> languages = dictionary_manager.get_languages();
79 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
80 std::string locale_name = *i;
81 if (item->id == mnid++) {
82 g_config->locale = locale_name;
83 dictionary_manager.set_language(g_config->locale);
91 class OptionsMenu : public Menu
95 virtual ~OptionsMenu();
97 virtual void menu_action(MenuItem* item);
100 std::auto_ptr<LanguageMenu> language_menu;
104 OptionsMenu::OptionsMenu() :
107 language_menu.reset(new LanguageMenu());
109 add_label(_("Options"));
112 // Language change should only be possible in the main menu, since elsewhere it might not always work fully
113 // FIXME: Implement me: if (get_parent() == main_menu)
114 add_submenu(_("Select Language"), language_menu.get())
115 ->set_help(_("Select a different language to display text in"));
117 add_submenu(_("Select Profile"), get_profile_menu())
118 ->set_help(_("Select a profile to play with"));
120 add_toggle(MNID_PROFILES, _("Profile on Startup"), g_config->sound_enabled)
121 ->set_help(_("Select your profile immediately after start-up"));
123 add_toggle(MNID_FULLSCREEN,_("Fullscreen"), g_config->use_fullscreen)
124 ->set_help(_("Fill the entire screen"));
126 MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Resolution"));
127 fullscreen_res->set_help(_("Determine the resolution used in fullscreen mode (you must toggle fullscreen to complete the change)"));
129 MenuItem* magnification = add_string_select(MNID_MAGNIFICATION, _("Magnification"));
130 magnification->set_help(_("Change the magnification of the game area"));
132 // These values go from screen:640/projection:1600 to
133 // screen:1600/projection:640 (i.e. 640, 800, 1024, 1280, 1600)
134 magnification->list.push_back("auto");
135 magnification->list.push_back("40%");
136 magnification->list.push_back("50%");
137 magnification->list.push_back("62.5%");
138 magnification->list.push_back("80%");
139 magnification->list.push_back("100%");
140 magnification->list.push_back("125%");
141 magnification->list.push_back("160%");
142 magnification->list.push_back("200%");
143 magnification->list.push_back("250%");
145 SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
147 if (modes == (SDL_Rect **)0)
148 { // No resolutions at all available, bad
151 else if(modes == (SDL_Rect **)-1)
152 { // All resolutions should work, so we fall back to hardcoded defaults
153 fullscreen_res->list.push_back("640x480");
154 fullscreen_res->list.push_back("800x600");
155 fullscreen_res->list.push_back("1024x768");
156 fullscreen_res->list.push_back("1152x864");
157 fullscreen_res->list.push_back("1280x960");
158 fullscreen_res->list.push_back("1280x1024");
159 fullscreen_res->list.push_back("1440x900");
160 fullscreen_res->list.push_back("1680x1050");
161 fullscreen_res->list.push_back("1600x1200");
162 fullscreen_res->list.push_back("1920x1080");
163 fullscreen_res->list.push_back("1920x1200");
167 for(int i = 0; modes[i]; ++i)
169 std::ostringstream out;
170 out << modes[i]->w << "x" << modes[i]->h;
171 fullscreen_res->list.push_back(out.str());
175 MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
176 aspect->set_help(_("Adjust the aspect ratio"));
178 aspect->list.push_back("auto");
179 aspect->list.push_back("5:4");
180 aspect->list.push_back("4:3");
181 aspect->list.push_back("16:10");
182 aspect->list.push_back("16:9");
183 aspect->list.push_back("1368:768");
185 if (g_config->aspect_width != 0 && g_config->aspect_height != 0)
187 std::ostringstream out;
188 out << g_config->aspect_width << ":" << g_config->aspect_height;
189 std::string aspect_ratio = out.str();
190 for(std::vector<std::string>::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i)
192 if(*i == aspect_ratio)
194 aspect_ratio.clear();
199 if (!aspect_ratio.empty())
201 aspect->selected = aspect->list.size();
202 aspect->list.push_back(aspect_ratio);
206 if (sound_manager->is_audio_enabled()) {
207 add_toggle(MNID_SOUND, _("Sound"), g_config->sound_enabled)
208 ->set_help(_("Disable all sound effects"));
209 add_toggle(MNID_MUSIC, _("Music"), g_config->music_enabled)
210 ->set_help(_("Disable all music"));
212 add_inactive(MNID_SOUND, _("Sound (disabled)"));
213 add_inactive(MNID_MUSIC, _("Music (disabled)"));
216 add_submenu(_("Setup Keyboard"), g_main_controller->get_key_options_menu())
217 ->set_help(_("Configure key-action mappings"));
219 add_submenu(_("Setup Joystick") ,g_main_controller->get_joystick_options_menu())
220 ->set_help(_("Configure joystick control-action mappings"));
225 OptionsMenu::~OptionsMenu()
230 OptionsMenu::menu_action(MenuItem* item)
233 case MNID_ASPECTRATIO:
235 if (item->list[item->selected] == "auto")
237 g_config->aspect_width = 0; // Magic values
238 g_config->aspect_height = 0;
239 Renderer::instance()->apply_config();
242 else if(sscanf(item->list[item->selected].c_str(), "%d:%d", &g_config->aspect_width, &g_config->aspect_height) == 2)
244 Renderer::instance()->apply_config();
249 assert(!"This must not be reached");
254 case MNID_MAGNIFICATION:
255 if (item->list[item->selected] == "auto")
257 g_config->magnification = 0.0f; // Magic value
259 else if(sscanf(item->list[item->selected].c_str(), "%f", &g_config->magnification) == 1)
261 g_config->magnification /= 100.0f;
263 Renderer::instance()->apply_config();
267 case MNID_FULLSCREEN_RESOLUTION:
268 if(sscanf(item->list[item->selected].c_str(), "%dx%d", &g_config->fullscreen_width, &g_config->fullscreen_height) == 2)
270 // do nothing, changes are only applied when toggling fullscreen mode
274 case MNID_FULLSCREEN:
275 if(g_config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
276 g_config->use_fullscreen = !g_config->use_fullscreen;
277 init_video(); // FIXME: Should call apply_config instead
284 if(g_config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
285 g_config->sound_enabled = !g_config->sound_enabled;
286 sound_manager->enable_sound(g_config->sound_enabled);
292 if(g_config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
293 g_config->music_enabled = !g_config->music_enabled;
294 sound_manager->enable_music(g_config->music_enabled);
304 Menu* get_options_menu()
306 //static OptionsMenu menu;
307 options_menu = new OptionsMenu();
311 void free_options_menu()