OpenBarnyard
 
Loading...
Searching...
No Matches
AGUISlideshow.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AGUISlideshow.h"
4#include "AGUISystem.h"
5#include "AGUI2.h"
6
7//-----------------------------------------------------------------------------
8// Enables memory debugging.
9// Note: Should be the last include!
10//-----------------------------------------------------------------------------
11#include <Core/TMemoryDebugOn.h>
12
14
30
31Toshi::TPString8* AGUISlideshow::LocaliseBackgroundFileName( Toshi::TPString8& a_rOutName, const Toshi::TPString8& a_rName )
32{
33 LocaliseBackgroundFileName( a_rOutName, a_rName.GetString8().GetString() );
34 return &a_rOutName;
35}
36
37void AGUISlideshow::LocaliseBackgroundFileName( Toshi::TPString8& a_rOutName, const TCHAR* a_szName )
38{
39 TCHAR szFormattedName[ 256 ];
40 auto eLang = ALocaleManager::GetSingleton()->GetLanguage();
41
43 {
44 TCHAR szLang[ 4 ];
45 Toshi::TStringManager::String8Copy(
46 szLang,
47 ALocaleManager::Interface()->GetCurrentLanguageName(),
48 sizeof( szLang )
49 );
50
51 szLang[ 1 ] = '\0';
52 Toshi::TStringManager::String8Format( szFormattedName, sizeof( szFormattedName ), "%s%s", a_szName, szLang );
53 a_szName = szFormattedName;
54 }
55
56 a_rOutName = Toshi::TPString8( a_szName );
57}
58
60{
61 TASSERT( m_Images.Size() > 0 );
62
65 m_fUnk2 = 0.0f;
66
67 if ( !m_bIsAppearing )
68 {
69 if ( !m_bShouldLocalise )
70 {
71 AGUISystem::GetSingleton()->SetPicture( m_Images[ 0 ] );
72 }
73 else
74 {
75 Toshi::TPString8 pictureName;
76 LocaliseBackgroundFileName( pictureName, m_Images[ 0 ] );
77 AGUISystem::GetSingleton()->SetPicture( pictureName );
78 }
79 }
80
83}
84
86{
87 TFLOAT fOpacity;
88
89 if ( !m_bIsAppearing )
90 {
92 {
94 {
95 fOpacity = 0.0f;
96 }
97 else
98 {
100
101 if ( fOpacity > 1.0f )
102 {
103 fOpacity = 1.0f;
104 }
105 }
106 }
107 else
108 {
109 fOpacity = 1.0f - m_fCurrentSlideTime / m_fFadeInTime;
110 }
111 }
112 else
113 {
115
116 if ( fOpacity >= 1.0f )
117 {
118 Toshi::TPString8 pictureName;
120 AGUISystem::GetSingleton()->SetPicture( pictureName );
121
123 m_fCurrentSlideTime = 0.0f;
124 fOpacity = 1.0f;
125 }
126 }
127
128 TASSERT( fOpacity <= 1.0f );
129 m_FadeOverlay.SetColour( TUINT32( fOpacity * 255 ) << 24 );
130 m_FadeOverlay.Unlink();
132 m_FadeOverlay.Show();
133}
134
135void AGUISlideshow::Update( TFLOAT a_fDeltaTime )
136{
137 if ( m_bIsActive && !IsSlideshowOver() )
138 {
139 m_fCurrentSlideTime += a_fDeltaTime;
140
141 if ( m_bIsAppearing )
142 {
144 return;
145 }
146
147 m_fUnk2 += a_fDeltaTime;
148
150 {
152 }
153
155 return;
156 }
157
158 m_FadeOverlay.Unlink();
159}
160
162{
164 {
165 return !m_ImageIterator.IsValid();
166 }
167
168 if ( !HASANYFLAG( m_eFlags, Flags_Ended ) && ( m_fUnk4 <= 0.0f || m_fUnk2 <= m_fUnk4 ) )
169 {
170 return TFALSE;
171 }
172
173 return TTRUE;
174}
175
177{
178 if ( m_ImageIterator.IsValid() )
179 {
181 }
182
183 if ( !m_ImageIterator.IsValid() )
184 {
185 if ( !HASANYFLAG( m_eFlags, Flags_Repeat ) ) return;
187 }
188
189 m_fCurrentSlideTime = 0.0f;
190
191 Toshi::TPString8 pictureName;
193 AGUISystem::GetSingleton()->SetPicture( pictureName );
194}
195
197{
199
201 AGUISystem::GetSingleton()->SetPicture( Toshi::TPString8() );
203}
204
205TBOOL AGUISlideshow::Setup( AGameState::HUDParams* a_pHUDParams, const Params& a_rParams, TBOOL a_bShouldLocalise )
206{
207 if ( m_pHUDParams )
208 {
209 return TFALSE;
210 }
211
212 m_bShouldLocalise = a_bShouldLocalise;
214
215 if ( a_rParams.iUnk1 != 0 )
216 {
217 return TFALSE;
218 }
219
220 m_pHUDParams = a_pHUDParams;
221
222 if ( a_rParams.bSlideSkippable )
223 {
225 }
226
227 if ( a_rParams.bUnk2 )
228 {
230 }
231
232 if ( a_rParams.bInstaSkippable )
233 {
235 }
236
237 if ( a_rParams.bHasFadeIn )
238 {
240 m_fFadeInTime = a_rParams.fFadeInTime;
241 }
242
243 if ( a_rParams.bHasFadeOut )
244 {
246 m_fFadeOutTime = a_rParams.fFadeOutTime;
247 }
248
249 if ( a_rParams.bRepeat )
250 {
252 }
253
254 m_fDuration = a_rParams.fDuration;
255 m_fUnk4 = a_rParams.fUnk5;
256
257 TFLOAT fWidth, fHeight;
258 AGUI2::GetSingleton()->GetDimensions( fWidth, fHeight );
259 m_FadeOverlay.SetDimensions( fWidth, fHeight );
261 m_FadeOverlay.Hide();
262
263 if ( a_rParams.bDelayAppear )
264 {
266 }
267
268 return TTRUE;
269}
270
271TBOOL AGUISlideshow::ProcessInput( const Toshi::TInputInterface::InputEvent* a_pEvent )
272{
273 if ( a_pEvent->GetEventType() == Toshi::TInputInterface::EVENT_TYPE_GONE_DOWN )
274 {
276 {
279 return TTRUE;
280 }
281
283 {
285 return TTRUE;
286 }
287 }
288
289 return TFALSE;
290}
291
293{
294 if ( ( ( a_eCommand != AInputCommand_Back && a_eCommand != AInputCommand_Cancel && a_eCommand != AInputCommand_Quit ) || !HASANYFLAG( m_eFlags, Flags_Unk1 ) ) && !HASANYFLAG( m_eFlags, Flags_InstaSkippable ) )
295 {
297 {
299 return TTRUE;
300 }
301
302 return TFALSE;
303 }
304
307 return TTRUE;
308}
309
311{
313 m_fCurrentSlideTime = 0.0f;
314 m_fUnk2 = 0.0f;
315}
#define TASSERT(X,...)
Definition Defines.h:138
#define HASANYFLAG(STATE, FLAG)
Definition Defines.h:5
TFORCEINLINE T2Allocator * GetGlobalAllocator()
Definition T2Allocator.h:49
#define TDEFINE_CLASS(...)
Definition TObject.h:120
char TCHAR
Definition Typedefs.h:20
float TFLOAT
Definition Typedefs.h:4
#define TNULL
Definition Typedefs.h:23
uint32_t TUINT32
Definition Typedefs.h:13
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
@ AGUI2ATTACHMENT_TOPCENTER
AInputCommand
Definition AInputMap.h:12
@ AInputCommand_Back
Definition AInputMap.h:18
@ AInputCommand_Quit
Definition AInputMap.h:20
@ AInputCommand_Cancel
Definition AInputMap.h:16
static AGUI2Element * GetRootElement()
Definition AGUI2.h:31
void AddChildTail(AGUI2Element &a_rElement)
AGUI2Rectangle m_FadeOverlay
TBOOL ProcessCommand(AInputCommand a_eCommand)
void UpdateFadeOverlay()
TFLOAT m_fFadeOutTime
AGameState::HUDParams * m_pHUDParams
void Update(TFLOAT a_fDeltaTime)
TBOOL IsSlideshowOver()
TBOOL ProcessInput(const Toshi::TInputInterface::InputEvent *a_pEvent)
TBOOL Setup(AGameState::HUDParams *a_pHUDParams, const Params &a_rParams, TBOOL a_bShouldLocalise)
Toshi::T2DynamicVector< Toshi::TPString8 >::Iterator m_ImageIterator
Toshi::T2DynamicVector< Toshi::TPString8 > m_Images
TFLOAT m_fFadeInTime
TFLOAT m_fCurrentSlideTime
TBOOL m_bShouldLocalise
void SwitchToNextSlide(TBOOL a_bUnused=true)
static Toshi::TPString8 * LocaliseBackgroundFileName(Toshi::TPString8 &a_rOutName, const Toshi::TPString8 &a_rName)
static ALocaleManager * Interface()