Etterna 0.74.4
Loading...
Searching...
No Matches
ScreenMiniMenu.h
1/* ScreenMiniMenu - Displays a simple menu over the top of another screen. */
2
3#ifndef SCREEN_MINI_MENU_H
4#define SCREEN_MINI_MENU_H
5
6#include <utility>
7
8#include "Etterna/Screen/Options/ScreenOptions.h"
9#include "Etterna/Models/Misc/Foreach.h"
10
11using MenuRowUpdateEnabled = bool (*)();
12
14{
15 int iRowCode{ 0 };
16 std::string sName;
17 bool bEnabled{ false };
18 MenuRowUpdateEnabled pfnEnabled{}; // if ! NULL, used instead of bEnabled
19
20 int iDefaultChoice{ 0 };
21 std::vector<std::string> choices;
22 bool bThemeTitle{ false };
23 bool bThemeItems{ false };
24
26 : sName("")
27 , choices(){};
28 MenuRowDef(int r,
29 const std::string& n,
30 MenuRowUpdateEnabled pe,
31
32 bool bTT,
33 bool bTI,
34 int d,
35 const char* c0 = nullptr,
36 const char* c1 = nullptr,
37 const char* c2 = nullptr,
38 const char* c3 = nullptr,
39 const char* c4 = nullptr,
40 const char* c5 = nullptr,
41 const char* c6 = nullptr,
42 const char* c7 = nullptr,
43 const char* c8 = nullptr,
44 const char* c9 = nullptr,
45 const char* c10 = nullptr,
46 const char* c11 = nullptr,
47 const char* c12 = nullptr,
48 const char* c13 = nullptr,
49 const char* c14 = nullptr,
50 const char* c15 = nullptr,
51 const char* c16 = nullptr,
52 const char* c17 = nullptr,
53 const char* c18 = nullptr,
54 const char* c19 = nullptr,
55 const char* c20 = nullptr,
56 const char* c21 = nullptr,
57 const char* c22 = nullptr,
58 const char* c23 = nullptr,
59 const char* c24 = nullptr,
60 const char* c25 = nullptr)
61 : iRowCode(r)
62 , sName(n)
63 , bEnabled(true)
64 , pfnEnabled(pe)
65
66 , iDefaultChoice(d)
67 , choices()
68 , bThemeTitle(bTT)
69 , bThemeItems(bTI)
70 {
71#define PUSH(c) \
72 if (c) \
73 choices.push_back(c);
74 PUSH(c0);
75 PUSH(c1);
76 PUSH(c2);
77 PUSH(c3);
78 PUSH(c4);
79 PUSH(c5);
80 PUSH(c6);
81 PUSH(c7);
82 PUSH(c8);
83 PUSH(c9);
84 PUSH(c10);
85 PUSH(c11);
86 PUSH(c12);
87 PUSH(c13);
88 PUSH(c14);
89 PUSH(c15);
90 PUSH(c16);
91 PUSH(c17);
92 PUSH(c18);
93 PUSH(c19);
94 PUSH(c20);
95 PUSH(c21);
96 PUSH(c22);
97 PUSH(c22);
98 PUSH(c23);
99 PUSH(c23);
100 PUSH(c24);
101 PUSH(c25);
102#undef PUSH
103 }
104
105 MenuRowDef(int r,
106 const std::string& n,
107 bool e,
108
109 bool bTT,
110 bool bTI,
111 int d,
112 std::vector<std::string>& options)
113 : iRowCode(r)
114 , sName(n)
115 , bEnabled(e)
116 , pfnEnabled(nullptr)
117
118 , iDefaultChoice(d)
119 , choices()
120 , bThemeTitle(bTT)
121 , bThemeItems(bTI)
122 {
123 FOREACH(std::string, options, str)
124 {
125 if (*str != "")
126 choices.push_back(*str);
127 }
128 }
129
130 MenuRowDef(int r,
131 const std::string& n,
132 bool e,
133
134 bool bTT,
135 bool bTI,
136 int d,
137 const char* c0 = nullptr,
138 const char* c1 = nullptr,
139 const char* c2 = nullptr,
140 const char* c3 = nullptr,
141 const char* c4 = nullptr,
142 const char* c5 = nullptr,
143 const char* c6 = nullptr,
144 const char* c7 = nullptr,
145 const char* c8 = nullptr,
146 const char* c9 = nullptr,
147 const char* c10 = nullptr,
148 const char* c11 = nullptr,
149 const char* c12 = nullptr,
150 const char* c13 = nullptr,
151 const char* c14 = nullptr,
152 const char* c15 = nullptr,
153 const char* c16 = nullptr,
154 const char* c17 = nullptr,
155 const char* c18 = nullptr,
156 const char* c19 = nullptr,
157 const char* c20 = nullptr,
158 const char* c21 = nullptr,
159 const char* c22 = nullptr,
160 const char* c23 = nullptr,
161 const char* c24 = nullptr,
162 const char* c25 = nullptr)
163 : iRowCode(r)
164 , sName(n)
165 , bEnabled(e)
166 , pfnEnabled(nullptr)
167
168 , iDefaultChoice(d)
169 , choices()
170 , bThemeTitle(bTT)
171 , bThemeItems(bTI)
172 {
173#define PUSH(c) \
174 if (c) \
175 choices.push_back(c);
176 PUSH(c0);
177 PUSH(c1);
178 PUSH(c2);
179 PUSH(c3);
180 PUSH(c4);
181 PUSH(c5);
182 PUSH(c6);
183 PUSH(c7);
184 PUSH(c8);
185 PUSH(c9);
186 PUSH(c10);
187 PUSH(c11);
188 PUSH(c12);
189 PUSH(c13);
190 PUSH(c14);
191 PUSH(c15);
192 PUSH(c16);
193 PUSH(c17);
194 PUSH(c18);
195 PUSH(c19);
196 PUSH(c20);
197 PUSH(c21);
198 PUSH(c22);
199 PUSH(c22);
200 PUSH(c23);
201 PUSH(c23);
202 PUSH(c24);
203 PUSH(c25);
204#undef PUSH
205 }
206
207 MenuRowDef(int r,
208 const std::string& n,
209 bool e,
210
211 bool bTT,
212 bool bTI,
213 int d,
214 int low,
215 int high)
216 : iRowCode(r)
217 , sName(n)
218 , bEnabled(e)
219 , pfnEnabled(nullptr)
220
221 , iDefaultChoice(d)
222 , choices()
223 , bThemeTitle(bTT)
224 , bThemeItems(bTI)
225 {
226 for (int i = low; i <= high; i++) {
227 choices.push_back(IntToString(i).c_str());
228 }
229 }
230
231 void SetOneUnthemedChoice(const std::string& sChoice)
232 {
233 choices.resize(1);
234 choices[0] = "|" + sChoice;
235 }
236
237 bool SetDefaultChoiceIfPresent(const std::string& sChoice)
238 {
239 iDefaultChoice = 0;
240 FOREACH_CONST(std::string, choices, s)
241 {
242 if (sChoice == *s) {
243 iDefaultChoice = s - choices.begin();
244 return true;
245 }
246 }
247 return false;
248 }
249};
250
252{
253 std::string sClassName;
254 std::vector<MenuRowDef> rows;
255
256 MenuDef(std::string c,
257 const MenuRowDef& r0 = MenuRowDef(),
258 const MenuRowDef& r1 = MenuRowDef(),
259 const MenuRowDef& r2 = MenuRowDef(),
260 const MenuRowDef& r3 = MenuRowDef(),
261 const MenuRowDef& r4 = MenuRowDef(),
262 const MenuRowDef& r5 = MenuRowDef(),
263 const MenuRowDef& r6 = MenuRowDef(),
264 const MenuRowDef& r7 = MenuRowDef(),
265 const MenuRowDef& r8 = MenuRowDef(),
266 const MenuRowDef& r9 = MenuRowDef(),
267 const MenuRowDef& r10 = MenuRowDef(),
268 const MenuRowDef& r11 = MenuRowDef(),
269 const MenuRowDef& r12 = MenuRowDef(),
270 const MenuRowDef& r13 = MenuRowDef(),
271 const MenuRowDef& r14 = MenuRowDef(),
272 const MenuRowDef& r15 = MenuRowDef(),
273 const MenuRowDef& r16 = MenuRowDef(),
274 const MenuRowDef& r17 = MenuRowDef(),
275 const MenuRowDef& r18 = MenuRowDef(),
276 const MenuRowDef& r19 = MenuRowDef(),
277 const MenuRowDef& r20 = MenuRowDef(),
278 const MenuRowDef& r21 = MenuRowDef(),
279 const MenuRowDef& r22 = MenuRowDef(),
280 const MenuRowDef& r23 = MenuRowDef(),
281 const MenuRowDef& r24 = MenuRowDef(),
282 const MenuRowDef& r25 = MenuRowDef(),
283 const MenuRowDef& r26 = MenuRowDef(),
284 const MenuRowDef& r27 = MenuRowDef(),
285 const MenuRowDef& r28 = MenuRowDef(),
286 const MenuRowDef& r29 = MenuRowDef())
287 : sClassName(std::move(c))
288 , rows()
289 {
290#define PUSH(r) \
291 if (!r.sName.empty()) \
292 rows.push_back(r);
293 PUSH(r0);
294 PUSH(r1);
295 PUSH(r2);
296 PUSH(r3);
297 PUSH(r4);
298 PUSH(r5);
299 PUSH(r6);
300 PUSH(r7);
301 PUSH(r8);
302 PUSH(r9);
303 PUSH(r10);
304 PUSH(r11);
305 PUSH(r12);
306 PUSH(r13);
307 PUSH(r14);
308 PUSH(r15);
309 PUSH(r16);
310 PUSH(r17);
311 PUSH(r18);
312 PUSH(r19);
313 PUSH(r20);
314 PUSH(r21);
315 PUSH(r22);
316 PUSH(r23);
317 PUSH(r24);
318 PUSH(r25);
319 PUSH(r26);
320 PUSH(r27);
321 PUSH(r28);
322 PUSH(r29);
323#undef PUSH
324 }
325};
326
328{
329 public:
330 static void MiniMenu(const MenuDef* pDef,
331 ScreenMessage smSendOnOK,
332 ScreenMessage smSendOnCancel = SM_None,
333 float fX = 0,
334 float fY = 0);
335
336 void Init() override;
337 void BeginScreen() override;
338 void HandleScreenMessage(const ScreenMessage& SM) override;
339
340 protected:
341 void AfterChangeValueOrRow(PlayerNumber pn) override;
342 void ImportOptions(int iRow, const PlayerNumber& vpns) override;
343 void ExportOptions(int iRow, const PlayerNumber& vpns) override;
344 void ExportOptionsOnCancel(int iRow, const PlayerNumber& pn) override;
345
346 bool FocusedItemEndsScreen(PlayerNumber pn) const override;
347
348 void LoadMenu(const MenuDef* pDef);
349
350 ScreenMessage m_SMSendOnOK;
351 ScreenMessage m_SMSendOnCancel;
352
353 std::vector<MenuRowDef> m_vMenuRows;
354
355 public:
357 : m_SMSendOnOK()
358 , m_SMSendOnCancel()
359 , m_vMenuRows()
360 {
361 }
362
363 static bool s_bCancelled;
364 static int s_iLastRowCode;
365 static std::vector<int> s_viLastAnswers;
366};
367
368#endif
Definition ScreenMiniMenu.h:328
void BeginScreen() override
This is called immediately before the screen is used.
Definition ScreenMiniMenu.cpp:73
void Init() override
This is called immediately after construction, to allow initializing after all derived classes exist.
Definition ScreenMiniMenu.cpp:64
A grid of options; the selected option is drawn with a highlight rectangle.
Definition ScreenOptions.h:38
Definition ScreenMiniMenu.h:252
Definition ScreenMiniMenu.h:14