00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "supertux/menu/options_menu.hpp"
00019
00020 #include "audio/sound_manager.hpp"
00021 #include "gui/menu_manager.hpp"
00022 #include "supertux/gameconfig.hpp"
00023 #include "supertux/menu/joystick_menu.hpp"
00024 #include "supertux/menu/keyboard_menu.hpp"
00025 #include "supertux/menu/language_menu.hpp"
00026 #include "supertux/menu/menu_storage.hpp"
00027 #include "supertux/menu/profile_menu.hpp"
00028 #include "util/string_util.hpp"
00029 #include "video/renderer.hpp"
00030
00031 #include <algorithm>
00032 #include <sstream>
00033
00034 enum OptionsMenuIDs {
00035 MNID_FULLSCREEN,
00036 MNID_FULLSCREEN_RESOLUTION,
00037 MNID_MAGNIFICATION,
00038 MNID_ASPECTRATIO,
00039 MNID_PROFILES,
00040 MNID_SOUND,
00041 MNID_MUSIC
00042 };
00043
00044 OptionsMenu::OptionsMenu() :
00045 language_menu()
00046 {
00047 language_menu.reset(new LanguageMenu());
00048
00049 add_label(_("Options"));
00050 add_hl();
00051
00052
00053
00054 add_submenu(_("Select Language"), language_menu.get())
00055 ->set_help(_("Select a different language to display text in"));
00056
00057 add_submenu(_("Select Profile"), MenuStorage::get_profile_menu())
00058 ->set_help(_("Select a profile to play with"));
00059
00060 add_toggle(MNID_PROFILES, _("Profile on Startup"), g_config->sound_enabled)
00061 ->set_help(_("Select your profile immediately after start-up"));
00062
00063 add_toggle(MNID_FULLSCREEN,_("Fullscreen"), g_config->use_fullscreen)
00064 ->set_help(_("Fill the entire screen"));
00065
00066 MenuItem* fullscreen_res = add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Resolution"));
00067 fullscreen_res->set_help(_("Determine the resolution used in fullscreen mode (you must toggle fullscreen to complete the change)"));
00068
00069 MenuItem* magnification = add_string_select(MNID_MAGNIFICATION, _("Magnification"));
00070 magnification->set_help(_("Change the magnification of the game area"));
00071
00072
00073
00074 magnification->list.push_back(_("auto"));
00075 magnification->list.push_back("40%");
00076 magnification->list.push_back("50%");
00077 magnification->list.push_back("62.5%");
00078 magnification->list.push_back("80%");
00079 magnification->list.push_back("100%");
00080 magnification->list.push_back("125%");
00081 magnification->list.push_back("160%");
00082 magnification->list.push_back("200%");
00083 magnification->list.push_back("250%");
00084 if (g_config->magnification != 0.0f)
00085 {
00086 std::ostringstream out;
00087 out << (g_config->magnification*100) << "%";
00088 std::string magn = out.str();
00089 size_t count = 0;
00090 for (std::vector<std::string>::iterator i = magnification->list.begin(); i != magnification->list.end(); ++i)
00091 {
00092 if (*i == magn)
00093 {
00094 magnification->selected = count;
00095 magn.clear();
00096 break;
00097 }
00098
00099 ++count;
00100 }
00101 if (!magn.empty())
00102 {
00103 magnification->selected = magnification->list.size();
00104 magnification->list.push_back(magn);
00105 }
00106 }
00107
00108
00109 SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL);
00110
00111 if (modes == (SDL_Rect **)0)
00112 {
00113
00114 }
00115 else if(modes == (SDL_Rect **)-1)
00116 {
00117 fullscreen_res->list.push_back("640x480");
00118 fullscreen_res->list.push_back("800x600");
00119 fullscreen_res->list.push_back("1024x768");
00120 fullscreen_res->list.push_back("1152x864");
00121 fullscreen_res->list.push_back("1280x960");
00122 fullscreen_res->list.push_back("1280x1024");
00123 fullscreen_res->list.push_back("1440x900");
00124 fullscreen_res->list.push_back("1680x1050");
00125 fullscreen_res->list.push_back("1600x1200");
00126 fullscreen_res->list.push_back("1920x1080");
00127 fullscreen_res->list.push_back("1920x1200");
00128 }
00129 else
00130 {
00131 for(int i = 0; modes[i]; ++i)
00132 {
00133 std::ostringstream out;
00134 out << modes[i]->w << "x" << modes[i]->h;
00135 fullscreen_res->list.push_back(out.str());
00136 }
00137
00138
00139
00140 std::sort(fullscreen_res->list.begin(), fullscreen_res->list.end(), StringUtil::numeric_less);
00141 }
00142
00143 std::ostringstream out;
00144 out << g_config->fullscreen_size.width << "x" << g_config->fullscreen_size.height;
00145 std::string fllscrn_sz = out.str();
00146 size_t cnt = 0;
00147 for (std::vector<std::string>::iterator i = fullscreen_res->list.begin(); i != fullscreen_res->list.end(); ++i)
00148 {
00149 if (*i == fllscrn_sz)
00150 {
00151 fllscrn_sz.clear();
00152 fullscreen_res->selected = cnt;
00153 break;
00154 }
00155 ++cnt;
00156 }
00157 if (!fllscrn_sz.empty())
00158 {
00159 fullscreen_res->selected = fullscreen_res->list.size();
00160 fullscreen_res->list.push_back(fllscrn_sz);
00161 }
00162
00163 MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
00164 aspect->set_help(_("Adjust the aspect ratio"));
00165
00166 aspect->list.push_back(_("auto"));
00167 aspect->list.push_back("5:4");
00168 aspect->list.push_back("4:3");
00169 aspect->list.push_back("16:10");
00170 aspect->list.push_back("16:9");
00171 aspect->list.push_back("1368:768");
00172
00173 if (g_config->aspect_size != Size(0, 0))
00174 {
00175 std::ostringstream out;
00176 out << g_config->aspect_size.width << ":" << g_config->aspect_size.height;
00177 std::string aspect_ratio = out.str();
00178 size_t cnt = 0;
00179 for(std::vector<std::string>::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i)
00180 {
00181 if(*i == aspect_ratio)
00182 {
00183 aspect_ratio.clear();
00184 aspect->selected = cnt;
00185 break;
00186 }
00187 ++cnt;
00188 }
00189
00190 if (!aspect_ratio.empty())
00191 {
00192 aspect->selected = aspect->list.size();
00193 aspect->list.push_back(aspect_ratio);
00194 }
00195 }
00196
00197 if (sound_manager->is_audio_enabled()) {
00198 add_toggle(MNID_SOUND, _("Sound"), g_config->sound_enabled)
00199 ->set_help(_("Disable all sound effects"));
00200 add_toggle(MNID_MUSIC, _("Music"), g_config->music_enabled)
00201 ->set_help(_("Disable all music"));
00202 } else {
00203 add_inactive(MNID_SOUND, _("Sound (disabled)"));
00204 add_inactive(MNID_MUSIC, _("Music (disabled)"));
00205 }
00206
00207 add_submenu(_("Setup Keyboard"), MenuStorage::get_key_options_menu())
00208 ->set_help(_("Configure key-action mappings"));
00209
00210 add_submenu(_("Setup Joystick"), MenuStorage::get_joystick_options_menu())
00211 ->set_help(_("Configure joystick control-action mappings"));
00212 add_hl();
00213 add_back(_("Back"));
00214 }
00215
00216 OptionsMenu::~OptionsMenu()
00217 {
00218 }
00219
00220 void
00221 OptionsMenu::menu_action(MenuItem* item)
00222 {
00223 switch (item->id) {
00224 case MNID_ASPECTRATIO:
00225 {
00226 if (item->list[item->selected] == _("auto"))
00227 {
00228 g_config->aspect_size = Size(0, 0);
00229 Renderer::instance()->apply_config();
00230 MenuManager::recalc_pos();
00231 }
00232 else if (sscanf(item->list[item->selected].c_str(), "%d:%d",
00233 &g_config->aspect_size.width, &g_config->aspect_size.height) == 2)
00234 {
00235 Renderer::instance()->apply_config();
00236 MenuManager::recalc_pos();
00237 }
00238 else
00239 {
00240 assert(!"This must not be reached");
00241 }
00242 }
00243 break;
00244
00245 case MNID_MAGNIFICATION:
00246 if (item->list[item->selected] == _("auto"))
00247 {
00248 g_config->magnification = 0.0f;
00249 }
00250 else if(sscanf(item->list[item->selected].c_str(), "%f", &g_config->magnification) == 1)
00251 {
00252 g_config->magnification /= 100.0f;
00253 }
00254 Renderer::instance()->apply_config();
00255 MenuManager::recalc_pos();
00256 break;
00257
00258 case MNID_FULLSCREEN_RESOLUTION:
00259 if(sscanf(item->list[item->selected].c_str(), "%dx%d",
00260 &g_config->fullscreen_size.width, &g_config->fullscreen_size.height) == 2)
00261 {
00262
00263 }
00264 break;
00265
00266 case MNID_FULLSCREEN:
00267 if(g_config->use_fullscreen != is_toggled(MNID_FULLSCREEN)) {
00268 g_config->use_fullscreen = !g_config->use_fullscreen;
00269 Renderer::instance()->apply_config();
00270 MenuManager::recalc_pos();
00271 g_config->save();
00272 }
00273 break;
00274
00275 case MNID_SOUND:
00276 if(g_config->sound_enabled != is_toggled(MNID_SOUND)) {
00277 g_config->sound_enabled = !g_config->sound_enabled;
00278 sound_manager->enable_sound(g_config->sound_enabled);
00279 g_config->save();
00280 }
00281 break;
00282
00283 case MNID_MUSIC:
00284 if(g_config->music_enabled != is_toggled(MNID_MUSIC)) {
00285 g_config->music_enabled = !g_config->music_enabled;
00286 sound_manager->enable_music(g_config->music_enabled);
00287 g_config->save();
00288 }
00289 break;
00290
00291 default:
00292 break;
00293 }
00294 }
00295
00296 void
00297 OptionsMenu::check_menu()
00298 {
00299 }
00300
00301