1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
luanti/src/gui/mainmenumanager.h

151 lines
2.8 KiB
C
Raw Normal View History

// Luanti
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
2011-10-12 13:53:38 +03:00
#pragma once
2011-10-12 13:53:38 +03:00
/*
All kinds of stuff that needs to be exposed from main.cpp
*/
#include "modalMenu.h"
#include <cassert>
2012-12-20 21:19:49 +04:00
#include <list>
2011-10-12 13:53:38 +03:00
class IGameCallback
{
public:
virtual void exitToOS() = 0;
2014-09-21 00:21:11 -03:00
virtual void keyConfig() = 0;
virtual void disconnect() = 0;
virtual void changePassword() = 0;
virtual void changeVolume() = 0;
virtual void showOpenURLDialog(const std::string &url) = 0;
virtual void signalKeyConfigChange() = 0;
};
extern gui::IGUIEnvironment *guienv;
extern gui::IGUIStaticText *guiroot;
2011-10-12 13:53:38 +03:00
// Handler for the modal menus
class MainMenuManager : public IMenuManager
{
public:
2016-02-27 15:51:09 -05:00
virtual void createdMenu(gui::IGUIElement *menu)
2011-10-12 13:53:38 +03:00
{
for (gui::IGUIElement *e : m_stack) {
if (e == menu)
return;
2011-10-12 13:53:38 +03:00
}
if(!m_stack.empty())
2012-12-20 21:19:49 +04:00
m_stack.back()->setVisible(false);
2011-10-12 13:53:38 +03:00
m_stack.push_back(menu);
guienv->setFocus(m_stack.back());
2011-10-12 13:53:38 +03:00
}
2016-02-27 15:51:09 -05:00
virtual void deletingMenu(gui::IGUIElement *menu)
2011-10-12 13:53:38 +03:00
{
// Remove all entries if there are duplicates
m_stack.remove(menu);
2011-10-12 13:53:38 +03:00
if(!m_stack.empty()) {
2012-12-20 21:19:49 +04:00
m_stack.back()->setVisible(true);
guienv->setFocus(m_stack.back());
}
2011-10-12 13:53:38 +03:00
}
2013-08-19 11:26:51 +02:00
// Returns true to prevent further processing
virtual bool preprocessEvent(const SEvent& event)
{
2016-02-27 15:51:09 -05:00
if (m_stack.empty())
2013-08-19 11:26:51 +02:00
return false;
2016-02-27 15:51:09 -05:00
GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
return mm && mm->preprocessEvent(event);
2013-08-19 11:26:51 +02:00
}
2024-04-11 13:54:09 +02:00
size_t menuCount() const
2011-10-12 13:53:38 +03:00
{
return m_stack.size();
}
2024-11-12 12:52:37 +03:00
void deleteFront()
{
m_stack.front()->setVisible(false);
deletingMenu(m_stack.front());
}
bool pausesGame()
{
for (gui::IGUIElement *i : m_stack) {
GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(i);
2016-02-27 15:51:09 -05:00
if (mm && mm->pausesGame())
return true;
}
return false;
}
2024-11-12 12:52:37 +03:00
private:
2016-02-27 15:51:09 -05:00
std::list<gui::IGUIElement*> m_stack;
2011-10-12 13:53:38 +03:00
};
extern MainMenuManager g_menumgr;
2024-04-11 13:54:09 +02:00
static inline bool isMenuActive()
{
return g_menumgr.menuCount() != 0;
}
2011-10-12 13:53:38 +03:00
class MainGameCallback : public IGameCallback
{
public:
MainGameCallback() = default;
virtual ~MainGameCallback() = default;
2011-10-12 13:53:38 +03:00
void exitToOS() override
2011-10-12 13:53:38 +03:00
{
shutdown_requested = true;
2011-10-12 13:53:38 +03:00
}
void disconnect() override
2011-10-12 13:53:38 +03:00
{
disconnect_requested = true;
}
void changePassword() override
2011-10-12 13:53:38 +03:00
{
changepassword_requested = true;
}
void changeVolume() override
{
changevolume_requested = true;
}
2014-09-21 00:21:11 -03:00
void keyConfig() override
2014-09-21 00:21:11 -03:00
{
keyconfig_requested = true;
}
void signalKeyConfigChange() override
{
keyconfig_changed = true;
}
2024-04-11 13:54:09 +02:00
void showOpenURLDialog(const std::string &url) override
{
show_open_url_dialog = url;
}
bool disconnect_requested = false;
bool changepassword_requested = false;
bool changevolume_requested = false;
bool keyconfig_requested = false;
bool shutdown_requested = false;
bool keyconfig_changed = false;
std::string show_open_url_dialog = "";
2011-10-12 13:53:38 +03:00
};
extern MainGameCallback *g_gamecallback;