X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Foptions_menu.cpp;h=1bd8e70d030fcbe5f987fd4e16f783854c993106;hb=2c624a0daabc4db00bf0b3ab49ccd3907586b6a3;hp=b67dbc389149cbef3ea5716b5a30e6175aeec47a;hpb=eab4db1114e55ec2da319c33936f4747a099eb49;p=supertux.git diff --git a/src/options_menu.cpp b/src/options_menu.cpp index b67dbc389..1bd8e70d0 100644 --- a/src/options_menu.cpp +++ b/src/options_menu.cpp @@ -19,6 +19,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include +#include "profile_menu.hpp" #include "options_menu.hpp" #include "gui/menu.hpp" #include "audio/sound_manager.hpp" @@ -31,10 +32,64 @@ Menu* options_menu = 0; enum OptionsMenuIDs { MNID_FULLSCREEN, + MNID_ASPECTRATIO, MNID_SOUND, MNID_MUSIC }; +class LanguageMenu : public Menu +{ +public: + LanguageMenu() { + add_label(_("Language")); + add_hl(); + add_entry(0, std::string("(")+_("auto-detect language")+")"); + add_entry(1, "English"); + + int mnid = 10; + std::set languages = dictionary_manager.get_languages(); + for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { + std::string locale_name = *i; + TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name); + std::string locale_fullname = locale_name; + if (std::string(ldef.code) == locale_name) { + locale_fullname = ldef.name; + } + add_entry(mnid++, locale_fullname); + } + + add_hl(); + add_back(_("Back")); + } + + virtual void menu_action(MenuItem* item) { + if (item->id == 0) { + config->locale = ""; + dictionary_manager.set_language(config->locale); + config->save(); + Menu::set_current(0); + } + else if (item->id == 1) { + config->locale = "en"; + dictionary_manager.set_language(config->locale); + config->save(); + Menu::set_current(0); + } + int mnid = 10; + std::set languages = dictionary_manager.get_languages(); + for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { + std::string locale_name = *i; + if (item->id == mnid++) { + config->locale = locale_name; + dictionary_manager.set_language(config->locale); + config->save(); + Menu::set_current(0); + } + } + } +}; + + class OptionsMenu : public Menu { public: @@ -42,24 +97,54 @@ public: virtual ~OptionsMenu(); virtual void menu_action(MenuItem* item); + +protected: + std::auto_ptr language_menu; + }; OptionsMenu::OptionsMenu() { + language_menu.reset(new LanguageMenu()); + add_label(_("Options")); add_hl(); - add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen); + + add_submenu(_("Select Language"), language_menu.get()) + ->set_help(_("Switch to another language")); + + add_submenu(_("Select Profile"), get_profile_menu()) + ->set_help(_("Switch between different savegames")); + + add_toggle(MNID_SOUND, _("Profile on Startup"), config->sound_enabled) + ->set_help(_("Display the profile menu when the game is newly started")); + + // 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* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ration")); + 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("5:4"); + if (sound_manager->is_audio_enabled()) { - add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled); - add_toggle(MNID_MUSIC, _("Music"), config->music_enabled); - } - else - { - add_deactive(MNID_SOUND, _("Sound disabled")); - add_deactive(MNID_SOUND, _("Music disabled")); + add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled) + ->set_help(_("Disable all sound effects in the game")); + add_toggle(MNID_MUSIC, _("Music"), config->music_enabled) + ->set_help(_("Disable all music in the game")); + } else { + add_deactive(MNID_SOUND, _("Sound (disabled)")); + add_deactive(MNID_SOUND, _("Music (disabled)")); } - add_submenu(_("Setup Keys"), main_controller->get_key_options_menu()); - add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu()); + + add_submenu(_("Setup Keyboard"), main_controller->get_key_options_menu()) + ->set_help(_("Configure how your keyboard maps to the game")); + + add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu()) + ->set_help(_("Configure how your joystick maps to the game")); add_hl(); add_back(_("Back")); } @@ -72,6 +157,32 @@ void OptionsMenu::menu_action(MenuItem* item) { switch (item->id) { + case MNID_ASPECTRATIO: + { // FIXME: Really crude and ugly here, move to video or so + int aspect_width; + int aspect_height; + + if(sscanf(item->list[item->selected].c_str(), "%d:%d", &aspect_width, &aspect_height) == 2) + { + config->aspect_ratio = static_cast(aspect_width) / + static_cast(aspect_height); + + if (config->aspect_ratio > 1) { + SCREEN_WIDTH = static_cast (600 * config->aspect_ratio + 0.5); + SCREEN_HEIGHT = 600; + } else { + SCREEN_WIDTH = 600; + SCREEN_HEIGHT = static_cast (600 * 1/config->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; + } + } + break; + case MNID_FULLSCREEN: if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) { config->use_fullscreen = !config->use_fullscreen; @@ -100,14 +211,13 @@ OptionsMenu::menu_action(MenuItem* item) Menu* get_options_menu() { - if(options_menu == NULL) - options_menu = new OptionsMenu(); - + //static OptionsMenu menu; + options_menu = new OptionsMenu(); return options_menu; } void free_options_menu() { delete options_menu; - options_menu = NULL; + options_menu = 0; }