2011-10-12 06:53:38 -04:00
|
|
|
/*
|
2013-02-24 12:40:43 -05:00
|
|
|
Minetest
|
2013-02-24 13:38:45 -05:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-10-12 06:53:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 10:56:56 -04: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 06:53:38 -04: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 10:56:56 -04:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-10-12 06:53:38 -04:00
|
|
|
|
2012-06-05 10:56:56 -04:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-10-12 06:53:38 -04:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MAINMENUMANAGER_HEADER
|
|
|
|
#define MAINMENUMANAGER_HEADER
|
|
|
|
|
|
|
|
/*
|
|
|
|
All kinds of stuff that needs to be exposed from main.cpp
|
|
|
|
*/
|
|
|
|
#include "debug.h" // assert
|
|
|
|
#include "modalMenu.h"
|
2012-12-20 12:19:49 -05:00
|
|
|
#include <list>
|
2011-10-12 06:53:38 -04:00
|
|
|
|
2014-03-04 13:57:39 -05:00
|
|
|
class IGameCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void exitToOS() = 0;
|
2014-09-20 23:21:11 -04:00
|
|
|
virtual void keyConfig() = 0;
|
2014-03-04 13:57:39 -05:00
|
|
|
virtual void disconnect() = 0;
|
|
|
|
virtual void changePassword() = 0;
|
|
|
|
virtual void changeVolume() = 0;
|
2014-11-09 21:26:19 -05:00
|
|
|
|
|
|
|
virtual void signalKeyConfigChange() = 0;
|
2014-03-04 13:57:39 -05:00
|
|
|
};
|
|
|
|
|
2011-10-12 06:53:38 -04:00
|
|
|
extern gui::IGUIEnvironment* guienv;
|
|
|
|
extern gui::IGUIStaticText *guiroot;
|
|
|
|
|
|
|
|
// Handler for the modal menus
|
|
|
|
|
|
|
|
class MainMenuManager : public IMenuManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void createdMenu(GUIModalMenu *menu)
|
|
|
|
{
|
2012-12-20 12:19:49 -05:00
|
|
|
for(std::list<GUIModalMenu*>::iterator
|
2011-10-12 06:53:38 -04:00
|
|
|
i = m_stack.begin();
|
2012-12-20 12:19:49 -05:00
|
|
|
i != m_stack.end(); ++i)
|
2011-10-12 06:53:38 -04:00
|
|
|
{
|
|
|
|
assert(*i != menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_stack.size() != 0)
|
2012-12-20 12:19:49 -05:00
|
|
|
m_stack.back()->setVisible(false);
|
2011-10-12 06:53:38 -04:00
|
|
|
m_stack.push_back(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void deletingMenu(GUIModalMenu *menu)
|
|
|
|
{
|
|
|
|
// Remove all entries if there are duplicates
|
|
|
|
bool removed_entry;
|
|
|
|
do{
|
|
|
|
removed_entry = false;
|
2012-12-20 12:19:49 -05:00
|
|
|
for(std::list<GUIModalMenu*>::iterator
|
2011-10-12 06:53:38 -04:00
|
|
|
i = m_stack.begin();
|
2012-12-20 12:19:49 -05:00
|
|
|
i != m_stack.end(); ++i)
|
2011-10-12 06:53:38 -04: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);*/
|
|
|
|
|
|
|
|
if(m_stack.size() != 0)
|
2012-12-20 12:19:49 -05:00
|
|
|
m_stack.back()->setVisible(true);
|
2011-10-12 06:53:38 -04:00
|
|
|
}
|
|
|
|
|
2013-08-19 05:26:51 -04:00
|
|
|
// Returns true to prevent further processing
|
|
|
|
virtual bool preprocessEvent(const SEvent& event)
|
|
|
|
{
|
|
|
|
if(m_stack.size() != 0)
|
|
|
|
return m_stack.back()->preprocessEvent(event);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-12 06:53:38 -04:00
|
|
|
u32 menuCount()
|
|
|
|
{
|
|
|
|
return m_stack.size();
|
|
|
|
}
|
|
|
|
|
2014-01-06 10:37:23 -05:00
|
|
|
bool pausesGame()
|
|
|
|
{
|
|
|
|
for(std::list<GUIModalMenu*>::iterator
|
|
|
|
i = m_stack.begin(); i != m_stack.end(); ++i)
|
|
|
|
{
|
|
|
|
if((*i)->pausesGame())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-20 12:19:49 -05:00
|
|
|
std::list<GUIModalMenu*> m_stack;
|
2011-10-12 06:53:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
extern MainMenuManager g_menumgr;
|
|
|
|
|
|
|
|
extern bool noMenuActive();
|
|
|
|
|
|
|
|
class MainGameCallback : public IGameCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MainGameCallback(IrrlichtDevice *a_device):
|
|
|
|
disconnect_requested(false),
|
|
|
|
changepassword_requested(false),
|
2013-02-23 10:01:35 -05:00
|
|
|
changevolume_requested(false),
|
2014-09-20 23:21:11 -04:00
|
|
|
keyconfig_requested(false),
|
2014-04-21 08:10:59 -04:00
|
|
|
shutdown_requested(false),
|
2014-11-09 21:26:19 -05:00
|
|
|
keyconfig_changed(false),
|
2011-10-12 06:53:38 -04:00
|
|
|
device(a_device)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void exitToOS()
|
|
|
|
{
|
2014-04-21 08:10:59 -04:00
|
|
|
shutdown_requested = true;
|
|
|
|
#ifndef __ANDROID__
|
2011-10-12 06:53:38 -04:00
|
|
|
device->closeDevice();
|
2014-04-21 08:10:59 -04:00
|
|
|
#endif
|
2011-10-12 06:53:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void disconnect()
|
|
|
|
{
|
|
|
|
disconnect_requested = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void changePassword()
|
|
|
|
{
|
|
|
|
changepassword_requested = true;
|
|
|
|
}
|
|
|
|
|
2013-02-23 10:01:35 -05:00
|
|
|
virtual void changeVolume()
|
|
|
|
{
|
|
|
|
changevolume_requested = true;
|
|
|
|
}
|
2014-09-20 23:21:11 -04:00
|
|
|
|
|
|
|
virtual void keyConfig()
|
|
|
|
{
|
|
|
|
keyconfig_requested = true;
|
|
|
|
}
|
|
|
|
|
2014-11-09 21:26:19 -05:00
|
|
|
virtual void signalKeyConfigChange()
|
|
|
|
{
|
|
|
|
keyconfig_changed = true;
|
|
|
|
}
|
|
|
|
|
2013-02-23 10:01:35 -05:00
|
|
|
|
2011-10-12 06:53:38 -04:00
|
|
|
bool disconnect_requested;
|
|
|
|
bool changepassword_requested;
|
2013-02-23 10:01:35 -05:00
|
|
|
bool changevolume_requested;
|
2014-09-20 23:21:11 -04:00
|
|
|
bool keyconfig_requested;
|
2014-04-21 08:10:59 -04:00
|
|
|
bool shutdown_requested;
|
2014-11-09 21:26:19 -05:00
|
|
|
|
|
|
|
bool keyconfig_changed;
|
|
|
|
|
2011-10-12 06:53:38 -04:00
|
|
|
IrrlichtDevice *device;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern MainGameCallback *g_gamecallback;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|