Added WorldmapCheatMenu (grow/fire/snow/etc., mark levels as solved)
[supertux.git] / src / supertux / menu / options_menu.cpp
index 13d6c30..c0991c2 100644 (file)
@@ -37,30 +37,26 @@ enum OptionsMenuIDs {
   MNID_FULLSCREEN_RESOLUTION,
   MNID_MAGNIFICATION,
   MNID_ASPECTRATIO,
-  MNID_PROFILES,
   MNID_SOUND,
   MNID_MUSIC
 };
 
-OptionsMenu::OptionsMenu() :
-  language_menu()
+OptionsMenu::OptionsMenu(bool complete)
 {
-  language_menu.reset(new LanguageMenu());
-
   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(_("Select a different language to display text in"));
+  if (complete)
+  {
+    // Language and profile changes are only be possible in the
+    // main menu, since elsewhere it might not always work fully
+    add_submenu(_("Select Language"), MenuStorage::LANGUAGE_MENU)
+      ->set_help(_("Select a different language to display text in"));
 
-  add_submenu(_("Select Profile"), MenuStorage::get_profile_menu())
-    ->set_help(_("Select a profile to play with"));
+    add_submenu(_("Select Profile"), MenuStorage::PROFILE_MENU)
+      ->set_help(_("Select a profile to play with"));
+  }
 
-  add_toggle(MNID_PROFILES, _("Profile on Startup"), g_config->sound_enabled)
-    ->set_help(_("Select your profile immediately after start-up"));
-  
   add_toggle(MNID_FULLSCREEN,_("Fullscreen"), g_config->use_fullscreen)
     ->set_help(_("Fill the entire screen"));
 
@@ -96,7 +92,7 @@ OptionsMenu::OptionsMenu() :
        magn.clear();
        break;
       }
-      
+
       ++count;
     }
     if (!magn.empty()) //magnification not in our list but accept anyway
@@ -105,56 +101,56 @@ OptionsMenu::OptionsMenu() :
       magnification->list.push_back(magn);
     }
   }
-  
 
-  for(int disp_mode_ctr = 0; disp_mode_ctr < SDL_GetNumDisplayModes(0); disp_mode_ctr++)
+  int display_mode_count = SDL_GetNumDisplayModes(0);
+  std::string last_display_mode;
+  for(int i = 0; i < display_mode_count; ++i)
   {
-    SDL_DisplayMode* current = NULL;
-    int disp_retval = SDL_GetDisplayMode(0, // Display Index
-                                         disp_mode_ctr, // Mode index (default to first)
-                                         current); // DisplayMode structure ptr
-    if (disp_retval == -1) 
-    { // No resolutions at all available, bad
-    }
-    else if(disp_retval == 0) 
-    { // All resolutions should work, so we fall back to hardcoded defaults
-      std::stringstream width;
-      std::stringstream height;
-      width << current->w;
-      height << current->h;
-      fullscreen_res->list.push_back(width.str() + "x" + height.str());
+    SDL_DisplayMode mode;
+    int ret = SDL_GetDisplayMode(0, i, &mode);
+    if (ret != 0)
+    {
+      log_warning << "failed to get display mode: " << SDL_GetError() << std::endl;
     }
     else
     {
+      std::ostringstream out;
+      out << mode.w << "x" << mode.h << "@" << mode.refresh_rate;
+      if(last_display_mode == out.str())
+        continue;
+      last_display_mode = out.str();
+      fullscreen_res->list.push_back(out.str());
     }
   }
-  // On Ubuntu/Linux resolutions are returned from highest to
-  // lowest, so reverse them
-  std::sort(fullscreen_res->list.begin(), fullscreen_res->list.end(), StringUtil::numeric_less);      
-  
+  fullscreen_res->list.push_back("Desktop");
+
   std::ostringstream out;
-  out << g_config->fullscreen_size.width << "x" << g_config->fullscreen_size.height;
-  std::string fllscrn_sz = out.str();
+  std::string fullscreen_size_str = "Desktop";
+  if (g_config->fullscreen_size != Size(0, 0))
+  {
+    out << g_config->fullscreen_size.width << "x" << g_config->fullscreen_size.height << "@" << g_config->fullscreen_refresh_rate;
+    fullscreen_size_str = out.str();
+  }
   size_t cnt = 0;
-  for (std::vector<std::string>::iterator i = fullscreen_res->list.begin(); i != fullscreen_res->list.end(); ++i) 
+  for (std::vector<std::string>::iterator i = fullscreen_res->list.begin(); i != fullscreen_res->list.end(); ++i)
   {
-    if (*i == fllscrn_sz)
+    if (*i == fullscreen_size_str)
     {
-      fllscrn_sz.clear();
+      fullscreen_size_str.clear();
       fullscreen_res->selected = cnt;
       break;
     }
     ++cnt;
   }
-  if (!fllscrn_sz.empty())
+  if (!fullscreen_size_str.empty())
   {
     fullscreen_res->selected = fullscreen_res->list.size();
-    fullscreen_res->list.push_back(fllscrn_sz);
+    fullscreen_res->list.push_back(fullscreen_size_str);
   }
 
   MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
   aspect->set_help(_("Adjust the aspect ratio"));
-  
+
   aspect->list.push_back(_("auto"));
   aspect->list.push_back("5:4");
   aspect->list.push_back("4:3");
@@ -185,7 +181,7 @@ OptionsMenu::OptionsMenu() :
       aspect->list.push_back(aspect_ratio);
     }
   }
