OptionsMenu Class Reference

#include <options_menu.hpp>

Inherits Menu.

List of all members.

Public Member Functions

 OptionsMenu ()
virtual ~OptionsMenu ()
void menu_action (MenuItem *item)
void check_menu ()

Protected Attributes

std::auto_ptr< LanguageMenulanguage_menu


Detailed Description

Definition at line 26 of file options_menu.hpp.


Constructor & Destructor Documentation

OptionsMenu::OptionsMenu (  ) 

Definition at line 44 of file options_menu.cpp.

References _(), Menu::add_back(), Menu::add_hl(), Menu::add_inactive(), Menu::add_label(), Menu::add_string_select(), Menu::add_submenu(), Menu::add_toggle(), Config::aspect_size, Config::fullscreen_size, g_config, MenuStorage::get_joystick_options_menu(), MenuStorage::get_key_options_menu(), MenuStorage::get_profile_menu(), Size::height, SoundManager::is_audio_enabled(), language_menu, MenuItem::list, Config::magnification, MNID_ASPECTRATIO, MNID_FULLSCREEN, MNID_FULLSCREEN_RESOLUTION, MNID_MAGNIFICATION, MNID_MUSIC, MNID_PROFILES, MNID_SOUND, Config::music_enabled, StringUtil::numeric_less(), MenuItem::selected, MenuItem::set_help(), Config::sound_enabled, sound_manager, Config::use_fullscreen, and Size::width.

00044                          :
00045   language_menu()
00046 {
00047   language_menu.reset(new LanguageMenu());
00048 
00049   add_label(_("Options"));
00050   add_hl();
00051 
00052   // Language change should only be possible in the main menu, since elsewhere it might not always work fully
00053   // FIXME: Implement me: if (get_parent() == main_menu)
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   // These values go from screen:640/projection:1600 to
00073   // screen:1600/projection:640 (i.e. 640, 800, 1024, 1280, 1600)
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) //auto
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()) //magnification not in our list but accept anyway
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   { // No resolutions at all available, bad
00113 
00114   }
00115   else if(modes == (SDL_Rect **)-1) 
00116   { // All resolutions should work, so we fall back to hardcoded defaults
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     // On Ubuntu/Linux resolutions are returned from highest to
00139     // lowest, so reverse them
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 }

OptionsMenu::~OptionsMenu (  )  [virtual]

Definition at line 216 of file options_menu.cpp.

00217 {
00218 }


Member Function Documentation

void OptionsMenu::menu_action ( MenuItem item  )  [virtual]

Reimplemented from Menu.

Definition at line 221 of file options_menu.cpp.

References _(), Renderer::apply_config(), Config::aspect_size, SoundManager::enable_music(), SoundManager::enable_sound(), Config::fullscreen_size, g_config, Size::height, MenuItem::id, Renderer::instance(), Menu::is_toggled(), MenuItem::list, Config::magnification, MNID_ASPECTRATIO, MNID_FULLSCREEN, MNID_FULLSCREEN_RESOLUTION, MNID_MAGNIFICATION, MNID_MUSIC, MNID_SOUND, Config::music_enabled, MenuManager::recalc_pos(), Config::save(), MenuItem::selected, Config::sound_enabled, sound_manager, Config::use_fullscreen, and Size::width.

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); // Magic values
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; // Magic value 
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         // do nothing, changes are only applied when toggling fullscreen mode
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 }

void OptionsMenu::check_menu (  )  [virtual]

Implements Menu.

Definition at line 297 of file options_menu.cpp.

00298 {
00299 }


Member Data Documentation

std::auto_ptr<LanguageMenu> OptionsMenu::language_menu [protected]

Definition at line 36 of file options_menu.hpp.

Referenced by OptionsMenu().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:33 2014 for SuperTux by  doxygen 1.5.1