forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenHighScores.cpp
359 lines (309 loc) · 10.1 KB
/
ScreenHighScores.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
#include "global.h"
#include "ScreenHighScores.h"
#include "ScreenManager.h"
#include "SongManager.h"
#include "Song.h"
#include "RageLog.h"
#include "UnlockManager.h"
#include <limits>
using std::vector;
std::string COLUMN_DIFFICULTY_NAME( size_t i );
std::string COLUMN_STEPS_TYPE_NAME( size_t i );
static const char *HighScoresTypeNames[] = {
"AllSteps",
"NonstopCourses",
"OniCourses",
"SurvivalCourses",
"AllCourses",
};
XToString( HighScoresType );
LuaXType( HighScoresType );
REGISTER_SCREEN_CLASS( ScreenHighScores );
static void GetAllSongsToShow( vector<Song*> &vpOut, int iNumMostRecentScoresToShow )
{
vpOut.clear();
for (auto *s: SONGMAN->GetAllSongs())
{
if( !s->NormallyDisplayed() )
continue; // skip
if( !s->ShowInDemonstrationAndRanking() )
continue; // skip
vpOut.push_back( s );
}
if( (int)vpOut.size() > iNumMostRecentScoresToShow )
{
SongUtil::SortSongPointerArrayByTitle( vpOut );
SongUtil::SortByMostRecentlyPlayedForMachine( vpOut );
if( (int) vpOut.size() > iNumMostRecentScoresToShow )
vpOut.erase( vpOut.begin()+iNumMostRecentScoresToShow, vpOut.end() );
}
}
static void GetAllCoursesToShow( vector<Course*> &vpOut, CourseType ct, int iNumMostRecentScoresToShow )
{
vpOut.clear();
vector<Course*> vpCourses;
if( ct == CourseType_Invalid )
SONGMAN->GetAllCourses( vpCourses, false );
else
SONGMAN->GetCourses( ct, vpCourses, false );
for (auto *c: vpCourses)
{
if( UNLOCKMAN->CourseIsLocked(c) )
continue; // skip
if( !c->ShowInDemonstrationAndRanking() )
continue; // skip
vpOut.push_back( c );
}
if( (int)vpOut.size() > iNumMostRecentScoresToShow )
{
CourseUtil::SortCoursePointerArrayByTitle( vpOut );
CourseUtil::SortByMostRecentlyPlayedForMachine( vpOut );
if( (int) vpOut.size() > iNumMostRecentScoresToShow )
vpOut.erase( vpOut.begin()+iNumMostRecentScoresToShow, vpOut.end() );
}
}
/////////////////////////////////////////////
ScoreScroller::ScoreScroller()
{
this->DeleteChildrenWhenDone();
}
void ScoreScroller::SetDisplay( const vector<DifficultyAndStepsType> &DifficultiesToShow )
{
m_DifficultiesToShow = DifficultiesToShow;
ShiftSubActors( std::numeric_limits<int>::max() );
}
bool ScoreScroller::Scroll( int iDir )
{
if( (int)m_vScoreRowItemData.size() <= SCROLLER_ITEMS_TO_DRAW )
return false;
float fDest = GetDestinationItem();
float fOldDest = fDest;
fDest += iDir;
float fLowClamp = (SCROLLER_ITEMS_TO_DRAW-1)/2.0f;
float fHighClamp = m_vScoreRowItemData.size()-(SCROLLER_ITEMS_TO_DRAW-1)/2.0f-1;
fDest = Rage::clamp( fDest, fLowClamp, fHighClamp );
if( fOldDest != fDest )
{
SetDestinationItem( fDest );
return true;
}
else
{
return false;
}
}
void ScoreScroller::ScrollTop()
{
SetCurrentAndDestinationItem( (SCROLLER_ITEMS_TO_DRAW-1)/2.0f );
}
void ScoreScroller::ConfigureActor( Actor *pActor, int iItem )
{
LOG->Trace("ScoreScroller::ConfigureActor");
Actor &item = *dynamic_cast<Actor *>(pActor);
const ScoreRowItemData &data = m_vScoreRowItemData[iItem];
Message msg("Set");
if( data.m_pSong != nullptr )
msg.SetParam( "Song", data.m_pSong );
if( data.m_pCourse != nullptr )
msg.SetParam( "Course", data.m_pCourse );
Lua *L = LUA->Get();
lua_newtable( L );
lua_pushvalue( L, -1 );
msg.SetParamFromStack( L, "Entries" );
for (auto iter = m_DifficultiesToShow.begin(); iter != m_DifficultiesToShow.end(); ++iter)
{
int i = iter-m_DifficultiesToShow.begin();
Difficulty dc = iter->first;
StepsType st = iter->second;
if( data.m_pSong != nullptr )
{
const Song* pSong = data.m_pSong;
Steps *pSteps = SongUtil::GetStepsByDifficulty( pSong, st, dc, false );
if( pSteps && UNLOCKMAN->StepsIsLocked(pSong, pSteps) )
pSteps = nullptr;
LuaHelpers::Push( L, pSteps );
}
else if( data.m_pCourse != nullptr )
{
const Course* pCourse = data.m_pCourse;
Trail *pTrail = pCourse->GetTrail( st, dc );
LuaHelpers::Push( L, pTrail );
}
// Because pSteps or pTrail can be nullptr, what we're creating in Lua is not an array.
// It must be iterated using pairs(), not ipairs().
lua_setfield( L, -2, fmt::sprintf("%d",i+1).c_str() );
}
lua_pop( L, 1 );
LUA->Release( L );
item.HandleMessage( msg );
LOG->Trace("end ScoreScroller::ConfigureActor");
}
void ScoreScroller::LoadSongs( int iNumRecentScores )
{
vector<Song*> vpSongs;
GetAllSongsToShow( vpSongs, iNumRecentScores );
m_vScoreRowItemData.resize( vpSongs.size() );
for( unsigned i=0; i<m_vScoreRowItemData.size(); ++i )
{
m_vScoreRowItemData[i].m_pSong = vpSongs[i];
}
}
void ScoreScroller::LoadCourses( CourseType ct, int iNumRecentScores )
{
vector<Course*> vpCourses;
GetAllCoursesToShow( vpCourses, ct, iNumRecentScores );
m_vScoreRowItemData.resize( vpCourses.size() );
for( unsigned i=0; i<m_vScoreRowItemData.size(); ++i )
{
m_vScoreRowItemData[i].m_pCourse = vpCourses[i];
}
}
void ScoreScroller::Load( std::string sMetricsGroup )
{
SCROLLER_ITEMS_TO_DRAW.Load(sMetricsGroup, "ScrollerItemsToDraw");
SCROLLER_SECONDS_PER_ITEM.Load(sMetricsGroup, "ScrollerSecondsPerItem");
int iNumCopies = SCROLLER_ITEMS_TO_DRAW+1;
for( int i=0; i<iNumCopies; ++i )
{
Actor *pActor = ActorUtil::MakeActor( THEME->GetPathG(sMetricsGroup,"ScrollerItem") );
if( pActor != nullptr )
this->AddChild( pActor );
}
DynamicActorScroller::SetTransformFromReference( THEME->GetMetricR(sMetricsGroup,"ScrollerItemTransformFunction") );
DynamicActorScroller::SetNumItemsToDraw( (float) SCROLLER_ITEMS_TO_DRAW );
DynamicActorScroller::SetSecondsPerItem( SCROLLER_SECONDS_PER_ITEM );
DynamicActorScroller::Load2();
m_iNumItems = m_vScoreRowItemData.size();
}
/////////////////////////////////////////////
std::string COLUMN_DIFFICULTY_NAME( size_t i ) { return fmt::sprintf("ColumnDifficulty%d",int(i+1)); }
std::string COLUMN_STEPS_TYPE_NAME( size_t i ) { return fmt::sprintf("ColumnStepsType%d",int(i+1)); }
void ScreenHighScores::Init()
{
ScreenAttract::Init();
MANUAL_SCROLLING.Load( m_sName,"ManualScrolling");
HIGH_SCORES_TYPE.Load( m_sName,"HighScoresType");
NUM_COLUMNS.Load( m_sName, "NumColumns" );
COLUMN_DIFFICULTY.Load( m_sName, COLUMN_DIFFICULTY_NAME, NUM_COLUMNS );
COLUMN_STEPS_TYPE.Load( m_sName, COLUMN_STEPS_TYPE_NAME, NUM_COLUMNS );
MAX_ITEMS_TO_SHOW.Load( m_sName, "MaxItemsToShow" );
m_Scroller.SetName( "Scroller" );
LOAD_ALL_COMMANDS( m_Scroller );
HighScoresType type = HIGH_SCORES_TYPE;
switch( type )
{
DEFAULT_FAIL( type );
case HighScoresType_AllSteps:
m_Scroller.LoadSongs( MAX_ITEMS_TO_SHOW );
break;
case HighScoresType_NonstopCourses:
case HighScoresType_OniCourses:
case HighScoresType_SurvivalCourses:
case HighScoresType_AllCourses:
{
CourseType ct;
switch( type )
{
default:
FAIL_M(fmt::sprintf("Invalid HighScoresType: %i", type));
case HighScoresType_NonstopCourses: ct = COURSE_TYPE_NONSTOP; break;
case HighScoresType_OniCourses: ct = COURSE_TYPE_ONI; break;
case HighScoresType_SurvivalCourses: ct = COURSE_TYPE_SURVIVAL; break;
case HighScoresType_AllCourses: ct = CourseType_Invalid; break;
}
m_Scroller.LoadCourses( ct, MAX_ITEMS_TO_SHOW );
}
break;
}
m_Scroller.Load( m_sName );
this->AddChild( &m_Scroller );
}
void ScreenHighScores::BeginScreen()
{
ScreenAttract::BeginScreen();
vector<DifficultyAndStepsType> vdast;
for( int i=0; i<NUM_COLUMNS; i++ )
{
DifficultyAndStepsType dast( COLUMN_DIFFICULTY.GetValue(i), COLUMN_STEPS_TYPE.GetValue(i) );
vdast.push_back( dast );
}
m_Scroller.SetDisplay( vdast );
if( (bool)MANUAL_SCROLLING )
m_Scroller.ScrollTop();
else
m_Scroller.ScrollThroughAllItems();
if( !MANUAL_SCROLLING )
{
float fSecs = m_Scroller.GetSecondsForCompleteScrollThrough();
this->PostScreenMessage( SM_BeginFadingOut, fSecs );
}
}
bool ScreenHighScores::Input( const InputEventPlus &input )
{
//LOG->Trace( "ScreenRanking::Input()" );
if( IsTransitioning() )
return false;
// If manually scrolling, pass the input to Screen::Input so it will call Menu*
if( (bool)MANUAL_SCROLLING )
return Screen::Input( input );
else
return ScreenAttract::Input( input );
}
void ScreenHighScores::HandleScreenMessage( const ScreenMessage SM )
{
if( SM == SM_BeginFadingOut ) /* Screen is starting to tween out. */
{
StartTransitioningScreen( SM_GoToNextScreen );
}
ScreenAttract::HandleScreenMessage( SM );
}
bool ScreenHighScores::MenuStart( const InputEventPlus &input )
{
if( !MANUAL_SCROLLING )
return false;
if( !IsTransitioning() )
StartTransitioningScreen( SM_GoToNextScreen );
SCREENMAN->PlayStartSound();
return true;
}
bool ScreenHighScores::MenuBack( const InputEventPlus &input )
{
if( !MANUAL_SCROLLING )
return false;
if( !IsTransitioning() )
StartTransitioningScreen( SM_GoToNextScreen );
SCREENMAN->PlayStartSound();
return true;
}
void ScreenHighScores::DoScroll( int iDir )
{
if( !m_Scroller.Scroll(iDir) )
iDir = 0;
Message msg("Scrolled");
msg.SetParam( "Dir", iDir );
this->HandleMessage( msg );
}
/*
* (c) 2001-2007 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.
*/