X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Foptions_menu.cpp;h=ccadc447e28f8f158e0cf2415d51747d5aed359e;hb=c13404a6b6a97ad0d5e1c9f905d7a7e37b797c13;hp=778f77cd45b4cc48ae05f0bc223d4c36a25a0e6b;hpb=403276e51afda11d0738be756025411d9103a6ed;p=supertux.git diff --git a/src/options_menu.cpp b/src/options_menu.cpp index 778f77cd4..ccadc447e 100644 --- a/src/options_menu.cpp +++ b/src/options_menu.cpp @@ -26,6 +26,7 @@ #include "control/joystickkeyboardcontroller.hpp" #include "main.hpp" #include "gettext.hpp" +#include "video/renderer.hpp" #include "gameconfig.hpp" Menu* options_menu = 0; @@ -33,8 +34,9 @@ Menu* options_menu = 0; enum OptionsMenuIDs { MNID_FULLSCREEN, MNID_FULLSCREEN_RESOLUTION, - MNID_PROJECTION_AREA, + MNID_MAGNIFICATION, MNID_ASPECTRATIO, + MNID_PROFILES, MNID_SOUND, MNID_MUSIC }; @@ -45,7 +47,7 @@ public: LanguageMenu() { add_label(_("Language")); add_hl(); - add_entry(0, std::string("(")+_("auto-detect language")+")"); + add_entry(0, std::string("<")+_("auto-detect")+">"); add_entry(1, "English"); int mnid = 10; @@ -69,13 +71,13 @@ public: config->locale = ""; dictionary_manager.set_language(config->locale); config->save(); - Menu::set_current(0); + Menu::pop_current(); } else if (item->id == 1) { config->locale = "en"; dictionary_manager.set_language(config->locale); config->save(); - Menu::set_current(0); + Menu::pop_current(); } int mnid = 10; std::set languages = dictionary_manager.get_languages(); @@ -85,7 +87,7 @@ public: config->locale = locale_name; dictionary_manager.set_language(config->locale); config->save(); - Menu::set_current(0); + Menu::pop_current(); } } } @@ -112,91 +114,115 @@ OptionsMenu::OptionsMenu() add_label(_("Options")); add_hl(); + // Language change should only be possible in the main menu, since elsewhere it might not always work fully + // FIXME: Implement me: if (get_parent() == main_menu) add_submenu(_("Select Language"), language_menu.get()) - ->set_help(_("Switch to another language")); + ->set_help(_("Select a different language to display text in")); add_submenu(_("Select Profile"), get_profile_menu()) - ->set_help(_("Switch between different savegames")); + ->set_help(_("Select a profile to play with")); - add_toggle(MNID_SOUND, _("Profile on Startup"), config->sound_enabled) - ->set_help(_("Display the profile menu when the game is newly started")); + add_toggle(MNID_PROFILES, _("Profile on Startup"), config->sound_enabled) + ->set_help(_("Select your profile immediately after start-up")); - // FIXME: Implement me: if (get_parent() == main_menu) add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen) - ->set_help(_("Let the game cover the whole screen")); - - MenuItem* projection = add_string_select(MNID_PROJECTION_AREA, _("Projection Area")); - projection->set_help(_("Change the visible area")); - - projection->list.push_back("640x480"); - projection->list.push_back("800x600"); - projection->list.push_back("1024x768"); - projection->list.push_back("1152x864"); - projection->list.push_back("1280x960"); - projection->list.push_back("1280x1024"); - projection->list.push_back("1440x900"); - projection->list.push_back("1680x1050"); - projection->list.push_back("1600x1200"); - projection->list.push_back("1920x1080"); - projection->list.push_back("1920x1200"); - - MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Fullscreen Resolution")); - fullscreen_res->set_help(_("Change the Fullscreen Resolution")); - - // FIXME: Hardcoded values are evil, these should be queried from the Xorg server - fullscreen_res->list.push_back("640x480"); - fullscreen_res->list.push_back("800x600"); - fullscreen_res->list.push_back("1024x768"); - fullscreen_res->list.push_back("1152x864"); - fullscreen_res->list.push_back("1280x960"); - fullscreen_res->list.push_back("1280x1024"); - fullscreen_res->list.push_back("1440x900"); - fullscreen_res->list.push_back("1680x1050"); - fullscreen_res->list.push_back("1600x1200"); - fullscreen_res->list.push_back("1920x1080"); - fullscreen_res->list.push_back("1920x1200"); + ->set_help(_("Fill the entire screen")); + + MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Resolution")); + fullscreen_res->set_help(_("Determine the resolution used in fullscreen mode (you must toggle fullscreen to complete the change)")); + + MenuItem* magnification = add_string_select(MNID_MAGNIFICATION, _("Magnification")); + magnification->set_help(_("Change the magnification of the game area")); + + // These values go from screen:640/projection:1600 to + // screen:1600/projection:640 (i.e. 640, 800, 1024, 1280, 1600) + magnification->list.push_back("auto"); + magnification->list.push_back("40%"); + magnification->list.push_back("50%"); + magnification->list.push_back("62.5%"); + magnification->list.push_back("80%"); + magnification->list.push_back("100%"); + magnification->list.push_back("125%"); + magnification->list.push_back("160%"); + magnification->list.push_back("200%"); + magnification->list.push_back("250%"); + + SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL); + + if (modes == (SDL_Rect **)0) + { // No resolutions at all available, bad + + } + else if(modes == (SDL_Rect **)-1) + { // All resolutions should work, so we fall back to hardcoded defaults + fullscreen_res->list.push_back("640x480"); + fullscreen_res->list.push_back("800x600"); + fullscreen_res->list.push_back("1024x768"); + fullscreen_res->list.push_back("1152x864"); + fullscreen_res->list.push_back("1280x960"); + fullscreen_res->list.push_back("1280x1024"); + fullscreen_res->list.push_back("1440x900"); + fullscreen_res->list.push_back("1680x1050"); + fullscreen_res->list.push_back("1600x1200"); + fullscreen_res->list.push_back("1920x1080"); + fullscreen_res->list.push_back("1920x1200"); + } + else + { + for(int i = 0; modes[i]; ++i) + { + std::ostringstream out; + out << modes[i]->w << "x" << modes[i]->h; + fullscreen_res->list.push_back(out.str()); + } + } MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio")); aspect->set_help(_("Adjust the aspect ratio")); - aspect->list.push_back("16:9"); - aspect->list.push_back("16:10"); - aspect->list.push_back("4:3"); + aspect->list.push_back("auto"); aspect->list.push_back("5:4"); + aspect->list.push_back("4:3"); + aspect->list.push_back("16:10"); + aspect->list.push_back("16:9"); + aspect->list.push_back("1368:768"); - std::ostringstream out; - out << config->aspect_width << ":" << config->aspect_height; - std::string aspect_ratio = out.str(); - for(std::vector::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i) + if (config->aspect_width != 0 && config->aspect_height != 0) { - if(*i == aspect_ratio) + std::ostringstream out; + out << config->aspect_width << ":" << config->aspect_height; + std::string aspect_ratio = out.str(); + for(std::vector::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i) { - aspect_ratio.clear(); - break; + if(*i == aspect_ratio) + { + aspect_ratio.clear(); + break; + } } - } - if (!aspect_ratio.empty()) - { - aspect->selected = aspect->list.size(); - aspect->list.push_back(aspect_ratio); + if (!aspect_ratio.empty()) + { + aspect->selected = aspect->list.size(); + aspect->list.push_back(aspect_ratio); + } } if (sound_manager->is_audio_enabled()) { add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled) - ->set_help(_("Disable all sound effects in the game")); + ->set_help(_("Disable all sound effects")); add_toggle(MNID_MUSIC, _("Music"), config->music_enabled) - ->set_help(_("Disable all music in the game")); + ->set_help(_("Disable all music")); } else { - add_deactive(MNID_SOUND, _("Sound (disabled)")); - add_deactive(MNID_SOUND, _("Music (disabled)")); + add_inactive(MNID_SOUND, _("Sound (disabled)")); + add_inactive(MNID_MUSIC, _("Music (disabled)")); } add_submenu(_("Setup Keyboard"), main_controller->get_key_options_menu()) - ->set_help(_("Configure how your keyboard maps to the game")); + ->set_help(_("Configure key-action mappings")); add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu()) - ->set_help(_("Configure how your joystick maps to the game")); + ->set_help(_("Configure joystick control-action mappings")); add_hl(); add_back(_("Back")); } @@ -210,38 +236,55 @@ OptionsMenu::menu_action(MenuItem* item) { switch (item->id) { case MNID_ASPECTRATIO: - { // FIXME: Really crude and ugly here, move to video or so - if(sscanf(item->list[item->selected].c_str(), "%d:%d", &config->aspect_width, &config->aspect_height) == 2) + { + if (item->list[item->selected] == "auto") { - float aspect_ratio = static_cast(config->aspect_width) / - static_cast(config->aspect_height); - - if (aspect_ratio > 1) { - SCREEN_WIDTH = static_cast (600 * aspect_ratio + 0.5); - SCREEN_HEIGHT = 600; - } else { - SCREEN_WIDTH = 600; - SCREEN_HEIGHT = static_cast (600 * 1/aspect_ratio + 0.5); - } - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0); - std::cout << __FILE__ << ":" << __LINE__ << ": change aspect ratio to " << item->list[item->selected] << std::endl; - - // Reposition the menu to be in the center of the screen again - set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); + config->aspect_width = 0; // Magic values + config->aspect_height = 0; + Renderer::instance()->apply_config(); + Menu::recalc_pos(); + } + else if(sscanf(item->list[item->selected].c_str(), "%d:%d", &config->aspect_width, &config->aspect_height) == 2) + { + Renderer::instance()->apply_config(); + Menu::recalc_pos(); + } + else + { + assert(!"This must not be reached"); } } break; + case MNID_MAGNIFICATION: + if (item->list[item->selected] == "auto") + { + config->magnification = 0.0f; // Magic value + } + else if(sscanf(item->list[item->selected].c_str(), "%f", &config->magnification) == 1) + { + config->magnification /= 100.0f; + } + Renderer::instance()->apply_config(); + Menu::recalc_pos(); + break; + + case MNID_FULLSCREEN_RESOLUTION: + if(sscanf(item->list[item->selected].c_str(), "%dx%d", &config->fullscreen_width, &config->fullscreen_height) == 2) + { + // do nothing, changes are only applied when toggling fullscreen mode + } + break; + case MNID_FULLSCREEN: if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) { config->use_fullscreen = !config->use_fullscreen; - init_video(); + init_video(); // FIXME: Should call apply_config instead + Menu::recalc_pos(); config->save(); } break; + case MNID_SOUND: if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) { config->sound_enabled = !config->sound_enabled; @@ -249,6 +292,7 @@ OptionsMenu::menu_action(MenuItem* item) config->save(); } break; + case MNID_MUSIC: if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) { config->music_enabled = !config->music_enabled; @@ -256,6 +300,7 @@ OptionsMenu::menu_action(MenuItem* item) config->save(); } break; + default: break; }