forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStepsDisplay.cpp
361 lines (321 loc) · 10.6 KB
/
StepsDisplay.cpp
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include "global.h"
#include "StepsDisplay.h"
#include "RageUtil.h"
#include "GameConstantsAndTypes.h"
#include "GameState.h"
#include "ThemeManager.h"
#include "Steps.h"
#include "Course.h"
#include "SongManager.h"
#include "ActorUtil.h"
#include "Style.h"
#include "XmlFile.h"
#include "LuaBinding.h"
#include "GameManager.h"
#include "PlayerState.h"
#include "RageLog.h"
#include "RageFmtWrap.h"
REGISTER_ACTOR_CLASS( StepsDisplay );
StepsDisplay::StepsDisplay()
{
}
/* sID experiment:
*
* Names of an actor, "Foo":
* [Foo]
* Metric=abc
*
* [ScreenSomething]
* FooP1X=20
* FooP2Y=30
*
* Graphics\Foo under p1
*
* We want to call it different things in different contexts: we may only want one
* set of internal metrics for a given use, but separate metrics for each player at
* the screen level, and we may or may not want separate names at the asset level.
*
* As is, we tend to end up having to either duplicate [Foo] to [FooP1] and [FooP2]
* or not use m_sName for [Foo], which limits its use. Let's try using a separate
* name for internal metrics. I'm not sure if this will cause more confusion than good,
* so I'm trying it first in only this object.
*/
void StepsDisplay::Load( const std::string &sMetricsGroup, const PlayerState *pPlayerState )
{
m_sMetricsGroup = sMetricsGroup;
/* We can't use global ThemeMetric<std::string>s, because we can have multiple
* StepsDisplays on screen at once, with different names. */
m_iNumTicks.Load(m_sMetricsGroup,"NumTicks");
m_iMaxTicks.Load(m_sMetricsGroup,"MaxTicks");
m_bShowTicks.Load(m_sMetricsGroup,"ShowTicks");
m_bShowMeter.Load(m_sMetricsGroup,"ShowMeter");
m_bShowDescription.Load(m_sMetricsGroup,"ShowDescription");
m_bShowCredit.Load(m_sMetricsGroup,"ShowCredit");
m_bShowAutogen.Load(m_sMetricsGroup,"ShowAutogen");
m_bShowStepsType.Load(m_sMetricsGroup,"ShowStepsType");
m_sZeroMeterString.Load(m_sMetricsGroup,"ZeroMeterString");
m_sMeterFormatString.Load(m_sMetricsGroup,"MeterFormatString");
m_sprFrame.Load( THEME->GetPathG(m_sMetricsGroup,"frame") );
m_sprFrame->SetName( "Frame" );
ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_sprFrame, m_sMetricsGroup );
this->AddChild( m_sprFrame );
if( m_bShowTicks )
{
std::string sChars = "10"; // on, off (todo: make this metricable -aj)
m_textTicks.SetName( "Ticks" );
m_textTicks.LoadFromTextureAndChars( THEME->GetPathF(m_sMetricsGroup,"ticks"), sChars );
ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_textTicks, m_sMetricsGroup );
this->AddChild( &m_textTicks );
}
if( m_bShowMeter )
{
m_textMeter.SetName( "Meter" );
m_textMeter.LoadFromFont( THEME->GetPathF(m_sMetricsGroup,"meter") );
ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_textMeter, m_sMetricsGroup );
this->AddChild( &m_textMeter );
// These commands should have been loaded by SetXYAndOnCommand above.
ASSERT( m_textMeter.HasCommand("Set") );
}
if( m_bShowDescription )
{
m_textDescription.SetName( "Description" );
m_textDescription.LoadFromFont( THEME->GetPathF(m_sMetricsGroup,"Description") );
ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_textDescription, m_sMetricsGroup );
this->AddChild( &m_textDescription );
}
if( m_bShowCredit )
{
m_textAuthor.SetName( "Step Author" );
m_textAuthor.LoadFromFont( THEME->GetPathF(m_sMetricsGroup,"Credit") );
ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_textAuthor, m_sMetricsGroup );
this->AddChild( &m_textAuthor );
}
if( m_bShowAutogen )
{
m_sprAutogen.Load( THEME->GetPathG(m_sMetricsGroup,"Autogen") );
m_sprAutogen->SetName( "Autogen" );
ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_sprAutogen, m_sMetricsGroup );
this->AddChild( m_sprAutogen );
}
if( m_bShowStepsType )
{
m_sprStepsType.Load( THEME->GetPathG(m_sMetricsGroup,"StepsType") );
m_sprStepsType->SetName( "StepsType" );
ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( m_sprStepsType, m_sMetricsGroup );
this->AddChild( m_sprStepsType );
}
// Play Load Command
PlayerState* pPlayerState_ = const_cast<PlayerState*>(pPlayerState);
Message msg("Load");
if( pPlayerState_ )
msg.SetParam( "PlayerState", LuaReference::CreateFromPush(*pPlayerState_) );
this->HandleMessage( msg );
Unset();
}
void StepsDisplay::SetFromGameState( PlayerNumber pn )
{
if( GAMESTATE->IsCourseMode() )
{
// figure out what course type is selected somehow.
const Trail* pTrail = GAMESTATE->m_pCurTrail[pn];
if( pTrail )
SetFromTrail( pTrail );
else
SetFromStepsTypeAndMeterAndDifficultyAndCourseType( StepsType_Invalid, 0, GAMESTATE->m_PreferredCourseDifficulty[pn], CourseType_Invalid );
}
else
{
const Steps* pSteps = GAMESTATE->m_pCurSteps[pn];
if( pSteps )
SetFromSteps( pSteps );
else
SetFromStepsTypeAndMeterAndDifficultyAndCourseType( StepsType_Invalid, 0, GAMESTATE->m_PreferredDifficulty[pn], CourseType_Invalid );
}
}
void StepsDisplay::SetFromSteps( const Steps* pSteps )
{
if( pSteps == nullptr )
{
Unset();
return;
}
SetParams params = { pSteps, nullptr, pSteps->GetMeter(), pSteps->m_StepsType, pSteps->GetDifficulty(), CourseType_Invalid };
SetInternal( params );
}
void StepsDisplay::SetFromTrail( const Trail* pTrail )
{
if( pTrail == nullptr )
{
Unset();
return;
}
SetParams params = { nullptr, pTrail, pTrail->GetMeter(), pTrail->m_StepsType, pTrail->m_CourseDifficulty, pTrail->m_CourseType };
SetInternal( params );
}
void StepsDisplay::Unset()
{
this->SetVisible( false );
}
void StepsDisplay::SetFromStepsTypeAndMeterAndDifficultyAndCourseType( StepsType st, int iMeter, Difficulty dc, CourseType ct )
{
SetParams params = { nullptr, nullptr, iMeter, st, dc, ct };
SetInternal( params );
}
void StepsDisplay::SetInternal( const SetParams ¶ms )
{
this->SetVisible( true );
Message msg( "Set" );
std::string sCustomDifficulty;
if( params.pSteps )
sCustomDifficulty = StepsToCustomDifficulty(params.pSteps);
else if( params.pTrail )
sCustomDifficulty = TrailToCustomDifficulty(params.pTrail);
else
sCustomDifficulty = GetCustomDifficulty( params.st, params.dc, params.ct );
msg.SetParam( "CustomDifficulty", sCustomDifficulty );
std::string sDisplayDescription;
if( params.pSteps && params.pSteps->IsAnEdit() )
sDisplayDescription = params.pSteps->GetDescription();
else if( sCustomDifficulty.empty() )
sDisplayDescription = std::string();
else
sDisplayDescription = CustomDifficultyToLocalizedString( sCustomDifficulty );
msg.SetParam( "DisplayDescription", sDisplayDescription );
std::string sDisplayCredit;
if( params.pSteps )
sDisplayCredit = params.pSteps->GetCredit();
if( params.pSteps )
msg.SetParam( "Steps", LuaReference::CreateFromPush(*(Steps*)params.pSteps) );
if( params.pTrail )
msg.SetParam( "Trail", LuaReference::CreateFromPush(*(Trail*)params.pTrail) );
msg.SetParam( "Meter", params.iMeter );
msg.SetParam( "StepsType", params.st );
m_sprFrame->HandleMessage( msg );
if( m_bShowTicks )
{
// todo: let themers handle the logic of tick text. -aj
char on = char('1');
char off = '0';
std::string sNewText;
int iNumOn = std::min( m_iMaxTicks.GetValue(), params.iMeter );
sNewText.insert( sNewText.end(), iNumOn, on );
int iNumOff = std::max( 0, m_iNumTicks.GetValue() - iNumOn );
sNewText.insert( sNewText.end(), iNumOff, off );
m_textTicks.SetText( sNewText );
m_textTicks.HandleMessage( msg );
}
if( m_bShowMeter )
{
if( params.iMeter == 0 ) // Unset calls with this
{
m_textMeter.SetText( m_sZeroMeterString.GetValue() );
}
else
{
const std::string sMeter = rage_fmt_wrapper(m_sMeterFormatString, params.iMeter);
m_textMeter.SetText( sMeter );
m_textMeter.HandleMessage( msg );
}
}
if( m_bShowDescription )
{
m_textDescription.SetText( sDisplayDescription );
m_textDescription.HandleMessage( msg );
}
if( m_bShowCredit )
{
m_textAuthor.SetText( sDisplayCredit );
m_textAuthor.HandleMessage( msg );
}
if( m_bShowAutogen )
{
bool b = params.pSteps && params.pSteps->IsAutogen();
m_sprAutogen->HandleMessage( msg );
m_sprAutogen->SetVisible( b );
}
if( m_bShowStepsType )
{
if( params.st != StepsType_Invalid )
{
/*
std::string sStepsType = GAMEMAN->GetStepsTypeInfo(params.st).szName;
m_sprStepsType.Load( THEME->GetPathG(m_sMetricsGroup,"StepsType "+sStepsType) );
*/
m_sprStepsType->HandleMessage( msg );
}
}
this->HandleMessage( msg );
}
// lua start
#include "LuaBinding.h"
/** @brief Allow Lua to have access to the StepsDisplay. */
class LunaStepsDisplay: public Luna<StepsDisplay>
{
public:
static int Load( T* p, lua_State *L ) { p->Load( SArg(1), nullptr ); COMMON_RETURN_SELF; }
static int SetFromSteps( T* p, lua_State *L )
{
if( lua_isnil(L,1) )
{
p->SetFromSteps( nullptr );
}
else
{
Steps *pS = Luna<Steps>::check(L,1);
p->SetFromSteps( pS );
}
COMMON_RETURN_SELF;
}
static int SetFromTrail( T* p, lua_State *L )
{
if( lua_isnil(L,1) )
{
p->SetFromTrail( nullptr );
}
else
{
Trail *pT = Luna<Trail>::check(L,1);
p->SetFromTrail( pT );
}
COMMON_RETURN_SELF;
}
static int SetFromGameState( T* p, lua_State *L )
{
PlayerNumber pn = Enum::Check<PlayerNumber>(L, 1);
p->SetFromGameState( pn );
COMMON_RETURN_SELF;
}
LunaStepsDisplay()
{
ADD_METHOD( Load );
ADD_METHOD( SetFromSteps );
ADD_METHOD( SetFromTrail );
ADD_METHOD( SetFromGameState );
}
};
LUA_REGISTER_DERIVED_CLASS( StepsDisplay, ActorFrame )
// lua end
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard
* 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.
*/