Etterna 0.74.4
Loading...
Searching...
No Matches
Screen.h
1#ifndef SCREEN_H
2#define SCREEN_H
3
4#include "Etterna/Actor/Base/ActorFrame.h"
5#include "Etterna/Models/Misc/CodeSet.h"
6#include "Etterna/Models/Misc/EnumHelper.h"
7#include "ScreenMessage.h"
8#include "Etterna/Models/Misc/ThemeMetric.h"
9
10#include <functional>
11#include <list>
12
13class InputEventPlus;
14class Screen;
15using CreateScreenFn = Screen* (*)(const std::string&);
16
23{
24 RegisterScreenClass(const std::string& sClassName, CreateScreenFn pfn);
25};
26
27#define REGISTER_SCREEN_CLASS(className) \
28 static Screen* Create##className(const std::string& sName) \
29 { \
30 LuaThreadVariable var("LoadingScreen", sName); \
31 Screen* pRet = new className; \
32 pRet->SetName(sName); \
33 Screen::InitScreen(pRet); \
34 return pRet; \
35 } \
36 static RegisterScreenClass register_##className(#className, \
37 Create##className)
38
40enum ScreenType
41{
42 attract,
44 game_menu,
47 gameplay,
49 evaluation,
50 system_menu,
53 NUM_ScreenType,
55 ScreenType_Invalid
56};
57
58const std::string&
59ScreenTypeToString(ScreenType st);
60LuaDeclareType(ScreenType);
61
63class Screen : public ActorFrame
64{
65 public:
66 static void InitScreen(Screen* pScreen);
67
68 ~Screen() override;
69
75 virtual void Init();
76
78 virtual void BeginScreen();
79
81 virtual void EndScreen();
82
83 void Update(float fDeltaTime) override;
84 virtual void UpdateTimedFunctions(float fDeltaTime);
85 virtual bool Input(const InputEventPlus& input);
86 virtual void HandleScreenMessage(const ScreenMessage& SM);
87 void SetLockInputSecs(const float f) { m_fLockInputSecs = f; }
88
93 void PostScreenMessage(const ScreenMessage& SM, float fDelay);
95 void ClearMessageQueue();
99 void ClearMessageQueue(const ScreenMessage& SM);
100
101 virtual ScreenType GetScreenType() const
102 {
103 return ALLOW_OPERATOR_MENU_BUTTON ? game_menu : system_menu;
104 }
105
106 bool AllowOperatorMenuButton() const { return ALLOW_OPERATOR_MENU_BUTTON; }
107
112 virtual bool AllowLateJoin() const { return false; }
113
114 // Lua
115 void PushSelf(lua_State* L) override;
116
117 std::vector<std::pair<std::function<void()>, float>> delayedFunctions;
118 void SetTimeout(const std::function<void()>& f, float ms);
119 std::list<std::tuple<std::function<void()>, float, float, int>>
120 delayedPeriodicFunctions; // This is a list to allow safe iterators
121 std::vector<int> delayedPeriodicFunctionIdsToDelete;
122 void SetInterval(const std::function<void()>& f, float ms, int fRemove);
123
124 bool b_PreviewNoteFieldIsActive = false;
125
126 protected:
129 {
131 ScreenMessage SM;
134 };
135
137 std::vector<QueuedScreenMessage> m_QueuedMessages;
138 static bool SortMessagesByDelayRemaining(const QueuedScreenMessage& m1,
139 const QueuedScreenMessage& m2);
140
141 InputQueueCodeSet m_Codes;
142
147 ThemeMetric<float> REPEAT_RATE;
148 ThemeMetric<float> REPEAT_DELAY;
149
154 std::string m_sNextScreen;
155 std::string m_sPrevScreen;
156 ScreenMessage m_smSendOnPop;
157
158 float m_fLockInputSecs = 0.F;
159
160 // If currently between BeginScreen/EndScreen calls:
161 bool m_bRunning = false;
162
163 public:
164 std::string GetNextScreenName() const;
165 std::string GetPrevScreen() const;
166 void SetNextScreenName(std::string const& name);
167 void SetPrevScreenName(std::string const& name);
168
169 bool PassInputToLua(const InputEventPlus& input);
170 void AddInputCallbackFromStack(lua_State* L);
171 void RemoveInputCallback(lua_State* L);
172 virtual bool AllowCallbackInput() { return true; }
173
174 // let subclass override if they want
175 virtual bool MenuUp(const InputEventPlus&) { return false; }
176 virtual bool MenuDown(const InputEventPlus&) { return false; }
177 virtual bool MenuLeft(const InputEventPlus&) { return false; }
178 virtual bool MenuRight(const InputEventPlus&) { return false; }
179 virtual bool MenuStart(const InputEventPlus&) { return false; }
180 virtual bool MenuSelect(const InputEventPlus&) { return false; }
181 virtual bool MenuBack(const InputEventPlus&) { return false; }
182 virtual bool MenuCoin(const InputEventPlus&) { return false; }
183
184 private:
185 // void* is the key so that we can use lua_topointer to find the callback
186 // to remove when removing a callback.
187 using callback_key_t = const void*;
188 std::map<callback_key_t, LuaReference> m_InputCallbacks;
189 std::vector<callback_key_t> orderedcallbacks;
190 std::vector<callback_key_t> m_DelayedCallbackRemovals;
191 bool m_CallingInputCallbacks = false;
192 void InternalRemoveCallback(callback_key_t key);
193};
194
195#endif
A container for other Actors.
Definition ActorFrame.h:8
Holds a device input plus Game/Menu translations.
Definition InputEventPlus.h:9
Definition CodeSet.h:8
Class that holds a screen-full of Actors.
Definition Screen.h:64
void PostScreenMessage(const ScreenMessage &SM, float fDelay)
Put the specified message onto the screen for a specified time.
Definition Screen.cpp:367
virtual void EndScreen()
This is called when the screen is popped.
Definition Screen.cpp:128
virtual void Init()
This is called immediately after construction, to allow initializing after all derived classes exist.
Definition Screen.cpp:60
std::string m_sNextScreen
The next screen to go to once this screen is done.
Definition Screen.h:154
void ClearMessageQueue()
Clear the entire message queue.
Definition Screen.cpp:378
virtual bool AllowLateJoin() const
Determine if we allow extra players to join in on this screen.
Definition Screen.h:112
virtual void BeginScreen()
This is called immediately before the screen is used.
Definition Screen.cpp:105
ThemeMetric< bool > ALLOW_OPERATOR_MENU_BUTTON
Do we allow the operator menu button to be pressed here?
Definition Screen.h:144
std::vector< QueuedScreenMessage > m_QueuedMessages
The list of messages that are sent to a Screen.
Definition Screen.h:137
ThemeMetric< bool > HANDLE_BACK_BUTTON
Do we handle the back button being pressed here?
Definition Screen.h:146
The theme specific data.
Definition ThemeMetric.h:52
Allow registering the screen for easier access.
Definition Screen.h:23
Holds the messages sent to a Screen.
Definition Screen.h:129
ScreenMessage SM
The message being held.
Definition Screen.h:131
float fDelayRemaining
How long the message is up.
Definition Screen.h:133