Etterna 0.74.4
Loading...
Searching...
No Matches
OptionRowHandler.h
1#ifndef OptionRowHandler_H
2#define OptionRowHandler_H
3
4#include "GameCommand.h"
5#include "Etterna/Models/Lua/LuaReference.h"
6
7#include <set>
8
9struct MenuRowDef;
10class OptionRow;
11struct ConfOption;
12
14enum SelectType
15{
16 SELECT_ONE,
17 SELECT_MULTIPLE,
18 SELECT_NONE,
19 NUM_SelectType,
20 SelectType_Invalid
21};
22const std::string&
23SelectTypeToString(SelectType x);
24SelectType
25StringToSelectType(const std::string& s);
26LuaDeclareType(SelectType);
28enum LayoutType
29{
30 LAYOUT_SHOW_ALL_IN_ROW,
31 LAYOUT_SHOW_ONE_IN_ROW,
32 NUM_LayoutType,
33 LayoutType_Invalid
34};
35const std::string&
36LayoutTypeToString(LayoutType x);
37LayoutType
38StringToLayoutType(const std::string& s);
39LuaDeclareType(LayoutType);
40
41enum ReloadChanged
42{
43 RELOAD_CHANGED_NONE,
44 RELOAD_CHANGED_ENABLED,
45 RELOAD_CHANGED_ALL,
46 NUM_ReloadChanged,
47 ReloadChanged_Invalid
48};
49const std::string&
50ReloadChangedToString(ReloadChanged x);
51ReloadChanged
52StringToReloadChanged(const std::string& s);
53LuaDeclareType(ReloadChanged);
54
57{
59 std::string m_sName;
61 std::string m_sExplanationName;
64 SelectType m_selectType{ SELECT_ONE };
65 LayoutType m_layoutType{ LAYOUT_SHOW_ALL_IN_ROW };
66 std::vector<std::string> m_vsChoices;
67 std::set<PlayerNumber> m_vEnabledForPlayers; // only players in this set may
68 // change focus to this row
69 int m_iDefault{ -1 };
70 bool m_bExportOnChange{ false };
71 bool m_bExportOnCancel{ false };
76 bool m_bAllowThemeItems{ true };
81 bool m_bAllowThemeTitle{ true };
89 bool m_bAllowExplanation{ true };
90 bool m_bShowChoicesListOnSelect{ false }; // (currently unused)
91
96 [[nodiscard]] bool IsEnabledForPlayer(PlayerNumber pn) const
97 {
98 return m_vEnabledForPlayers.find(pn) != m_vEnabledForPlayers.end();
99 }
100
102 : m_sName("")
104
105 {
106 m_vEnabledForPlayers.insert(PLAYER_1);
107 }
108 void Init()
109 {
110 m_sName = "";
113 m_selectType = SELECT_ONE;
114 m_layoutType = LAYOUT_SHOW_ALL_IN_ROW;
115 m_vsChoices.clear();
116 m_vEnabledForPlayers.clear();
117 m_vEnabledForPlayers.insert(PLAYER_1);
118 m_iDefault = -1;
119 m_bExportOnChange = false;
120 m_bExportOnCancel = false;
121 m_bAllowThemeItems = true;
122 m_bAllowThemeTitle = true;
123 m_bAllowExplanation = true;
124 m_bShowChoicesListOnSelect = false;
125 }
126
127 OptionRowDefinition(const char* n,
128 bool b,
129 const char* c0 = nullptr,
130 const char* c1 = nullptr,
131 const char* c2 = nullptr,
132 const char* c3 = nullptr,
133 const char* c4 = nullptr,
134 const char* c5 = nullptr,
135 const char* c6 = nullptr,
136 const char* c7 = nullptr,
137 const char* c8 = nullptr,
138 const char* c9 = nullptr,
139 const char* c10 = nullptr,
140 const char* c11 = nullptr,
141 const char* c12 = nullptr,
142 const char* c13 = nullptr,
143 const char* c14 = nullptr,
144 const char* c15 = nullptr,
145 const char* c16 = nullptr,
146 const char* c17 = nullptr,
147 const char* c18 = nullptr,
148 const char* c19 = nullptr)
149 : m_sName(n)
152
153 {
154 m_vEnabledForPlayers.insert(PLAYER_1);
155
156#define PUSH(c) \
157 if (c) \
158 m_vsChoices.push_back(c);
159 PUSH(c0);
160 PUSH(c1);
161 PUSH(c2);
162 PUSH(c3);
163 PUSH(c4);
164 PUSH(c5);
165 PUSH(c6);
166 PUSH(c7);
167 PUSH(c8);
168 PUSH(c9);
169 PUSH(c10);
170 PUSH(c11);
171 PUSH(c12);
172 PUSH(c13);
173 PUSH(c14);
174 PUSH(c15);
175 PUSH(c16);
176 PUSH(c17);
177 PUSH(c18);
178 PUSH(c19);
179#undef PUSH
180 }
181};
182
185{
186 public:
188 std::vector<std::string>
189 m_vsReloadRowMessages; // refresh this row on on these messages
190
191 OptionRowHandler() = default;
192 virtual ~OptionRowHandler() = default;
193 virtual void Init()
194 {
195 m_Def.Init();
196 m_vsReloadRowMessages.clear();
197 }
198 bool Load(const Commands& cmds)
199 {
200 Init();
201 return this->LoadInternal(cmds);
202 }
203
204 [[nodiscard]] std::string OptionTitle() const;
205 [[nodiscard]] std::string GetThemedItemText(int iChoice) const;
206
207 virtual bool LoadInternal(const Commands&) { return true; }
208
209 /* We may re-use OptionRowHandlers. This is called before each use. If the
210 * contents of the row are dependent on external state (for example, the
211 * current song), clear the row contents and reinitialize them. As an
212 * optimization, rows which do not change can be initialized just once and
213 * left alone.
214 * If the row has been reinitialized, return RELOAD_CHANGED_ALL, and the
215 * graphic elements will also be reinitialized. If only m_vEnabledForPlayers
216 * has been changed, return RELOAD_CHANGED_ENABLED. If the row is static,
217 * and nothing has changed, return RELOAD_CHANGED_NONE. */
218 virtual ReloadChanged Reload() { return RELOAD_CHANGED_NONE; }
219
220 [[nodiscard]] virtual int GetDefaultOption() const { return -1; }
221 virtual void ImportOption(OptionRow*,
222 const PlayerNumber&,
223 std::vector<bool>& vbSelectedOut) const
224 {
225 }
226 // Returns an OPT mask.
227 [[nodiscard]] virtual int ExportOption(const PlayerNumber&,
228 const std::vector<bool>& vbSelected) const
229 {
230 return 0;
231 }
232 virtual void GetIconTextAndGameCommand(int iFirstSelection,
233 std::string& sIconTextOut,
234 GameCommand& gcOut) const;
235
236 [[nodiscard]] virtual std::string GetScreen(int /* iChoice */) const
237 {
238 return std::string();
239 }
240 // Exists so that a lua function can act on the selection. Returns true if
241 // the choices should be reloaded.
242 virtual bool NotifyOfSelection(PlayerNumber pn, int choice)
243 {
244 return false;
245 }
246 virtual bool GoToFirstOnStart() { return true; }
247};
248
252Make(const Commands& cmds);
254MakeNull();
256MakeSimple(const MenuRowDef& mrd);
257
258void
259SelectExactlyOne(int iSelection, std::vector<bool>& vbSelectedOut);
260int
261GetOneSelection(const std::vector<bool>& vbSelected);
262}
263
264inline void
265VerifySelected(SelectType st, std::vector<bool>& selected, const std::string& sName)
266{
267 auto num_selected = 0;
268 if (st == SELECT_ONE) {
269 auto first_selected = -1;
270 if (selected.empty()) {
271 LuaHelpers::ReportScriptErrorFmt(
272 "Option row %s requires only one "
273 "thing to be selected, but the list of selected things has zero "
274 "elements.",
275 sName.c_str());
276 return;
277 }
278 for (unsigned int e = 0; e < selected.size(); ++e) {
279 if (selected[e]) {
280 num_selected++;
281 if (first_selected == -1) {
282 first_selected = static_cast<int>(e);
283 }
284 }
285 }
286 if (num_selected != 1) {
287 LuaHelpers::ReportScriptErrorFmt(
288 "Option row %s requires only one "
289 "thing to be selected, but %i out of %i things are selected.",
290 sName.c_str(),
291 num_selected,
292 static_cast<int>(selected.size()));
293 for (unsigned int e = 0; e < selected.size(); ++e) {
294 if (selected[e] && e != first_selected) {
295 selected[e] = false;
296 }
297 }
298 if (num_selected == 0) {
299 selected[0] = true;
300 }
301 return;
302 }
303 }
304}
305
306#endif
Definition Command.h:38
Definition GameCommand.h:20
Shows PlayerOptions and SongOptions in icon form.
Definition OptionRowHandler.h:185
Definition OptionRow.h:56
Utilities for the OptionRowHandlers.
Definition OptionRowHandler.h:250
Definition ScreenOptionsMasterPrefs.h:26
Definition ScreenMiniMenu.h:14
Define the purpose of the OptionRow.
Definition OptionRowHandler.h:57
std::string m_sName
the name of the option row.
Definition OptionRowHandler.h:59
bool m_bAllowThemeItems
Are theme items allowed here?
Definition OptionRowHandler.h:76
bool IsEnabledForPlayer(PlayerNumber pn) const
Is this option enabled for the Player?
Definition OptionRowHandler.h:96
bool m_bOneChoiceForAllPlayers
Do all players have to share one option from the row?
Definition OptionRowHandler.h:63
std::string m_sExplanationName
an explanation of the row's purpose.
Definition OptionRowHandler.h:61
bool m_bAllowThemeTitle
Are theme titles allowed here?
Definition OptionRowHandler.h:81
bool m_bAllowExplanation
Are explanations allowed for this row?
Definition OptionRowHandler.h:89