mainmenumanager.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 "debug.h" // assert
  22. #include "modalMenu.h"
  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. for(std::list<gui::IGUIElement*>::iterator
  43. i = m_stack.begin();
  44. i != m_stack.end(); ++i)
  45. {
  46. assert(*i != menu);
  47. }
  48. if(!m_stack.empty())
  49. m_stack.back()->setVisible(false);
  50. m_stack.push_back(menu);
  51. }
  52. virtual void deletingMenu(gui::IGUIElement *menu)
  53. {
  54. // Remove all entries if there are duplicates
  55. bool removed_entry;
  56. do{
  57. removed_entry = false;
  58. for(std::list<gui::IGUIElement*>::iterator
  59. i = m_stack.begin();
  60. i != m_stack.end(); ++i)
  61. {
  62. if(*i == menu)
  63. {
  64. m_stack.erase(i);
  65. removed_entry = true;
  66. break;
  67. }
  68. }
  69. }while(removed_entry);
  70. /*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
  71. assert(*i == menu);
  72. m_stack.erase(i);*/
  73. if(!m_stack.empty())
  74. m_stack.back()->setVisible(true);
  75. }
  76. // Returns true to prevent further processing
  77. virtual bool preprocessEvent(const SEvent& event)
  78. {
  79. if (m_stack.empty())
  80. return false;
  81. GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
  82. return mm && mm->preprocessEvent(event);
  83. }
  84. u32 menuCount()
  85. {
  86. return m_stack.size();
  87. }
  88. bool pausesGame()
  89. {
  90. for(std::list<gui::IGUIElement*>::iterator
  91. i = m_stack.begin(); i != m_stack.end(); ++i)
  92. {
  93. GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(*i);
  94. if (mm && mm->pausesGame())
  95. return true;
  96. }
  97. return false;
  98. }
  99. std::list<gui::IGUIElement*> m_stack;
  100. };
  101. extern MainMenuManager g_menumgr;
  102. extern bool isMenuActive();
  103. class MainGameCallback : public IGameCallback
  104. {
  105. public:
  106. MainGameCallback(IrrlichtDevice *a_device):
  107. device(a_device)
  108. {
  109. }
  110. virtual void exitToOS()
  111. {
  112. shutdown_requested = true;
  113. #ifndef __ANDROID__
  114. device->closeDevice();
  115. #endif
  116. }
  117. virtual void disconnect()
  118. {
  119. disconnect_requested = true;
  120. }
  121. virtual void changePassword()
  122. {
  123. changepassword_requested = true;
  124. }
  125. virtual void changeVolume()
  126. {
  127. changevolume_requested = true;
  128. }
  129. virtual void keyConfig()
  130. {
  131. keyconfig_requested = true;
  132. }
  133. virtual void signalKeyConfigChange()
  134. {
  135. keyconfig_changed = true;
  136. }
  137. bool disconnect_requested = false;
  138. bool changepassword_requested = false;
  139. bool changevolume_requested = false;
  140. bool keyconfig_requested = false;
  141. bool shutdown_requested = false;
  142. bool keyconfig_changed = false;
  143. IrrlichtDevice *device;
  144. };
  145. extern MainGameCallback *g_gamecallback;
  146. #endif