forked from stepmania/stepmania
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenUnlockStatus.cpp
363 lines (305 loc) · 13.7 KB
/
ScreenUnlockStatus.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
362
363
#include "global.h"
#include "PrefsManager.h"
#include "ScreenUnlockStatus.h"
#include "ThemeManager.h"
#include "GameState.h"
#include "RageLog.h"
#include "UnlockManager.h"
#include "SongManager.h"
#include "ActorUtil.h"
#include "Song.h"
#include "Course.h"
using std::vector;
#define UNLOCK_TEXT_SCROLL_X THEME->GetMetricF("ScreenUnlockStatus","UnlockTextScrollX");
#define UNLOCK_TEXT_SCROLL_START_Y THEME->GetMetricF("ScreenUnlockStatus","UnlockTextScrollStartY")
#define UNLOCK_TEXT_SCROLL_END_Y THEME->GetMetricF("ScreenUnlockStatus","UnlockTextScrollEndY")
#define UNLOCK_TEXT_SCROLL_ZOOM THEME->GetMetricF("ScreenUnlockStatus","UnlockTextScrollZoom")
#define UNLOCK_TEXT_SCROLL_ROWS THEME->GetMetricF("ScreenUnlockStatus","UnlockTextScrollRows")
#define UNLOCK_TEXT_SCROLL_MAX_WIDTH THEME->GetMetricF("ScreenUnlockStatus","UnlockTextScrollMaxWidth")
#define UNLOCK_TEXT_SCROLL_ICON_X THEME->GetMetricF("ScreenUnlockStatus","UnlockTextScrollIconX")
#define UNLOCK_TEXT_SCROLL_ICON_SIZE THEME->GetMetricF("ScreenUnlockStatus","UnlockTextScrollIconSize")
#define UNLOCK_TEXT_SCROLL THEME->GetMetricI("ScreenUnlockStatus","UnlockTextScroll")
#define TYPE_TO_DISPLAY THEME->GetMetric ("ScreenUnlockStatus","TypeOfPointsToDisplay")
#define ICON_COMMAND THEME->GetMetricA("ScreenUnlockStatus","UnlockIconCommand")
#define TIME_TO_DISPLAY THEME->GetMetricF("ScreenUnlockStatus","TimeToDisplay")
#define POINTS_ZOOM THEME->GetMetricF("ScreenUnlockStatus","PointsZoom")
REGISTER_SCREEN_CLASS( ScreenUnlockStatus );
void ScreenUnlockStatus::Init()
{
ScreenAttract::Init();
unsigned iNumUnlocks = UNLOCKMAN->m_UnlockEntries.size();
if( !PREFSMAN->m_bUseUnlockSystem || iNumUnlocks == 0 )
{
this->PostScreenMessage( SM_GoToNextScreen, 0 );
return;
}
unsigned NumUnlocks = UNLOCKMAN->m_UnlockEntries.size();
PointsUntilNextUnlock.LoadFromFont( THEME->GetPathF("Common","normal") );
PointsUntilNextUnlock.SetHorizAlign( align_left );
apActorCommands IconCommand = ICON_COMMAND;
for( unsigned i=1; i <= NumUnlocks; i++ )
{
// get pertaining UnlockEntry
const UnlockEntry &entry = UNLOCKMAN->m_UnlockEntries[i-1];
const Song *pSong = entry.m_Song.ToSong();
if( pSong == nullptr)
continue;
Sprite* pSpr = new Sprite;
// new unlock graphic
pSpr->Load( THEME->GetPathG("ScreenUnlockStatus",fmt::sprintf("%04d icon", i)) );
// set graphic location
pSpr->SetName( fmt::sprintf("Unlock%04d",i) );
LOAD_ALL_COMMANDS_AND_SET_XY( pSpr );
pSpr->RunCommands(IconCommand);
Unlocks.push_back(pSpr);
if ( !entry.IsLocked() )
this->AddChild(Unlocks[Unlocks.size() - 1]);
}
// scrolling text
if (UNLOCK_TEXT_SCROLL != 0)
{
float ScrollingTextX = UNLOCK_TEXT_SCROLL_X;
float ScrollingTextStartY = UNLOCK_TEXT_SCROLL_START_Y;
float ScrollingTextEndY = UNLOCK_TEXT_SCROLL_END_Y;
float ScrollingTextZoom = UNLOCK_TEXT_SCROLL_ZOOM;
float ScrollingTextRows = UNLOCK_TEXT_SCROLL_ROWS;
float MaxWidth = UNLOCK_TEXT_SCROLL_MAX_WIDTH;
float SecondsToScroll = TIME_TO_DISPLAY;
if (SecondsToScroll > 2) SecondsToScroll--;
float SECS_PER_CYCLE = 0;
if (UNLOCK_TEXT_SCROLL != 3)
SECS_PER_CYCLE = (float)SecondsToScroll/(ScrollingTextRows + NumUnlocks);
else
SECS_PER_CYCLE = (float)SecondsToScroll/(ScrollingTextRows * 3 + NumUnlocks + 4);
for(unsigned i = 1; i <= NumUnlocks; i++)
{
const UnlockEntry &entry = UNLOCKMAN->m_UnlockEntries[i-1];
BitmapText* text = new BitmapText;
text->LoadFromFont( THEME->GetPathF("ScreenUnlockStatus","text") );
text->SetHorizAlign( align_left );
text->SetZoom(ScrollingTextZoom);
switch( entry.m_Type )
{
case UnlockRewardType_Song:
{
const Song *pSong = entry.m_Song.ToSong();
ASSERT( pSong != nullptr );
std::string title = pSong->GetDisplayMainTitle();
std::string subtitle = pSong->GetDisplaySubTitle();
if( subtitle != "" )
title = title + "\n" + subtitle;
text->SetMaxWidth( MaxWidth );
text->SetText( title );
}
break;
case UnlockRewardType_Course:
{
const Course *pCourse = entry.m_Course.ToCourse();
ASSERT( pCourse != nullptr );
text->SetMaxWidth( MaxWidth );
text->SetText( pCourse->GetDisplayFullTitle() );
text->SetDiffuse( Rage::Color(0,1,0,1) );
}
break;
default:
text->SetText( "" );
text->SetDiffuse( Rage::Color(0.5f,0,0,1) );
break;
}
if( entry.IsLocked() )
{
text->SetText("???");
text->SetZoomX(1);
}
else
{
// unlocked. change color
const Song *pSong = entry.m_Song.ToSong();
Rage::Color color = Rage::Color(1,1,1,1);
if( pSong )
color = SONGMAN->GetSongGroupColor(pSong->m_sGroupName);
text->SetGlobalDiffuseColor(color);
}
text->SetXY( ScrollingTextX, ScrollingTextStartY );
if (UNLOCK_TEXT_SCROLL == 3 && UNLOCK_TEXT_SCROLL_ROWS + i > NumUnlocks)
{ // special command for last unlocks when scrolling is in effect
float TargetRow = -0.5f + i + UNLOCK_TEXT_SCROLL_ROWS - NumUnlocks;
float StopOffPoint = ScrollingTextEndY - TargetRow / UNLOCK_TEXT_SCROLL_ROWS * (ScrollingTextEndY - ScrollingTextStartY);
float FirstCycleTime = (UNLOCK_TEXT_SCROLL_ROWS - TargetRow) * SECS_PER_CYCLE;
float SecondCycleTime = (6 + TargetRow) * SECS_PER_CYCLE - FirstCycleTime;
//LOG->Trace("Target Row: %f", TargetRow);
//LOG->Trace("command for icon %d: %s", i, fmt::sprintf("diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,%f;y,%f;linear,0.1;diffusealpha,0", SECS_PER_CYCLE * (i - 1), FirstCycleTime, StopOffPoint, SecondCycleTime * 2, ScrollingTextEndY).c_str() );
std::string sCommand = fmt::sprintf("diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,%f;y,%f;linear,0.1;diffusealpha,0", SECS_PER_CYCLE * (i - 1), FirstCycleTime, StopOffPoint, SecondCycleTime, ScrollingTextEndY);
text->RunCommands( ActorUtil::ParseActorCommands(sCommand) );
}
else
{
std::string sCommand = fmt::sprintf("diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,0.1;diffusealpha,0", SECS_PER_CYCLE * (i - 1), SECS_PER_CYCLE * (ScrollingTextRows), ScrollingTextEndY);
text->RunCommands( ActorUtil::ParseActorCommands(sCommand) );
}
item.push_back(text);
if (UNLOCK_TEXT_SCROLL >= 2)
{
Sprite* IconCount = new Sprite;
// new unlock graphic
IconCount->Load( THEME->GetPathG("ScreenUnlockStatus",fmt::sprintf("%04d icon", i)) );
// set graphic location
IconCount->SetXY( UNLOCK_TEXT_SCROLL_ICON_X, ScrollingTextStartY);
IconCount->SetHeight(UNLOCK_TEXT_SCROLL_ICON_SIZE);
IconCount->SetWidth(UNLOCK_TEXT_SCROLL_ICON_SIZE);
if (UNLOCK_TEXT_SCROLL == 3 && UNLOCK_TEXT_SCROLL_ROWS + i > NumUnlocks)
{
float TargetRow = -0.5f + i + UNLOCK_TEXT_SCROLL_ROWS - NumUnlocks;
float StopOffPoint = ScrollingTextEndY - TargetRow / UNLOCK_TEXT_SCROLL_ROWS * (ScrollingTextEndY - ScrollingTextStartY);
float FirstCycleTime = (UNLOCK_TEXT_SCROLL_ROWS - TargetRow) * SECS_PER_CYCLE;
float SecondCycleTime = (6 + TargetRow) * SECS_PER_CYCLE - FirstCycleTime;
//LOG->Trace("Target Row: %f", TargetRow);
//LOG->Trace("command for icon %d: %s", i, fmt::sprintf("diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,%f;y,%f;linear,0.1;diffusealpha,0", SECS_PER_CYCLE * (i - 1), FirstCycleTime, StopOffPoint, SecondCycleTime * 2, ScrollingTextEndY).c_str() );
std::string sCommand = fmt::sprintf("diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,%f;y,%f;linear,0.1;diffusealpha,0", SECS_PER_CYCLE * (i - 1), FirstCycleTime, StopOffPoint, SecondCycleTime, ScrollingTextEndY);
IconCount->RunCommands( ActorUtil::ParseActorCommands(sCommand) );
}
else
{
std::string sCommand = fmt::sprintf("diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;linear,0.1;diffusealpha,0", SECS_PER_CYCLE * (i - 1), SECS_PER_CYCLE * (ScrollingTextRows), ScrollingTextEndY);
IconCount->RunCommands( ActorUtil::ParseActorCommands(sCommand) );
}
ItemIcons.push_back(IconCount);
//LOG->Trace("Added unlock text %d", i);
if (UNLOCK_TEXT_SCROLL == 3)
{
if ( !entry.IsLocked() )
LastUnlocks.push_back(i);
}
}
}
}
if (UNLOCK_TEXT_SCROLL == 3)
{
float ScrollingTextX = UNLOCK_TEXT_SCROLL_X;
float ScrollingTextStartY = UNLOCK_TEXT_SCROLL_START_Y;
float ScrollingTextEndY = UNLOCK_TEXT_SCROLL_END_Y;
float ScrollingTextRows = UNLOCK_TEXT_SCROLL_ROWS;
float MaxWidth = UNLOCK_TEXT_SCROLL_MAX_WIDTH;
float SecondsToScroll = TIME_TO_DISPLAY - 1;
float SECS_PER_CYCLE = (float)SecondsToScroll/(ScrollingTextRows * 3 + NumUnlocks + 4);
for(unsigned i=1; i <= UNLOCK_TEXT_SCROLL_ROWS; i++)
{
if (i > LastUnlocks.size())
continue;
unsigned NextIcon = LastUnlocks[LastUnlocks.size() - i];
const UnlockEntry &entry = UNLOCKMAN->m_UnlockEntries[NextIcon-1];
const Song *pSong = entry.m_Song.ToSong();
if( pSong == nullptr )
continue;
BitmapText* NewText = new BitmapText;
NewText->LoadFromFont( THEME->GetPathF("ScreenUnlockStatus","text") );
NewText->SetHorizAlign( align_left );
std::string title = pSong->GetDisplayMainTitle();
std::string subtitle = pSong->GetDisplaySubTitle();
if( subtitle != "" )
title = title + "\n" + subtitle;
NewText->SetZoom(UNLOCK_TEXT_SCROLL_ZOOM);
NewText->SetMaxWidth( MaxWidth );
NewText->SetText( title );
Rage::Color color = SONGMAN->GetSongGroupColor(pSong->m_sGroupName);
NewText->SetGlobalDiffuseColor(color);
NewText->SetXY(ScrollingTextX, ScrollingTextStartY);
{
std::string sCommand = fmt::sprintf("diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;", SECS_PER_CYCLE * (NumUnlocks + 2 * i - 2), SECS_PER_CYCLE * ((ScrollingTextRows - i) * 2 + 1 ), (ScrollingTextStartY + (ScrollingTextEndY - ScrollingTextStartY) * (ScrollingTextRows - i + 0.5) / ScrollingTextRows ));
NewText->RunCommands( ActorUtil::ParseActorCommands(sCommand) );
}
// new unlock graphic
Sprite* NewIcon = new Sprite;
NewIcon->Load( THEME->GetPathG("ScreenUnlockStatus",fmt::sprintf("%04d icon", NextIcon)) );
NewIcon->SetXY( UNLOCK_TEXT_SCROLL_ICON_X, ScrollingTextStartY);
NewIcon->SetHeight(UNLOCK_TEXT_SCROLL_ICON_SIZE);
NewIcon->SetWidth(UNLOCK_TEXT_SCROLL_ICON_SIZE);
{
std::string sCommand = fmt::sprintf("diffusealpha,0;sleep,%f;diffusealpha,1;linear,%f;y,%f;", SECS_PER_CYCLE * (NumUnlocks + 2 * i - 2), SECS_PER_CYCLE * ((ScrollingTextRows - i) * 2 + 1 ), (ScrollingTextStartY + (ScrollingTextEndY - ScrollingTextStartY) * (ScrollingTextRows - i + 0.5) / ScrollingTextRows ));
NewIcon->RunCommands( ActorUtil::ParseActorCommands(sCommand) );
}
ItemIcons.push_back(NewIcon);
item.push_back(NewText);
}
}
// NOTE: the following two loops require the iterator to
// be ints because if you decrement an unsigned when it
// equals zero, you get the maximum value of an unsigned,
// which is still greater than 0. By typecasting it as
// an integer, you can achieve -1, which exits the loop.
for(int i = item.size() - 1; (int)i >= 0; i--)
{
this->AddChild(item[i]);
}
for(int i = ItemIcons.size() - 1; (int)i >= 0; i--)
{
this->AddChild(ItemIcons[i]);
}
PointsUntilNextUnlock.SetName( "PointsDisplay" );
std::string PointDisplay = TYPE_TO_DISPLAY;
if (PointDisplay == "DP" || PointDisplay == "Dance")
{
std::string sDP = fmt::sprintf( "%d", (int)UNLOCKMAN->PointsUntilNextUnlock(UnlockRequirement_DancePoints) );
PointsUntilNextUnlock.SetText( sDP );
}
else if (PointDisplay == "AP" || PointDisplay == "Arcade")
{
std::string sAP = fmt::sprintf( "%d", (int)UNLOCKMAN->PointsUntilNextUnlock(UnlockRequirement_ArcadePoints) );
PointsUntilNextUnlock.SetText( sAP );
}
else if (PointDisplay == "SP" || PointDisplay == "Song")
{
std::string sSP = fmt::sprintf( "%d", (int)UNLOCKMAN->PointsUntilNextUnlock(UnlockRequirement_SongPoints) );
PointsUntilNextUnlock.SetText( sSP );
}
PointsUntilNextUnlock.SetZoom( POINTS_ZOOM );
LOAD_ALL_COMMANDS_AND_SET_XY( PointsUntilNextUnlock );
this->AddChild( &PointsUntilNextUnlock );
this->ClearMessageQueue( SM_BeginFadingOut ); // ignore ScreenAttract's SecsToShow
this->PostScreenMessage( SM_BeginFadingOut, TIME_TO_DISPLAY );
}
ScreenUnlockStatus::~ScreenUnlockStatus()
{
while (Unlocks.size() > 0)
{
Sprite* entry = Unlocks[Unlocks.size()-1];
Rage::safe_delete(entry);
Unlocks.pop_back();
}
while (item.size() > 0)
{
BitmapText* entry = item[item.size()-1];
Rage::safe_delete(entry);
item.pop_back();
}
while (ItemIcons.size() > 0)
{
Sprite* entry = ItemIcons[ItemIcons.size()-1];
Rage::safe_delete(entry);
ItemIcons.pop_back();
}
}
/*
* (c) 2003 Andrew Wong
* 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.
*/