Final Minetest - Please use Linux & Windows build kits at: https://downloads.minetest.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mainmenumanager.h 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef MAINMENUMANAGER_HEADER
  17. #define MAINMENUMANAGER_HEADER
  18. /*
  19. All kinds of stuff that needs to be exposed from main.cpp
  20. */
  21. #include "modalMenu.h"
  22. #include <cassert>
  23. #include <list>
  24. class IGameCallback
  25. {
  26. public:
  27. virtual void exitToOS() = 0;
  28. virtual void keyConfig() = 0;
  29. virtual void disconnect() = 0;
  30. virtual void changePassword() = 0;
  31. virtual void changeVolume() = 0;
  32. virtual void signalKeyConfigChange() = 0;
  33. };
  34. extern gui::IGUIEnvironment *guienv;
  35. extern gui::IGUIStaticText *guiroot;
  36. // Handler for the modal menus
  37. class MainMenuManager : public IMenuManager
  38. {
  39. public:
  40. virtual void createdMenu(gui::IGUIElement *menu)
  41. {
  42. #ifdef NOTDEF // Silence a warning
  43. for (gui::IGUIElement *i : m_stack) {
  44. assert(i != menu);
  45. }
  46. #endif
  47. if(!m_stack.empty())
  48. m_stack.back()->setVisible(false);
  49. m_stack.push_back(menu);
  50. }
  51. virtual void deletingMenu(gui::IGUIElement *menu)
  52. {
  53. // Remove all entries if there are duplicates
  54. m_stack.remove(menu);
  55. /*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
  56. assert(*i == menu);
  57. m_stack.erase(i);*/
  58. if(!m_stack.empty())
  59. m_stack.back()->setVisible(true);
  60. }
  61. // Returns true to prevent further processing
  62. virtual bool preprocessEvent(const SEvent& event)
  63. {
  64. if (m_stack.empty())
  65. return false;
  66. GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
  67. return mm && mm->preprocessEvent(event);
  68. }
  69. u32 menuCount()
  70. {
  71. return m_stack.size();
  72. }
  73. bool pausesGame()
  74. {
  75. for (gui::IGUIElement *i : m_stack) {
  76. GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(i);
  77. if (mm && mm->pausesGame())
  78. return true;
  79. }
  80. return false;
  81. }
  82. std::list<gui::IGUIElement*> m_stack;
  83. };
  84. extern MainMenuManager g_menumgr;
  85. extern bool isMenuActive();
  86. class MainGameCallback : public IGameCallback
  87. {
  88. public:
  89. MainGameCallback() = default;
  90. virtual ~MainGameCallback() = default;
  91. virtual void exitToOS()
  92. {
  93. shutdown_requested = true;
  94. }
  95. virtual void disconnect()
  96. {
  97. disconnect_requested = true;
  98. }
  99. virtual void changePassword()
  100. {
  101. changepassword_requested = true;
  102. }
  103. virtual void changeVolume()
  104. {
  105. changevolume_requested = true;
  106. }
  107. virtual void keyConfig()
  108. {
  109. keyconfig_requested = true;
  110. }
  111. virtual void signalKeyConfigChange()
  112. {
  113. keyconfig_changed = true;
  114. }
  115. bool disconnect_requested = false;
  116. bool changepassword_requested = false;
  117. bool changevolume_requested = false;
  118. bool keyconfig_requested = false;
  119. bool shutdown_requested = false;
  120. bool keyconfig_changed = false;
  121. };
  122. extern MainGameCallback *g_gamecallback;
  123. #endif