options_menu.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. // SuperTux
  2. // Copyright (C) 2004 Tobas Glaesser <tobi.web@gmx.de>
  3. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #include "supertux/menu/options_menu.hpp"
  18. #include "audio/sound_manager.hpp"
  19. #include "gui/dialog.hpp"
  20. #include "gui/item_goto.hpp"
  21. #include "gui/item_stringselect.hpp"
  22. #include "gui/item_toggle.hpp"
  23. #include "gui/menu_item.hpp"
  24. #include "gui/menu_manager.hpp"
  25. #include "supertux/gameconfig.hpp"
  26. #include "supertux/game_session.hpp"
  27. #include "supertux/globals.hpp"
  28. #include "supertux/menu/menu_storage.hpp"
  29. #include "supertux/title_screen.hpp"
  30. #include "util/gettext.hpp"
  31. #include "util/log.hpp"
  32. #include "video/renderer.hpp"
  33. #include "video/video_system.hpp"
  34. #include "video/viewport.hpp"
  35. #include <sstream>
  36. #ifdef __EMSCRIPTEN__
  37. #include <emscripten.h>
  38. #include <emscripten/html5.h>
  39. #endif
  40. bool
  41. OptionsMenu::less_than_volume(const std::string& lhs, const std::string& rhs)
  42. {
  43. int lhs_i, rhs_i;
  44. if (sscanf(lhs.c_str(), "%i", &lhs_i) == 1 &&
  45. sscanf(rhs.c_str(), "%i", &rhs_i) == 1)
  46. {
  47. return lhs_i < rhs_i;
  48. }
  49. return false;
  50. }
  51. OptionsMenu::OptionsMenu(Type type, bool complete) :
  52. m_magnifications(),
  53. m_aspect_ratios(),
  54. m_window_resolutions(),
  55. m_resolutions(),
  56. m_vsyncs(),
  57. m_sound_volumes(),
  58. m_music_volumes(),
  59. m_mobile_control_scales()
  60. {
  61. switch (type) // Insert label and menu items, appropriate for the chosen OptionsMenu type
  62. {
  63. case LOCALE: /** LOCALE */
  64. {
  65. insert_label(_("Locale"));
  66. if (complete)
  67. {
  68. add_submenu(_("Select Language"), MenuStorage::LANGUAGE_MENU)
  69. .set_help(_("Select a different language to display text in"));
  70. add_submenu(_("Language Packs"), MenuStorage::LANGPACK_MENU)
  71. .set_help(_("Language packs contain up-to-date translations"));
  72. }
  73. break;
  74. }
  75. case VIDEO: /** VIDEO */
  76. {
  77. insert_label(_("Video"));
  78. #if !defined(HIDE_NONMOBILE_OPTIONS) && !defined(__EMSCRIPTEN__)
  79. add_toggle(MNID_FULLSCREEN,_("Window Resizable"), &g_config->window_resizable)
  80. .set_help(_("Allow window resizing, might require a restart to take effect"));
  81. add_window_resolutions();
  82. add_toggle(MNID_FULLSCREEN,_("Fullscreen"), &g_config->use_fullscreen)
  83. .set_help(_("Fill the entire screen"));
  84. add_resolutions();
  85. #endif
  86. #if 0
  87. #ifdef __EMSCRIPTEN__
  88. add_toggle(MNID_FIT_WINDOW, _("Fit to browser"), &g_config->fit_window)
  89. .set_help(_("Fit the resolution to the size of your browser"));
  90. #endif
  91. #endif
  92. add_magnification();
  93. add_vsync();
  94. #if !defined(HIDE_NONMOBILE_OPTIONS) && !defined(__EMSCRIPTEN__)
  95. add_aspect_ratio();
  96. #endif
  97. add_submenu(_("Change Video System"), MenuStorage::MenuId::VIDEO_SYSTEM_MENU)
  98. .set_help(_("Change video system used to render graphics"));
  99. break;
  100. }
  101. case AUDIO: /** AUDIO */
  102. {
  103. insert_label(_("Audio"));
  104. if (SoundManager::current()->is_audio_enabled())
  105. {
  106. add_toggle(MNID_SOUND, _("Sound"), &g_config->sound_enabled)
  107. .set_help(_("Disable all sound effects"));
  108. add_toggle(MNID_MUSIC, _("Music"), &g_config->music_enabled)
  109. .set_help(_("Disable all music"));
  110. add_sound_volume();
  111. add_music_volume();
  112. }
  113. else
  114. {
  115. add_inactive( _("Sound (disabled)"));
  116. add_inactive( _("Music (disabled)"));
  117. }
  118. break;
  119. }
  120. case CONTROLS: /** CONTROLS */
  121. {
  122. insert_label(_("Controls"));
  123. // Separated both translation strings so the latter can be removed if it is
  124. // no longer true, without requiring a new round of translating
  125. add_toggle(MNID_RUMBLING, _("Enable Rumbling Controllers"), &g_config->multiplayer_buzz_controllers)
  126. .set_help(_("Enable vibrating the game controllers.") + " " + _("This feature is currently only used in the multiplayer options menu."));
  127. add_submenu(_("Setup Keyboard"), MenuStorage::KEYBOARD_MENU)
  128. .set_help(_("Configure key-action mappings"));
  129. #ifndef UBUNTU_TOUCH
  130. add_submenu(_("Setup Joystick"), MenuStorage::JOYSTICK_MENU)
  131. .set_help(_("Configure joystick control-action mappings"));
  132. #endif
  133. break;
  134. }
  135. case EXTRAS: /** EXTRAS */
  136. {
  137. insert_label(_("Extras"));
  138. if (complete)
  139. add_submenu(_("Select Profile"), MenuStorage::PROFILE_MENU)
  140. .set_help(_("Select a profile to play with"));
  141. #ifndef UBUNTU_TOUCH
  142. add_submenu(_("Multiplayer settings"), MenuStorage::MULTIPLAYER_MENU)
  143. .set_help(_("Configure settings specific to multiplayer"));
  144. #endif
  145. add_toggle(MNID_TRANSITIONS, _("Enable transitions"), &g_config->transitions_enabled)
  146. .set_help(_("Enable screen transitions and smooth menu animation"));
  147. add_toggle(MNID_CUSTOM_TITLE_LEVELS, _("Custom title screen levels"), &g_config->custom_title_levels)
  148. .set_help(_("Allow overriding the title screen level, when loading certain worlds"));
  149. if (g_config->is_christmas() || g_config->christmas_mode)
  150. add_toggle(MNID_CHRISTMAS_MODE, _("Christmas Mode"), &g_config->christmas_mode);
  151. add_submenu(_("Integrations and presence"), MenuStorage::INTEGRATIONS_MENU)
  152. .set_help(_("Manage whether SuperTux should display the levels you play on your social media profiles (Discord)"));
  153. if (g_config->developer_mode)
  154. add_submenu(_("Menu Customization"), MenuStorage::CUSTOM_MENU_MENU)
  155. .set_help(_("Customize the appearance of the menus"));
  156. break;
  157. }
  158. case ADVANCED: /** ADVANCED */
  159. {
  160. insert_label(_("Advanced"));
  161. #ifndef HIDE_NONMOBILE_OPTIONS
  162. if (g_config->developer_mode)
  163. #endif
  164. add_toggle(MNID_DEVELOPER_MODE, _("Developer Mode"), &g_config->developer_mode);
  165. add_toggle(MNID_CONFIRMATION_DIALOG, _("Confirmation Dialog"), &g_config->confirmation_dialog).set_help(_("Confirm aborting level"));
  166. add_toggle(MNID_PAUSE_ON_FOCUSLOSS, _("Pause on focus loss"), &g_config->pause_on_focusloss)
  167. .set_help(_("Automatically pause the game when the window loses focus"));
  168. add_toggle(MNID_CUSTOM_CURSOR, _("Use custom mouse cursor"), &g_config->custom_mouse_cursor).set_help(_("Whether the game renders its own cursor or uses the system's cursor"));
  169. #ifndef __EMSCRIPTEN__
  170. add_toggle(MNID_RELEASE_CHECK, _("Check for new releases"), &g_config->do_release_check)
  171. .set_help(_("Allows the game to perform checks for new SuperTux releases on startup and notify if any found."));
  172. #endif
  173. break;
  174. }
  175. }
  176. add_hl();
  177. add_back(_("Back"));
  178. on_window_resize();
  179. }
  180. OptionsMenu::~OptionsMenu()
  181. {
  182. }
  183. void
  184. OptionsMenu::insert_label(const std::string& text)
  185. {
  186. add_label(text);
  187. add_hl();
  188. }
  189. void
  190. OptionsMenu::add_magnification()
  191. {
  192. // These values go from screen:640/projection:1600 to
  193. // screen:1600/projection:640 (i.e. 640, 800, 1024, 1280, 1600)
  194. m_magnifications.list.push_back(_("auto"));
  195. #ifndef HIDE_NONMOBILE_OPTIONS
  196. m_magnifications.list.push_back("40%");
  197. m_magnifications.list.push_back("50%");
  198. m_magnifications.list.push_back("62.5%");
  199. m_magnifications.list.push_back("80%");
  200. #endif
  201. m_magnifications.list.push_back("100%");
  202. m_magnifications.list.push_back("125%");
  203. m_magnifications.list.push_back("160%");
  204. m_magnifications.list.push_back("200%");
  205. m_magnifications.list.push_back("250%");
  206. // Gets the actual magnification:
  207. if (g_config->magnification != 0.0f) //auto
  208. {
  209. std::ostringstream out;
  210. out << (g_config->magnification*100) << "%";
  211. std::string magn = out.str();
  212. int count = 0;
  213. for (const auto& magnification : m_magnifications.list)
  214. {
  215. if (magnification == magn)
  216. {
  217. m_magnifications.next = count;
  218. magn.clear();
  219. break;
  220. }
  221. ++count;
  222. }
  223. if (!magn.empty()) // Current magnification not found
  224. {
  225. m_magnifications.next = static_cast<int>(m_magnifications.list.size());
  226. m_magnifications.list.push_back(magn);
  227. }
  228. }
  229. add_string_select(MNID_MAGNIFICATION, _("Magnification"), &m_magnifications.next, m_magnifications.list)
  230. .set_help(_("Change the magnification of the game area"));
  231. }
  232. void
  233. OptionsMenu::add_aspect_ratio()
  234. {
  235. m_aspect_ratios.list.push_back(_("auto"));
  236. m_aspect_ratios.list.push_back("5:4");
  237. m_aspect_ratios.list.push_back("4:3");
  238. m_aspect_ratios.list.push_back("16:10");
  239. m_aspect_ratios.list.push_back("16:9");
  240. m_aspect_ratios.list.push_back("1368:768");
  241. // Gets the actual aspect ratio:
  242. if (g_config->aspect_size != Size(0, 0)) //auto
  243. {
  244. std::ostringstream out;
  245. out << g_config->aspect_size.width << ":" << g_config->aspect_size.height;
  246. std::string aspect_ratio = out.str();
  247. int count = 0;
  248. for (const auto& ratio : m_aspect_ratios.list)
  249. {
  250. if (ratio == aspect_ratio)
  251. {
  252. aspect_ratio.clear();
  253. m_aspect_ratios.next = count;
  254. break;
  255. }
  256. ++count;
  257. }
  258. if (!aspect_ratio.empty()) // Current aspect ratio not found
  259. {
  260. m_aspect_ratios.next = static_cast<int>(m_aspect_ratios.list.size());
  261. m_aspect_ratios.list.push_back(aspect_ratio);
  262. }
  263. }
  264. add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"), &m_aspect_ratios.next, m_aspect_ratios.list)
  265. .set_help(_("Adjust the aspect ratio"));
  266. }
  267. void
  268. OptionsMenu::add_window_resolutions()
  269. {
  270. m_window_resolutions.list = { "640x480", "854x480", "800x600", "1280x720", "1280x800",
  271. "1440x900", "1920x1080", "1920x1200", "2560x1440" };
  272. m_window_resolutions.next = -1;
  273. Size window_size = VideoSystem::current()->get_window_size();
  274. std::ostringstream out;
  275. out << window_size.width << "x" << window_size.height;
  276. std::string window_size_text = out.str();
  277. for (size_t i = 0; i < m_window_resolutions.list.size(); ++i)
  278. {
  279. if (m_window_resolutions.list[i] == window_size_text)
  280. {
  281. m_window_resolutions.next = static_cast<int>(i);
  282. break;
  283. }
  284. }
  285. if (m_window_resolutions.next == -1) // Current window resolution not found
  286. {
  287. m_window_resolutions.list.insert(m_window_resolutions.list.begin(), window_size_text);
  288. m_window_resolutions.next = 0;
  289. }
  290. add_string_select(MNID_WINDOW_RESOLUTION, _("Window Resolution"), &m_window_resolutions.next, m_window_resolutions.list)
  291. .set_help(_("Resize the window to the given size"));
  292. }
  293. void
  294. OptionsMenu::add_resolutions()
  295. {
  296. int display_mode_count = SDL_GetNumDisplayModes(0);
  297. std::string last_display_mode;
  298. for (int i = 0; i < display_mode_count; ++i)
  299. {
  300. SDL_DisplayMode mode;
  301. int ret = SDL_GetDisplayMode(0, i, &mode);
  302. if (ret != 0)
  303. {
  304. log_warning << "failed to get display mode: " << SDL_GetError() << std::endl;
  305. }
  306. else
  307. {
  308. std::ostringstream out;
  309. out << mode.w << "x" << mode.h;
  310. if (mode.refresh_rate)
  311. out << "@" << mode.refresh_rate;
  312. if (last_display_mode == out.str())
  313. continue;
  314. last_display_mode = out.str();
  315. m_resolutions.list.insert(m_resolutions.list.begin(), out.str());
  316. }
  317. }
  318. m_resolutions.list.push_back("Desktop");
  319. std::string fullscreen_size_str = _("Desktop");
  320. std::ostringstream out;
  321. if (g_config->fullscreen_size != Size(0, 0))
  322. {
  323. out << g_config->fullscreen_size.width << "x" << g_config->fullscreen_size.height;
  324. if (g_config->fullscreen_refresh_rate)
  325. out << "@" << g_config->fullscreen_refresh_rate;
  326. fullscreen_size_str = out.str();
  327. }
  328. int count = 0;
  329. for (const auto& res : m_resolutions.list)
  330. {
  331. if (res == fullscreen_size_str)
  332. {
  333. fullscreen_size_str.clear();
  334. m_resolutions.next = count;
  335. break;
  336. }
  337. ++count;
  338. }
  339. if (!fullscreen_size_str.empty()) // Current resolution not found
  340. {
  341. m_resolutions.next = static_cast<int>(m_resolutions.list.size());
  342. m_resolutions.list.push_back(fullscreen_size_str);
  343. }
  344. add_string_select(MNID_FULLSCREEN_RESOLUTION, _("Fullscreen Resolution"), &m_resolutions.next, m_resolutions.list)
  345. .set_help(_("Determine the resolution used in fullscreen mode (you must toggle fullscreen to complete the change)"));
  346. }
  347. void
  348. OptionsMenu::add_vsync()
  349. {
  350. m_vsyncs.list.push_back(_("on"));
  351. m_vsyncs.list.push_back(_("off"));
  352. m_vsyncs.list.push_back(_("adaptive"));
  353. const int mode = VideoSystem::current()->get_vsync();
  354. switch (mode)
  355. {
  356. case -1:
  357. m_vsyncs.next = 2;
  358. break;
  359. case 0:
  360. m_vsyncs.next = 1;
  361. break;
  362. case 1:
  363. m_vsyncs.next = 0;
  364. break;
  365. default:
  366. log_warning << "Unknown swap mode: " << mode << std::endl;
  367. m_vsyncs.next = 0;
  368. }
  369. add_string_select(MNID_VSYNC, _("VSync"), &m_vsyncs.next, m_vsyncs.list)
  370. .set_help(_("Set the VSync mode"));
  371. }
  372. void
  373. OptionsMenu::add_sound_volume()
  374. {
  375. m_sound_volumes.list = { "0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%" };
  376. std::ostringstream sound_vol_stream;
  377. sound_vol_stream << g_config->sound_volume << "%";
  378. std::string sound_vol_string = sound_vol_stream.str();
  379. if (std::find(m_sound_volumes.list.begin(),
  380. m_sound_volumes.list.end(), sound_vol_string) == m_sound_volumes.list.end())
  381. {
  382. m_sound_volumes.list.push_back(sound_vol_string);
  383. }
  384. std::sort(m_sound_volumes.list.begin(), m_sound_volumes.list.end(), less_than_volume);
  385. std::ostringstream out;
  386. out << g_config->sound_volume << "%";
  387. std::string sound_volume = out.str();
  388. int count = 0;
  389. for (const auto& volume : m_sound_volumes.list)
  390. {
  391. if (volume == sound_volume)
  392. {
  393. sound_volume.clear();
  394. m_sound_volumes.next = count;
  395. break;
  396. }
  397. ++count;
  398. }
  399. add_string_select(MNID_SOUND_VOLUME, _("Sound Volume"), &m_sound_volumes.next, m_sound_volumes.list)
  400. .set_help(_("Adjust sound volume"));
  401. }
  402. void
  403. OptionsMenu::add_music_volume()
  404. {
  405. m_music_volumes.list = { "0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%" };
  406. std::ostringstream music_vol_stream;
  407. music_vol_stream << g_config->music_volume << "%";
  408. std::string music_vol_string = music_vol_stream.str();
  409. if (std::find(m_music_volumes.list.begin(),
  410. m_music_volumes.list.end(), music_vol_string) == m_music_volumes.list.end())
  411. {
  412. m_music_volumes.list.push_back(music_vol_string);
  413. }
  414. std::sort(m_music_volumes.list.begin(), m_music_volumes.list.end(), less_than_volume);
  415. std::ostringstream out;
  416. out << g_config->music_volume << "%";
  417. std::string music_volume = out.str();
  418. int count = 0;
  419. for (const auto& volume : m_music_volumes.list)
  420. {
  421. if (volume == music_volume)
  422. {
  423. music_volume.clear();
  424. m_music_volumes.next = count;
  425. break;
  426. }
  427. ++count;
  428. }
  429. add_string_select(MNID_MUSIC_VOLUME, _("Music Volume"), &m_music_volumes.next, m_music_volumes.list)
  430. .set_help(_("Adjust music volume"));
  431. }
  432. void
  433. OptionsMenu::add_mobile_control_scales()
  434. {
  435. for (unsigned i = 50; i <= 300; i += 25)
  436. {
  437. m_mobile_control_scales.list.push_back(std::to_string(i) + "%");
  438. if (i == static_cast<unsigned>(g_config->m_mobile_controls_scale * 100))
  439. m_mobile_control_scales.next = (i - 50) / 25;
  440. }
  441. add_string_select(MNID_MOBILE_CONTROLS_SCALE, _("On-screen controls scale"), &m_mobile_control_scales.next, m_mobile_control_scales.list);
  442. }
  443. void
  444. OptionsMenu::on_window_resize()
  445. {
  446. set_center_pos(static_cast<float>(SCREEN_WIDTH) / 2.0f,
  447. static_cast<float>(SCREEN_HEIGHT) / 2.0f + 15.0f);
  448. }
  449. void
  450. OptionsMenu::menu_action(MenuItem& item)
  451. {
  452. switch (item.get_id()) {
  453. case MNID_ASPECTRATIO:
  454. {
  455. if (m_aspect_ratios.next == 0)
  456. {
  457. g_config->aspect_size = Size(0, 0); // Magic values
  458. VideoSystem::current()->apply_config();
  459. MenuManager::instance().on_window_resize();
  460. }
  461. else if (sscanf(m_aspect_ratios.list[m_aspect_ratios.next].c_str(), "%d:%d",
  462. &g_config->aspect_size.width, &g_config->aspect_size.height) == 2)
  463. {
  464. VideoSystem::current()->apply_config();
  465. MenuManager::instance().on_window_resize();
  466. }
  467. else
  468. {
  469. log_fatal << "Invalid aspect ratio " << m_aspect_ratios.list[m_aspect_ratios.next] << " specified" << std::endl;
  470. assert(false);
  471. }
  472. }
  473. break;
  474. case MNID_MAGNIFICATION:
  475. if (m_magnifications.next == 0)
  476. {
  477. g_config->magnification = 0.0f; // Magic value
  478. }
  479. else if (sscanf(m_magnifications.list[m_magnifications.next].c_str(), "%f", &g_config->magnification) == 1)
  480. {
  481. g_config->magnification /= 100.0f;
  482. }
  483. VideoSystem::current()->apply_config();
  484. MenuManager::instance().on_window_resize();
  485. break;
  486. case MNID_WINDOW_RESIZABLE:
  487. if (!g_config->window_resizable)
  488. m_resolutions.next = 0;
  489. break;
  490. case MNID_WINDOW_RESOLUTION:
  491. {
  492. int width;
  493. int height;
  494. if (sscanf(m_window_resolutions.list[m_window_resolutions.next].c_str(), "%dx%d",
  495. &width, &height) != 2)
  496. {
  497. log_fatal << "can't parse " << m_window_resolutions.list[m_window_resolutions.next] << std::endl;
  498. }
  499. else
  500. {
  501. g_config->window_size = Size(width, height);
  502. VideoSystem::current()->apply_config();
  503. MenuManager::instance().on_window_resize();
  504. }
  505. }
  506. break;
  507. case MNID_FULLSCREEN_RESOLUTION:
  508. {
  509. int width;
  510. int height;
  511. int refresh_rate;
  512. if (m_resolutions.list[m_resolutions.next] == "Desktop")
  513. {
  514. g_config->fullscreen_size.width = 0;
  515. g_config->fullscreen_size.height = 0;
  516. g_config->fullscreen_refresh_rate = 0;
  517. }
  518. else if (sscanf(m_resolutions.list[m_resolutions.next].c_str(), "%dx%d@%d",
  519. &width, &height, &refresh_rate) == 3)
  520. {
  521. // do nothing, changes are only applied when toggling fullscreen mode
  522. g_config->fullscreen_size.width = width;
  523. g_config->fullscreen_size.height = height;
  524. g_config->fullscreen_refresh_rate = refresh_rate;
  525. }
  526. else if (sscanf(m_resolutions.list[m_resolutions.next].c_str(), "%dx%d",
  527. &width, &height) == 2)
  528. {
  529. g_config->fullscreen_size.width = width;
  530. g_config->fullscreen_size.height = height;
  531. g_config->fullscreen_refresh_rate = 0;
  532. }
  533. }
  534. break;
  535. #ifdef __EMSCRIPTEN__
  536. case MNID_FIT_WINDOW:
  537. {
  538. // Emscripten's Clang detects the "$" in the macro as part of C++ code
  539. // although it isn't even Javascript, it's Emscripten's way to pass
  540. // arguments from C++ to Javascript
  541. #pragma GCC diagnostic push
  542. #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
  543. int resultds = EM_ASM_INT({
  544. if (window.supertux_setAutofit)
  545. window.supertux_setAutofit($0);
  546. return !!window.supertux_setAutofit;
  547. }, g_config->fit_window);
  548. #pragma GCC diagnostic pop
  549. if (!resultds)
  550. {
  551. Dialog::show_message(_("The game couldn't detect your browser resolution.\n"
  552. "This most likely happens because it is not embedded\n"
  553. "in the SuperTux custom HTML template.\n"));
  554. }
  555. }
  556. break;
  557. #endif
  558. case MNID_VSYNC:
  559. {
  560. int vsync = 0;
  561. switch (m_vsyncs.next)
  562. {
  563. case 2:
  564. vsync = -1;
  565. break;
  566. case 1:
  567. vsync = 0;
  568. break;
  569. case 0:
  570. vsync = 1;
  571. break;
  572. default:
  573. assert(false);
  574. break;
  575. }
  576. g_config->vsync = vsync;
  577. VideoSystem::current()->set_vsync(vsync);
  578. }
  579. break;
  580. case MNID_FULLSCREEN:
  581. VideoSystem::current()->apply_config();
  582. MenuManager::instance().on_window_resize();
  583. g_config->save();
  584. break;
  585. case MNID_SOUND:
  586. SoundManager::current()->enable_sound(g_config->sound_enabled);
  587. g_config->save();
  588. break;
  589. case MNID_SOUND_VOLUME:
  590. if (sscanf(m_sound_volumes.list[m_sound_volumes.next].c_str(), "%i", &g_config->sound_volume) == 1)
  591. {
  592. bool sound_enabled = g_config->sound_volume > 0 ? true : false;
  593. SoundManager::current()->enable_sound(sound_enabled);
  594. SoundManager::current()->set_sound_volume(g_config->sound_volume);
  595. g_config->save();
  596. }
  597. break;
  598. case MNID_MUSIC:
  599. SoundManager::current()->enable_music(g_config->music_enabled);
  600. g_config->save();
  601. break;
  602. case MNID_MUSIC_VOLUME:
  603. if (sscanf(m_music_volumes.list[m_music_volumes.next].c_str(), "%i", &g_config->music_volume) == 1)
  604. {
  605. bool music_enabled = g_config->music_volume > 0 ? true : false;
  606. SoundManager::current()->enable_music(music_enabled);
  607. SoundManager::current()->set_music_volume(g_config->music_volume);
  608. g_config->save();
  609. }
  610. break;
  611. case MNID_CUSTOM_TITLE_LEVELS:
  612. TitleScreen::current()->refresh_level();
  613. break;
  614. case MNID_CUSTOM_CURSOR:
  615. SDL_ShowCursor(g_config->custom_mouse_cursor ? 0 : 1);
  616. break;
  617. case MNID_MOBILE_CONTROLS_SCALE:
  618. if (sscanf(m_mobile_control_scales.list[m_mobile_control_scales.next].c_str(), "%f", &g_config->m_mobile_controls_scale) == EOF)
  619. g_config->m_mobile_controls_scale = 1; // if sscanf fails revert to default scale
  620. else
  621. g_config->m_mobile_controls_scale /= 100.0f;
  622. break;
  623. default:
  624. break;
  625. }
  626. }
  627. /* EOF */