Luanti 5.11.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 virtual void touchscreenLayout() = 0;
25};
26
27extern gui::IGUIEnvironment *guienv;
28extern gui::IGUIStaticText *guiroot;
29
30// Handler for the modal menus
31
33{
34public:
35 virtual void createdMenu(gui::IGUIElement *menu)
36 {
37 for (gui::IGUIElement *e : m_stack) {
38 if (e == menu)
39 return;
40 }
41
42 if(!m_stack.empty())
43 m_stack.back()->setVisible(false);
44
45 m_stack.push_back(menu);
46 guienv->setFocus(m_stack.back());
47 }
48
49 virtual void deletingMenu(gui::IGUIElement *menu)
50 {
51 // Remove all entries if there are duplicates
52 m_stack.remove(menu);
53
54 if(!m_stack.empty()) {
55 m_stack.back()->setVisible(true);
56 guienv->setFocus(m_stack.back());
57 }
58 }
59
60 // Returns true to prevent further processing
61 virtual bool preprocessEvent(const SEvent& event)
62 {
63 if (m_stack.empty())
64 return false;
65 GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(m_stack.back());
66 return mm && mm->preprocessEvent(event);
67 }
68
69 size_t menuCount() const
70 {
71 return m_stack.size();
72 }
73
75 {
76 m_stack.front()->setVisible(false);
77 deletingMenu(m_stack.front());
78 }
79
81 {
82 for (gui::IGUIElement *i : m_stack) {
83 GUIModalMenu *mm = dynamic_cast<GUIModalMenu*>(i);
84 if (mm && mm->pausesGame())
85 return true;
86 }
87 return false;
88 }
89
90private:
91 std::list<gui::IGUIElement*> m_stack;
92};
93
95
96static inline bool isMenuActive()
97{
98 return g_menumgr.menuCount() != 0;
99}
100
102{
103public:
104 MainGameCallback() = default;
105 virtual ~MainGameCallback() = default;
106
107 void exitToOS() override
108 {
109 shutdown_requested = true;
110 }
111
112 void disconnect() override
113 {
115 }
116
117 void changePassword() override
118 {
120 }
121
122 void changeVolume() override
123 {
125 }
126
127 void keyConfig() override
128 {
129 keyconfig_requested = true;
130 }
131
132 void signalKeyConfigChange() override
133 {
134 keyconfig_changed = true;
135 }
136
137 void touchscreenLayout() override
138 {
140 }
141
142 void showOpenURLDialog(const std::string &url) override
143 {
145 }
146
152 bool shutdown_requested = false;
153 bool keyconfig_changed = false;
154 std::string show_open_url_dialog = "";
155};
156
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 touchscreenLayout()=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:102
bool keyconfig_changed
Definition mainmenumanager.h:153
bool touchscreenlayout_requested
Definition mainmenumanager.h:151
bool keyconfig_requested
Definition mainmenumanager.h:150
MainGameCallback()=default
bool shutdown_requested
Definition mainmenumanager.h:152
void touchscreenLayout() override
Definition mainmenumanager.h:137
std::string show_open_url_dialog
Definition mainmenumanager.h:154
bool disconnect_requested
Definition mainmenumanager.h:147
void changeVolume() override
Definition mainmenumanager.h:122
void showOpenURLDialog(const std::string &url) override
Definition mainmenumanager.h:142
virtual ~MainGameCallback()=default
void exitToOS() override
Definition mainmenumanager.h:107
void keyConfig() override
Definition mainmenumanager.h:127
bool changevolume_requested
Definition mainmenumanager.h:149
void disconnect() override
Definition mainmenumanager.h:112
bool changepassword_requested
Definition mainmenumanager.h:148
void changePassword() override
Definition mainmenumanager.h:117
void signalKeyConfigChange() override
Definition mainmenumanager.h:132
Definition mainmenumanager.h:33
virtual bool preprocessEvent(const SEvent &event)
Definition mainmenumanager.h:61
void deleteFront()
Definition mainmenumanager.h:74
bool pausesGame()
Definition mainmenumanager.h:80
size_t menuCount() const
Definition mainmenumanager.h:69
virtual void createdMenu(gui::IGUIElement *menu)
Definition mainmenumanager.h:35
std::list< gui::IGUIElement * > m_stack
Definition mainmenumanager.h:91
virtual void deletingMenu(gui::IGUIElement *menu)
Definition mainmenumanager.h:49
MainMenuManager g_menumgr
Definition clientlauncher.cpp:36
gui::IGUIEnvironment * guienv
Definition clientlauncher.cpp:34
static bool isMenuActive()
Definition mainmenumanager.h:96
MainGameCallback * g_gamecallback
Definition clientlauncher.cpp:39
gui::IGUIStaticText * guiroot
Definition clientlauncher.cpp:35