Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
mainmenumanager.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7/*
8 All kinds of stuff that needs to be exposed from main.cpp
9*/
10#include "modalMenu.h"
11#include <cassert>
12#include <list>
13
15{
16public:
17 virtual void exitToOS() = 0;
18 virtual void keyConfig() = 0;
19 virtual void disconnect() = 0;
20 virtual void changePassword() = 0;
21 virtual void changeVolume() = 0;
22 virtual void showOpenURLDialog(const std::string &url) = 0;
23 virtual void signalKeyConfigChange() = 0;
24};
25
26extern gui::IGUIEnvironment *guienv;
27extern gui::IGUIStaticText *guiroot;
28
29// Handler for the modal menus
30
32{
33public:
34 virtual void createdMenu(gui::IGUIElement *menu)
35 {
36 for (gui::IGUIElement *e : m_stack) {
37 if (e == menu)
38 return;
39 }
40
41 if(!m_stack.empty())
42 m_stack.back()->setVisible(false);
43
44 m_stack.push_back(menu);
45 guienv->setFocus(m_stack.back());
46 }
47
48 virtual void deletingMenu(gui::IGUIElement *menu)
49 {
50 // Remove all entries if there are duplicates
51 m_stack.remove(menu);
52
53 if(!m_stack.empty()) {
54 m_stack.back()->setVisible(true);
55 guienv->setFocus(m_stack.back());
56 }
57 }
58
59 // Returns true to prevent further processing
60 virtual bool preprocessEvent(const SEvent& event)
61 {
62 if (m_stack.empty())
63 return false;
64 GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
65 return mm && mm->preprocessEvent(event);
66 }
67
68 size_t menuCount() const
69 {
70 return m_stack.size();
71 }
72
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
83 // FIXME: why isn't this private?
84 std::list<gui::IGUIElement*> m_stack;
85};
86
88
89static inline bool isMenuActive()
90{
91 return g_menumgr.menuCount() != 0;
92}
93
95{
96public:
97 MainGameCallback() = default;
98 virtual ~MainGameCallback() = default;
99
100 void exitToOS() override
101 {
102 shutdown_requested = true;
103 }
104
105 void disconnect() override
106 {
108 }
109
110 void changePassword() override
111 {
113 }
114
115 void changeVolume() override
116 {
118 }
119
120 void keyConfig() override
121 {
122 keyconfig_requested = true;
123 }
124
125 void signalKeyConfigChange() override
126 {
127 keyconfig_changed = true;
128 }
129
130 void showOpenURLDialog(const std::string &url) override
131 {
133 }
134
139 bool shutdown_requested = false;
140 bool keyconfig_changed = false;
141 std::string show_open_url_dialog = "";
142};
143
Definition modalMenu.h:36
virtual bool preprocessEvent(const SEvent &event)
Definition modalMenu.cpp:243
virtual bool pausesGame()
Definition modalMenu.h:51
Definition mainmenumanager.h:15
virtual void exitToOS()=0
virtual void changePassword()=0
virtual void showOpenURLDialog(const std::string &url)=0
virtual void signalKeyConfigChange()=0
virtual void disconnect()=0
virtual void changeVolume()=0
virtual void keyConfig()=0
Definition modalMenu.h:25
Definition mainmenumanager.h:95
bool keyconfig_changed
Definition mainmenumanager.h:140
bool keyconfig_requested
Definition mainmenumanager.h:138
MainGameCallback()=default
bool shutdown_requested
Definition mainmenumanager.h:139
std::string show_open_url_dialog
Definition mainmenumanager.h:141
bool disconnect_requested
Definition mainmenumanager.h:135
void changeVolume() override
Definition mainmenumanager.h:115
void showOpenURLDialog(const std::string &url) override
Definition mainmenumanager.h:130
virtual ~MainGameCallback()=default
void exitToOS() override
Definition mainmenumanager.h:100
void keyConfig() override
Definition mainmenumanager.h:120
bool changevolume_requested
Definition mainmenumanager.h:137
void disconnect() override
Definition mainmenumanager.h:105
bool changepassword_requested
Definition mainmenumanager.h:136
void changePassword() override
Definition mainmenumanager.h:110
void signalKeyConfigChange() override
Definition mainmenumanager.h:125
Definition mainmenumanager.h:32
virtual bool preprocessEvent(const SEvent &event)
Definition mainmenumanager.h:60
bool pausesGame()
Definition mainmenumanager.h:73
size_t menuCount() const
Definition mainmenumanager.h:68
virtual void createdMenu(gui::IGUIElement *menu)
Definition mainmenumanager.h:34
std::list< gui::IGUIElement * > m_stack
Definition mainmenumanager.h:84
virtual void deletingMenu(gui::IGUIElement *menu)
Definition mainmenumanager.h:48
MainMenuManager g_menumgr
Definition clientlauncher.cpp:36
gui::IGUIEnvironment * guienv
Definition clientlauncher.cpp:34
static bool isMenuActive()
Definition mainmenumanager.h:89
MainGameCallback * g_gamecallback
Definition clientlauncher.cpp:39
gui::IGUIStaticText * guiroot
Definition clientlauncher.cpp:35