This repository has been archived by the owner on Sep 8, 2019. It is now read-only.
/
RA_AchievementPopup.cpp
177 lines (145 loc) · 4.51 KB
/
RA_AchievementPopup.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
#include "RA_AchievementPopup.h"
#include "RA_Achievement.h"
#include "RA_Defs.h"
#include "RA_AchievementOverlay.h"
#include "RA_ImageFactory.h"
namespace
{
const float POPUP_DIST_Y_TO_PCT = 0.856f; // Where on screen to end up
const float POPUP_DIST_Y_FROM_PCT = 0.4f; // Amount of screens to travel
const TCHAR* FONT_TO_USE = _T( "Tahoma" );
const int FONT_SIZE_TITLE = 32;
const int FONT_SIZE_SUBTITLE = 28;
const float START_AT = 0.0f;
const float APPEAR_AT = 0.8f;
const float FADEOUT_AT = 4.2f;
const float FINISH_AT = 5.0f;
const TCHAR* MSG_SOUND[] =
{
_T( "./Overlay/login.wav" ),
_T( "./Overlay/info.wav" ),
_T( "./Overlay/unlock.wav" ),
_T( "./Overlay/acherror.wav" ),
_T( "./Overlay/lb.wav" ),
_T( "./Overlay/lbcancel.wav" ),
_T( "./Overlay/message.wav" ),
};
static_assert( SIZEOF_ARRAY( MSG_SOUND ) == NumMessageTypes, "Must match!" );
}
AchievementPopup::AchievementPopup() :
m_fTimer( 0.0f )
{
}
void AchievementPopup::PlayAudio()
{
PlaySound( MSG_SOUND[ ActiveMessage().Type() ], NULL, SND_FILENAME|SND_ASYNC );
}
void AchievementPopup::AddMessage( const MessagePopup& msg )
{
PlayAudio();
m_vMessages.push( msg );
}
void AchievementPopup::Update( ControllerInput input, float fDelta, bool bFullScreen, bool bPaused )
{
if( bPaused )
fDelta = 0.0f;
fDelta = RAClamp<float>( fDelta, 0.0f, 0.3f ); // Limit this!
if( m_vMessages.size() > 0 )
{
m_fTimer += fDelta;
if( m_fTimer >= FINISH_AT )
{
m_vMessages.pop();
m_fTimer = 0.0f;
}
}
}
float AchievementPopup::GetYOffsetPct() const
{
float fVal = 0.0f;
if( m_fTimer < APPEAR_AT )
{
// Fading in.
float fDelta = (APPEAR_AT - m_fTimer);
fDelta *= fDelta; // Quadratic
fVal = fDelta;
}
else if( m_fTimer < (FADEOUT_AT) )
{
// Faded in - held
fVal = 0.0f;
}
else if( m_fTimer < (FINISH_AT) )
{
// Fading out
float fDelta = ( FADEOUT_AT - m_fTimer );
fDelta *= fDelta; // Quadratic
fVal = ( fDelta );
}
else
{
// Finished!
fVal = 1.0f;
}
return fVal;
}
void AchievementPopup::Render( HDC hDC, RECT& rcDest )
{
if( !MessagesPresent() )
return;
const MessagePopup& msg = ActiveMessage();
const int nPixelWidth = rcDest.right - rcDest.left;
//SetBkColor( hDC, RGB( 0, 212, 0 ) );
SetBkColor( hDC, COL_TEXT_HIGHLIGHT );
SetTextColor( hDC, COL_POPUP );
HFONT hFontTitle = CreateFont( FONT_SIZE_TITLE, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS, ANTIALIASED_QUALITY,/*NONANTIALIASED_QUALITY,*/
DEFAULT_PITCH, FONT_TO_USE );
HFONT hFontDesc = CreateFont( FONT_SIZE_SUBTITLE, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS, ANTIALIASED_QUALITY,/*NONANTIALIASED_QUALITY,*/
DEFAULT_PITCH, FONT_TO_USE );
int nTitleX = 10;
int nDescX = nTitleX + 2;
const int nHeight = rcDest.bottom - rcDest.top;
float fFadeInY = GetYOffsetPct() * ( POPUP_DIST_Y_FROM_PCT * (float)nHeight );
fFadeInY += ( POPUP_DIST_Y_TO_PCT * static_cast<float>( nHeight ) );
const int nTitleY = static_cast<int>( fFadeInY );
const int nDescY = nTitleY + 32;
if( msg.Type() == PopupAchievementUnlocked || msg.Type() == PopupAchievementError )
{
DrawImage( hDC, msg.Image(), nTitleX, nTitleY, 64, 64 );
nTitleX += 64 + 4 + 2; // Negate the 2 from earlier!
nDescX += 64 + 4;
}
else if( msg.Type() == PopupLeaderboardInfo )
{
// meh
}
SelectObject( hDC, hFontTitle );
TextOut( hDC, nTitleX, nTitleY, ActiveMessage().Title().c_str(), strlen( ActiveMessage().Title().c_str() ) );
SIZE szTitle = { 0, 0 };
GetTextExtentPoint32( hDC, msg.Title().c_str(), strlen( msg.Title().c_str() ), &szTitle );
SelectObject( hDC, hFontDesc );
TextOut( hDC, nDescX, nDescY, msg.Subtitle().c_str(), strlen( msg.Subtitle().c_str() ) );
SIZE szAchievement = { 0, 0 };
GetTextExtentPoint32( hDC, msg.Subtitle().c_str(), strlen( msg.Subtitle().c_str() ), &szAchievement );
HGDIOBJ hPen = CreatePen( PS_SOLID, 2, COL_POPUP_SHADOW );
SelectObject( hDC, hPen );
MoveToEx( hDC, nTitleX, nTitleY + szTitle.cy, NULL );
LineTo( hDC, nTitleX + szTitle.cx, nTitleY + szTitle.cy ); // right
LineTo( hDC, nTitleX + szTitle.cx, nTitleY + 1 ); // up
if( msg.Subtitle().length() > 0 )
{
MoveToEx( hDC, nDescX, nDescY + szAchievement.cy, NULL );
LineTo( hDC, nDescX + szAchievement.cx, nDescY + szAchievement.cy );
LineTo( hDC, nDescX + szAchievement.cx, nDescY + 1 );
}
DeleteObject( hPen );
DeleteObject( hFontTitle );
DeleteObject( hFontDesc );
}
void AchievementPopup::Clear()
{
while( !m_vMessages.empty() )
m_vMessages.pop();
}