-  
+
   if (sound_manager->is_audio_enabled()) {
     add_toggle(MNID_SOUND, _("Sound"), g_config->sound_enabled)
       ->set_help(_("Disable all sound effects"));
@@ -195,11 +191,11 @@ OptionsMenu::OptionsMenu() :
     add_inactive(MNID_SOUND, _("Sound (disabled)"));
     add_inactive(MNID_MUSIC, _("Music (disabled)"));
   }
-  
-  add_submenu(_("Setup Keyboard"), MenuStorage::get_key_options_menu())
+
+  add_submenu(_("Setup Keyboard"), MenuStorage::KEYBOARD_MENU)
     ->set_help(_("Configure key-action mappings"));
 
-  add_submenu(_("Setup Joystick"), MenuStorage::get_joystick_options_menu())
+  add_submenu(_("Setup Joystick"), MenuStorage::JOYSTICK_MENU)
     ->set_help(_("Configure joystick control-action mappings"));
   add_hl();
   add_back(_("Back"));
@@ -214,52 +210,66 @@ OptionsMenu::menu_action(MenuItem* item)
 {
   switch (item->id) {
     case MNID_ASPECTRATIO:
-    { 
-      if (item->list[item->selected] == _("auto"))
-      {
-        g_config->aspect_size = Size(0, 0); // Magic values
-        Renderer::instance()->apply_config();
-        MenuManager::recalc_pos();
-      }
-      else if (sscanf(item->list[item->selected].c_str(), "%d:%d", 
-                      &g_config->aspect_size.width, &g_config->aspect_size.height) == 2)
       {
-        Renderer::instance()->apply_config();
-        MenuManager::recalc_pos();
+        if (item->list[item->selected] == _("auto"))
+        {
+          g_config->aspect_size = Size(0, 0); // Magic values
+          Renderer::instance()->apply_config();
+          MenuManager::instance().on_window_resize();
+        }
+        else if (sscanf(item->list[item->selected].c_str(), "%d:%d",
+                        &g_config->aspect_size.width, &g_config->aspect_size.height) == 2)
+        {
+          Renderer::instance()->apply_config();
+          MenuManager::instance().on_window_resize();
+        }
+        else
+        {
+          assert(!"This must not be reached");
+        }
       }
-      else
-      {
-        assert(!"This must not be reached");
-      }
-    }
-    break;
+      break;
 
     case MNID_MAGNIFICATION:
       if (item->list[item->selected] == _("auto"))
       {
-        g_config->magnification = 0.0f; // Magic value 
+        g_config->magnification = 0.0f; // Magic value
       }
       else if(sscanf(item->list[item->selected].c_str(), "%f", &g_config->magnification) == 1)
       {
         g_config->magnification /= 100.0f;
       }
       Renderer::instance()->apply_config();
-      MenuManager::recalc_pos();
+      MenuManager::instance().on_window_resize();
       break;
 
     case MNID_FULLSCREEN_RESOLUTION:
-      if(sscanf(item->list[item->selected].c_str(), "%dx%d", 
-                &g_config->fullscreen_size.width, &g_config->fullscreen_size.height) == 2)
       {
-        // do nothing, changes are only applied when toggling fullscreen mode
-      }      
+        int width;
+        int height;
+        int refresh_rate;
+        if (item->list[item->selected] == "Desktop")
+        {
+          g_config->fullscreen_size.width = 0;
+          g_config->fullscreen_size.height = 0;
+          g_config->fullscreen_refresh_rate = 0;
+        }
+        else if(sscanf(item->list[item->selected].c_str(), "%dx%d@%d",
+                  &width, &height, &refresh_rate) == 3)
+        {
+          // do nothing, changes are only applied when toggling fullscreen mode
+          g_config->fullscreen_size.width = width;
+          g_config->fullscreen_size.height = height;
+          g_config->fullscreen_refresh_rate = refresh_rate;
+        }
+      }
       break;
 
     case MNID_FULLSCREEN:
       if(g_config->use_fullscreen != is_toggled(MNID_FULLSCREEN)) {
         g_config->use_fullscreen = !g_config->use_fullscreen;
         Renderer::instance()->apply_config();
-        MenuManager::recalc_pos();
+        MenuManager::instance().on_window_resize();
         g_config->save();
       }
       break;