2011-10-12 12:53:38 +02:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-10-12 12:53:38 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2011-10-12 12:53:38 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-10-12 12:53:38 +02:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-10-12 12:53:38 +02:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2011-10-12 12:53:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
All kinds of stuff that needs to be exposed from main.cpp
|
|
|
|
*/
|
|
|
|
#include "modalMenu.h"
|
2017-08-18 19:25:07 +02:00
|
|
|
#include <cassert>
|
2012-12-20 18:19:49 +01:00
|
|
|
#include <list>
|
2011-10-12 12:53:38 +02:00
|
|
|
|
2014-03-04 19:57:39 +01:00
|
|
|
class IGameCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void exitToOS() = 0;
|
2014-09-21 05:21:11 +02:00
|
|
|
virtual void keyConfig() = 0;
|
2014-03-04 19:57:39 +01:00
|
|
|
virtual void disconnect() = 0;
|
|
|
|
virtual void changePassword() = 0;
|
|
|
|
virtual void changeVolume() = 0;
|
2014-11-10 03:26:19 +01:00
|
|
|
|
|
|
|
virtual void signalKeyConfigChange() = 0;
|
2014-03-04 19:57:39 +01:00
|
|
|
};
|
|
|
|
|
2015-04-01 15:01:28 +02:00
|
|
|
extern gui::IGUIEnvironment *guienv;
|
2011-10-12 12:53:38 +02:00
|
|
|
extern gui::IGUIStaticText *guiroot;
|
|
|
|
|
|
|
|
// Handler for the modal menus
|
|
|
|
|
|
|
|
class MainMenuManager : public IMenuManager
|
|
|
|
{
|
|
|
|
public:
|
2016-02-27 21:51:09 +01:00
|
|
|
virtual void createdMenu(gui::IGUIElement *menu)
|
2011-10-12 12:53:38 +02:00
|
|
|
{
|
2017-08-20 13:30:50 +02:00
|
|
|
#ifndef NDEBUG
|
2017-08-18 18:18:25 +02:00
|
|
|
for (gui::IGUIElement *i : m_stack) {
|
|
|
|
assert(i != menu);
|
2011-10-12 12:53:38 +02:00
|
|
|
}
|
2017-08-20 13:30:50 +02:00
|
|
|
#endif
|
2011-10-12 12:53:38 +02:00
|
|
|
|
2014-12-12 15:55:40 +01:00
|
|
|
if(!m_stack.empty())
|
2012-12-20 18:19:49 +01:00
|
|
|
m_stack.back()->setVisible(false);
|
2011-10-12 12:53:38 +02:00
|
|
|
m_stack.push_back(menu);
|
|
|
|
}
|
|
|
|
|
2016-02-27 21:51:09 +01:00
|
|
|
virtual void deletingMenu(gui::IGUIElement *menu)
|
2011-10-12 12:53:38 +02:00
|
|
|
{
|
|
|
|
// Remove all entries if there are duplicates
|
|
|
|
bool removed_entry;
|
|
|
|
do{
|
|
|
|
removed_entry = false;
|
2016-02-27 21:51:09 +01:00
|
|
|
for(std::list<gui::IGUIElement*>::iterator
|
2011-10-12 12:53:38 +02:00
|
|
|
i = m_stack.begin();
|
2012-12-20 18:19:49 +01:00
|
|
|
i != m_stack.end(); ++i)
|
2011-10-12 12:53:38 +02:00
|
|
|
{
|
|
|
|
if(*i == menu)
|
|
|
|
{
|
|
|
|
m_stack.erase(i);
|
|
|
|
removed_entry = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}while(removed_entry);
|
|
|
|
|
|
|
|
/*core::list<GUIModalMenu*>::Iterator i = m_stack.getLast();
|
|
|
|
assert(*i == menu);
|
|
|
|
m_stack.erase(i);*/
|
2017-05-13 11:05:16 +02:00
|
|
|
|
2014-12-12 15:55:40 +01:00
|
|
|
if(!m_stack.empty())
|
2012-12-20 18:19:49 +01:00
|
|
|
m_stack.back()->setVisible(true);
|
2011-10-12 12:53:38 +02:00
|
|
|
}
|
|
|
|
|
2013-08-19 11:26:51 +02:00
|
|
|
// Returns true to prevent further processing
|
|
|
|
virtual bool preprocessEvent(const SEvent& event)
|
|
|
|
{
|
2016-02-27 21:51:09 +01:00
|
|
|
if (m_stack.empty())
|
2013-08-19 11:26:51 +02:00
|
|
|
return false;
|
2016-02-27 21:51:09 +01:00
|
|
|
GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
|
|
|
|
return mm && mm->preprocessEvent(event);
|
2013-08-19 11:26:51 +02:00
|
|
|
}
|
|
|
|
|
2011-10-12 12:53:38 +02:00
|
|
|
u32 menuCount()
|
|
|
|
{
|
|
|
|
return m_stack.size();
|
|
|
|
}
|
|
|
|
|
2014-01-06 16:37:23 +01:00
|
|
|
bool pausesGame()
|
|
|
|
{
|
2017-08-18 18:18:25 +02:00
|
|
|
for (gui::IGUIElement *i : m_stack) {
|
|
|
|
GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(i);
|
2016-02-27 21:51:09 +01:00
|
|
|
if (mm && mm->pausesGame())
|
2014-01-06 16:37:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-27 21:51:09 +01:00
|
|
|
std::list<gui::IGUIElement*> m_stack;
|
2011-10-12 12:53:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern MainMenuManager g_menumgr;
|
|
|
|
|
2017-05-13 11:05:16 +02:00
|
|
|
extern bool isMenuActive();
|
2011-10-12 12:53:38 +02:00
|
|
|
|
|
|
|
class MainGameCallback : public IGameCallback
|
|
|
|
{
|
|
|
|
public:
|
2017-08-18 18:18:25 +02:00
|
|
|
MainGameCallback() = default;
|
|
|
|
virtual ~MainGameCallback() = default;
|
2011-10-12 12:53:38 +02:00
|
|
|
|
|
|
|
virtual void exitToOS()
|
|
|
|
{
|
2014-04-21 14:10:59 +02:00
|
|
|
shutdown_requested = true;
|
2011-10-12 12:53:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void disconnect()
|
|
|
|
{
|
|
|
|
disconnect_requested = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void changePassword()
|
|
|
|
{
|
|
|
|
changepassword_requested = true;
|
|
|
|
}
|
|
|
|
|
2013-02-23 16:01:35 +01:00
|
|
|
virtual void changeVolume()
|
|
|
|
{
|
|
|
|
changevolume_requested = true;
|
|
|
|
}
|
2014-09-21 05:21:11 +02:00
|
|
|
|
|
|
|
virtual void keyConfig()
|
|
|
|
{
|
|
|
|
keyconfig_requested = true;
|
|
|
|
}
|
|
|
|
|
2014-11-10 03:26:19 +01:00
|
|
|
virtual void signalKeyConfigChange()
|
|
|
|
{
|
|
|
|
keyconfig_changed = true;
|
|
|
|
}
|
|
|
|
|
2017-05-13 11:05:16 +02:00
|
|
|
|
2017-06-17 19:11:28 +02:00
|
|
|
bool disconnect_requested = false;
|
|
|
|
bool changepassword_requested = false;
|
|
|
|
bool changevolume_requested = false;
|
|
|
|
bool keyconfig_requested = false;
|
|
|
|
bool shutdown_requested = false;
|
2014-11-10 03:26:19 +01:00
|
|
|
|
2017-06-17 19:11:28 +02:00
|
|
|
bool keyconfig_changed = false;
|
2011-10-12 12:53:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern MainGameCallback *g_gamecallback;
|