forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionRowHandler.h
275 lines (259 loc) · 9.51 KB
/
OptionRowHandler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#ifndef OptionRowHandler_H
#define OptionRowHandler_H
#include "GameCommand.h"
#include "LuaReference.h"
#include "RageUtil.h"
#include <set>
struct MenuRowDef;
class OptionRow;
struct ConfOption;
/** @brief How many options can be selected on this row? */
enum SelectType
{
SELECT_ONE, /**< Only one option can be chosen on this row. */
SELECT_MULTIPLE, /**< Multiple options can be chosen on this row. */
SELECT_NONE, /**< No options can be chosen on this row. */
NUM_SelectType,
SelectType_Invalid
};
std::string const SelectTypeToString( SelectType pm );
SelectType StringToSelectType( const std::string& s );
LuaDeclareType( SelectType );
/** @brief How many items are shown on the row? */
enum LayoutType
{
LAYOUT_SHOW_ALL_IN_ROW, /**< All of the options are shown at once. */
LAYOUT_SHOW_ONE_IN_ROW, /**< Only one option is shown at a time. */
NUM_LayoutType,
LayoutType_Invalid
};
std::string const LayoutTypeToString( LayoutType pm );
LayoutType StringToLayoutType( const std::string& s );
LuaDeclareType( LayoutType );
enum ReloadChanged
{
RELOAD_CHANGED_NONE, RELOAD_CHANGED_ENABLED, RELOAD_CHANGED_ALL, NUM_ReloadChanged, ReloadChanged_Invalid
};
std::string const ReloadChangedToString( ReloadChanged rc );
ReloadChanged StringToReloadChanged( const std::string& rc );
LuaDeclareType( ReloadChanged );
/** @brief Define the purpose of the OptionRow. */
struct OptionRowDefinition
{
/** @brief the name of the option row. */
std::string m_sName;
/** @brief an explanation of the row's purpose. */
std::string m_sExplanationName;
/** @brief Do all players have to share one option from the row? */
bool m_bOneChoiceForAllPlayers;
SelectType m_selectType;
LayoutType m_layoutType;
std::vector<std::string> m_vsChoices;
std::set<PlayerNumber> m_vEnabledForPlayers; // only players in this set may change focus to this row
int m_iDefault;
bool m_bExportOnChange;
/**
* @brief Are theme items allowed here?
*
* This should be true for dynamic strings. */
bool m_bAllowThemeItems;
/**
* @brief Are theme titles allowed here?
*
* This should be true for dynamic strings. */
bool m_bAllowThemeTitle;
/**
* @brief Are explanations allowed for this row?
*
* If this is false, it will ignore the ScreenOptions::SHOW_EXPLANATIONS metric.
*
* This should be true for dynamic strings. */
bool m_bAllowExplanation;
bool m_bShowChoicesListOnSelect; // (currently unused)
/**
* @brief Is this option enabled for the Player?
* @param pn the Player the PlayerNumber represents.
* @return true if the option is enabled, false otherwise. */
bool IsEnabledForPlayer( PlayerNumber pn ) const
{
return m_vEnabledForPlayers.find(pn) != m_vEnabledForPlayers.end();
}
OptionRowDefinition(): m_sName(""), m_sExplanationName(""),
m_bOneChoiceForAllPlayers(false), m_selectType(SELECT_ONE),
m_layoutType(LAYOUT_SHOW_ALL_IN_ROW), m_vsChoices(),
m_vEnabledForPlayers(), m_iDefault(-1),
m_bExportOnChange(false), m_bAllowThemeItems(true),
m_bAllowThemeTitle(true), m_bAllowExplanation(true),
m_bShowChoicesListOnSelect(false)
{
FOREACH_PlayerNumber( pn )
m_vEnabledForPlayers.insert( pn );
}
void Init()
{
m_sName = "";
m_sExplanationName = "";
m_bOneChoiceForAllPlayers = false;
m_selectType = SELECT_ONE;
m_layoutType = LAYOUT_SHOW_ALL_IN_ROW;
m_vsChoices.clear();
m_vEnabledForPlayers.clear();
FOREACH_PlayerNumber( pn )
m_vEnabledForPlayers.insert( pn );
m_iDefault = -1;
m_bExportOnChange = false;
m_bAllowThemeItems = true;
m_bAllowThemeTitle = true;
m_bAllowExplanation = true;
m_bShowChoicesListOnSelect = false;
}
OptionRowDefinition( const char *n, bool b, const char *c0=nullptr,
const char *c1=nullptr, const char *c2=nullptr,
const char *c3=nullptr, const char *c4=nullptr,
const char *c5=nullptr, const char *c6=nullptr,
const char *c7=nullptr, const char *c8=nullptr,
const char *c9=nullptr, const char *c10=nullptr,
const char *c11=nullptr, const char *c12=nullptr,
const char *c13=nullptr, const char *c14=nullptr,
const char *c15=nullptr, const char *c16=nullptr,
const char *c17=nullptr, const char *c18=nullptr,
const char *c19=nullptr ): m_sName(n),
m_sExplanationName(""), m_bOneChoiceForAllPlayers(b),
m_selectType(SELECT_ONE),
m_layoutType(LAYOUT_SHOW_ALL_IN_ROW), m_vsChoices(),
m_vEnabledForPlayers(), m_iDefault(-1),
m_bExportOnChange(false), m_bAllowThemeItems(true),
m_bAllowThemeTitle(true), m_bAllowExplanation(true),
m_bShowChoicesListOnSelect(false)
{
FOREACH_PlayerNumber( pn )
m_vEnabledForPlayers.insert( pn );
#define PUSH( c ) if(c) m_vsChoices.push_back(c);
PUSH(c0);PUSH(c1);PUSH(c2);PUSH(c3);PUSH(c4);PUSH(c5);
PUSH(c6);PUSH(c7);PUSH(c8);PUSH(c9);PUSH(c10);PUSH(c11);
PUSH(c12);PUSH(c13);PUSH(c14);PUSH(c15);PUSH(c16);PUSH(c17);
PUSH(c18);PUSH(c19);
#undef PUSH
}
};
/** @brief Shows PlayerOptions and SongOptions in icon form. */
class OptionRowHandler
{
public:
OptionRowDefinition m_Def;
std::vector<std::string> m_vsReloadRowMessages; // refresh this row on on these messages
OptionRowHandler(): m_Def(), m_vsReloadRowMessages() { }
virtual ~OptionRowHandler() { }
virtual void Init()
{
m_Def.Init();
m_vsReloadRowMessages.clear();
}
bool Load( const Commands &cmds )
{
Init();
return this->LoadInternal( cmds );
}
std::string OptionTitle() const;
std::string GetThemedItemText( int iChoice ) const;
virtual bool LoadInternal( const Commands & ) { return true; }
/* We may re-use OptionRowHandlers. This is called before each use. If the
* contents of the row are dependent on external state (for example, the
* current song), clear the row contents and reinitialize them. As an
* optimization, rows which do not change can be initialized just once and
* left alone.
* If the row has been reinitialized, return RELOAD_CHANGED_ALL, and the
* graphic elements will also be reinitialized. If only m_vEnabledForPlayers
* has been changed, return RELOAD_CHANGED_ENABLED. If the row is static, and
* nothing has changed, return RELOAD_CHANGED_NONE. */
virtual ReloadChanged Reload() { return RELOAD_CHANGED_NONE; }
virtual int GetDefaultOption() const { return -1; }
virtual void ImportOption( OptionRow *, const std::vector<PlayerNumber> &, std::vector<bool> [NUM_PLAYERS] ) const { }
// Returns an OPT mask.
virtual int ExportOption( const std::vector<PlayerNumber> &, const std::vector<bool> [NUM_PLAYERS] ) const { return 0; }
virtual void GetIconTextAndGameCommand( int iFirstSelection, std::string &sIconTextOut, GameCommand &gcOut ) const;
virtual std::string GetScreen( int /* iChoice */ ) const { return std::string(); }
// Exists so that a lua function can act on the selection. Returns true if the choices should be reloaded.
virtual bool NotifyOfSelection(PlayerNumber, int) { return false; }
virtual bool GoToFirstOnStart() { return true; }
};
/** @brief Utilities for the OptionRowHandlers. */
namespace OptionRowHandlerUtil
{
OptionRowHandler* Make( const Commands &cmds );
OptionRowHandler* MakeNull();
OptionRowHandler* MakeSimple( const MenuRowDef &mrd );
void SelectExactlyOne( int iSelection, std::vector<bool> &vbSelectedOut );
int GetOneSelection( const std::vector<bool> &vbSelected );
}
inline void VerifySelected(SelectType st, std::vector<bool> &selected, const std::string &sName)
{
int num_selected = 0;
if( st == SELECT_ONE )
{
int first_selected= -1;
if(selected.empty())
{
LuaHelpers::ReportScriptErrorFmt("Option row %s requires only one "
"thing to be selected, but the list of selected things has zero "
"elements.", sName.c_str());
return;
}
for(unsigned int e= 0; e < selected.size(); ++e)
{
if(selected[e])
{
num_selected++;
if(first_selected == -1)
{
first_selected= static_cast<int>(e);
}
}
}
if(num_selected != 1)
{
LuaHelpers::ReportScriptErrorFmt("Option row %s requires only one "
"thing to be selected, but %i out of %i things are selected.",
sName.c_str(), num_selected, static_cast<int>(selected.size()));
for(unsigned int e= 0; e < selected.size(); ++e)
{
if(selected[e] && e != static_cast<unsigned int>(first_selected))
{
selected[e]= false;
}
}
if(num_selected == 0)
{
selected[0]= true;
}
return;
}
}
}
#endif
/**
* @file
* @author Chris Danford (c) 2002-2004
* @section LICENSE
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/