game_menu.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SuperTux
  2. // Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "supertux/menu/game_menu.hpp"
  17. #include "gui/dialog.hpp"
  18. #include "gui/menu_item.hpp"
  19. #include "gui/menu_manager.hpp"
  20. #include "supertux/game_session.hpp"
  21. #include "supertux/gameconfig.hpp"
  22. #include "supertux/globals.hpp"
  23. #include "supertux/level.hpp"
  24. #include "supertux/menu/menu_storage.hpp"
  25. #include "supertux/sector.hpp"
  26. #include "object/player.hpp"
  27. #include "util/gettext.hpp"
  28. GameMenu::GameMenu() :
  29. reset_callback ( [] {
  30. MenuManager::instance().clear_menu_stack();
  31. GameSession::current()->toggle_pause();
  32. GameSession::current()->reset_button = true;
  33. }),
  34. reset_checkpoint_callback( [] {
  35. MenuManager::instance().clear_menu_stack();
  36. GameSession::current()->toggle_pause();
  37. GameSession::current()->reset_checkpoint_button = true;
  38. }),
  39. abort_callback([] {
  40. GameSession::current()->abort_level();
  41. })
  42. {
  43. Level& level = GameSession::current()->get_current_level();
  44. add_label(level.m_name);
  45. add_hl();
  46. add_entry(MNID_CONTINUE, _("Continue"));
  47. add_entry(MNID_RESETLEVEL, _("Restart Level"));
  48. if (Sector::current()->get_players()[0]->get_status().can_reach_checkpoint()) {
  49. add_entry(MNID_RESETLEVELCHECKPOINT, _("Restart from Checkpoint"));
  50. }
  51. add_submenu(_("Options"), MenuStorage::INGAME_OPTIONS_MENU);
  52. add_hl();
  53. add_entry(MNID_ABORTLEVEL, _("Abort Level"));
  54. }
  55. void
  56. GameMenu::menu_action(MenuItem& item)
  57. {
  58. switch (item.get_id())
  59. {
  60. case MNID_CONTINUE:
  61. MenuManager::instance().clear_menu_stack();
  62. GameSession::current()->toggle_pause();
  63. break;
  64. case MNID_RESETLEVEL:
  65. if (g_config->confirmation_dialog)
  66. {
  67. Dialog::show_confirmation(_("Are you sure?"), reset_callback);
  68. }
  69. else
  70. {
  71. reset_callback();
  72. }
  73. break;
  74. case MNID_RESETLEVELCHECKPOINT:
  75. if (g_config->confirmation_dialog)
  76. {
  77. Dialog::show_confirmation(_("Are you sure?"),
  78. reset_checkpoint_callback);
  79. }
  80. else
  81. {
  82. reset_checkpoint_callback();
  83. }
  84. break;
  85. case MNID_ABORTLEVEL:
  86. if (g_config->confirmation_dialog)
  87. {
  88. Dialog::show_confirmation(_("Are you sure?"), abort_callback);
  89. }
  90. else
  91. {
  92. abort_callback();
  93. }
  94. break;
  95. }
  96. }
  97. /* EOF */