Skip to content

Commit f66beea

Browse files
committed
slight refactoring
1 parent 26d2f5e commit f66beea

3 files changed

Lines changed: 170 additions & 174 deletions

File tree

src/game/client/swarm/vgui/nb_header_footer.cpp

Lines changed: 97 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static bool s_bLastReduceMotion = false;
2424

2525
CASW_Background_Movie *g_pBackgroundMovie = NULL;
2626

27-
CASW_Background_Movie* ASWBackgroundMovie()
27+
CASW_Background_Movie *ASWBackgroundMovie()
2828
{
2929
if ( !g_pBackgroundMovie )
3030
{
@@ -37,7 +37,7 @@ CASW_Background_Movie::CASW_Background_Movie()
3737
{
3838
m_nMaterialType = MATERIAL_INVALID;
3939
m_nTextureID = -1;
40-
m_szCurrentMovie[0] = 0;
40+
m_szCurrentMovie[ 0 ] = 0;
4141
m_nLastGameState = -1;
4242
}
4343

@@ -49,17 +49,17 @@ CASW_Background_Movie::~CASW_Background_Movie()
4949
void CASW_Background_Movie::SetCurrentMovie( const char *szFilename )
5050
{
5151
// Safety check as we're possibly going to overwrite a file here!
52-
char szBaseName[MAX_PATH];
53-
V_FileBase(szFilename, szBaseName, sizeof(szBaseName));
54-
const char* szAllowedExtensions[] = { "bik", "webm", nullptr };
52+
char szBaseName[ MAX_PATH ];
53+
V_FileBase( szFilename, szBaseName, sizeof( szBaseName ) );
54+
const char *szAllowedExtensions[] = { "bik", "webm", nullptr };
5555

5656
bool bValidExtension = false;
57-
const char* szExt = V_GetFileExtension(szFilename);
58-
if (szExt)
57+
const char *szExt = V_GetFileExtension( szFilename );
58+
if ( szExt )
5959
{
60-
for (int i = 0; szAllowedExtensions[i]; i++)
60+
for ( int i = 0; szAllowedExtensions[ i ]; i++ )
6161
{
62-
if (!Q_stricmp(szExt, szAllowedExtensions[i]))
62+
if ( !Q_stricmp( szExt, szAllowedExtensions[ i ] ) )
6363
{
6464
bValidExtension = true;
6565
break;
@@ -68,45 +68,45 @@ void CASW_Background_Movie::SetCurrentMovie( const char *szFilename )
6868
}
6969

7070
bool bValidPath = false;
71-
if (V_IsAbsolutePath(szFilename))
71+
if ( V_IsAbsolutePath( szFilename ) )
7272
{
73-
Warning("Absolute paths are not allowed for video files: %s\n", szFilename);
73+
Warning( "Absolute paths are not allowed for video files: %s\n", szFilename );
7474
}
7575
else
7676
{
7777
char szExpectedPrefix[] = "media/";
78-
if (!Q_strnicmp(szFilename, szExpectedPrefix, sizeof(szExpectedPrefix) - 1))
78+
if ( !Q_strnicmp( szFilename, szExpectedPrefix, sizeof( szExpectedPrefix ) - 1 ) )
7979
{
8080
bValidPath = true;
8181
}
8282
}
8383

84-
if (!bValidExtension || !bValidPath)
84+
if ( !bValidExtension || !bValidPath )
8585
{
86-
Warning("Invalid video path: %s (must be in media/ folder with .bik or .webm extension)\n", szFilename);
86+
Warning( "Invalid video path: %s (must be in media/ folder with .bik or .webm extension)\n", szFilename );
8787

88-
const char* szDefaultFiles[] = {
88+
const char *szDefaultFiles[] = {
8989
"media/BGFX_03.webm",
9090
"media/BGFX_03.bik",
9191
nullptr
9292
};
9393

94-
for (int i = 0; szDefaultFiles[i]; i++)
94+
for ( int i = 0; szDefaultFiles[ i ]; i++ )
9595
{
96-
if (g_pFullFileSystem->FileExists(szDefaultFiles[i], "GAME"))
96+
if ( g_pFullFileSystem->FileExists( szDefaultFiles[ i ], "GAME" ) )
9797
{
98-
szFilename = szDefaultFiles[i];
98+
szFilename = szDefaultFiles[ i ];
9999
break;
100100
}
101101
}
102102
}
103103

104-
szFilename = g_ReactiveDropWorkshop.GetNativeFileSystemFile(szFilename);
105-
if (Q_strcmp(m_szCurrentMovie, szFilename))
104+
szFilename = g_ReactiveDropWorkshop.GetNativeFileSystemFile( szFilename );
105+
if ( Q_strcmp( m_szCurrentMovie, szFilename ) )
106106
{
107-
if (m_nMaterialType != MATERIAL_INVALID)
107+
if ( m_nMaterialType != MATERIAL_INVALID )
108108
{
109-
switch (m_nMaterialType)
109+
switch ( m_nMaterialType )
110110
{
111111
case MATERIAL_WEBM:
112112
g_pWEBM->DestroyVideoMaterial( m_pWEBMMaterial );
@@ -119,43 +119,43 @@ void CASW_Background_Movie::SetCurrentMovie( const char *szFilename )
119119
m_nTextureID = -1;
120120
}
121121

122-
const char* ext = Q_GetFileExtension(szFilename);
123-
if (ext && !Q_stricmp(ext, "webm"))
122+
const char *ext = Q_GetFileExtension( szFilename );
123+
if ( ext && !Q_stricmp( ext, "webm" ) )
124124
{
125-
char szMaterialName[MAX_PATH];
126-
Q_snprintf(szMaterialName, sizeof(szMaterialName), "BackgroundWebMMaterial%i", g_pWEBM->GetUniqueMaterialID());
125+
char szMaterialName[ MAX_PATH ];
126+
Q_snprintf( szMaterialName, sizeof( szMaterialName ), "BackgroundWebMMaterial%i", g_pWEBM->GetUniqueMaterialID() );
127127

128128
m_pWEBMMaterial = g_pWEBM->CreateVideoMaterial(
129129
szMaterialName, szFilename, "GAME",
130130
VideoPlaybackFlags::LOOP_VIDEO | VideoPlaybackFlags::DEFAULT_MATERIAL_OPTIONS,
131-
VideoSystem::WEBM);
131+
VideoSystem::WEBM );
132132

133-
if (m_pWEBMMaterial)
133+
if ( m_pWEBMMaterial )
134134
{
135135
m_nMaterialType = MATERIAL_WEBM;
136136
m_pWEBMMaterial->StartVideo();
137137
}
138138
}
139139
else
140140
{
141-
char szMaterialName[MAX_PATH];
142-
Q_snprintf(szMaterialName, sizeof(szMaterialName), "BackgroundBIKMaterial%i", g_pBIK->GetGlobalMaterialAllocationNumber());
141+
char szMaterialName[ MAX_PATH ];
142+
Q_snprintf( szMaterialName, sizeof( szMaterialName ), "BackgroundBIKMaterial%i", g_pBIK->GetGlobalMaterialAllocationNumber() );
143143

144-
m_nBIKMaterial = bik->CreateMaterial(szMaterialName, szFilename, "GAME", BIK_LOOP);
144+
m_nBIKMaterial = bik->CreateMaterial( szMaterialName, szFilename, "GAME", BIK_LOOP );
145145
m_nMaterialType = MATERIAL_BIK;
146146
}
147147

148-
Q_snprintf(m_szCurrentMovie, sizeof(m_szCurrentMovie), "%s", szFilename);
148+
Q_snprintf( m_szCurrentMovie, sizeof( m_szCurrentMovie ), "%s", szFilename );
149149
s_bLastReduceMotion = false;
150150
}
151151
}
152152

153153

154154
void CASW_Background_Movie::ClearCurrentMovie()
155155
{
156-
if (m_nMaterialType != MATERIAL_INVALID)
156+
if ( m_nMaterialType != MATERIAL_INVALID )
157157
{
158-
switch (m_nMaterialType)
158+
switch ( m_nMaterialType )
159159
{
160160
case MATERIAL_WEBM:
161161
g_pWEBM->DestroyVideoMaterial( m_pWEBMMaterial );
@@ -171,27 +171,23 @@ void CASW_Background_Movie::ClearCurrentMovie()
171171

172172
int CASW_Background_Movie::SetTextureMaterial()
173173
{
174-
if (m_nMaterialType == MATERIAL_INVALID)
174+
if ( m_nMaterialType == MATERIAL_INVALID )
175175
return -1;
176176

177-
if (m_nTextureID == -1)
177+
if ( m_nTextureID == -1 )
178178
{
179-
m_nTextureID = g_pMatSystemSurface->CreateNewTextureID(true);
179+
m_nTextureID = g_pMatSystemSurface->CreateNewTextureID( true );
180180
}
181181

182-
switch (m_nMaterialType)
182+
switch ( m_nMaterialType )
183183
{
184184
case MATERIAL_WEBM:
185185
{
186-
IMaterial *pMaterial = m_pWEBMMaterial->GetMaterial();
187-
if ( pMaterial )
188-
{
189-
g_pMatSystemSurface->DrawSetTextureMaterial( m_nTextureID, pMaterial );
190-
}
186+
g_pMatSystemSurface->DrawSetTextureMaterial( m_nTextureID, m_pWEBMMaterial->GetMaterial() );
191187
break;
192188
}
193189
case MATERIAL_BIK:
194-
g_pMatSystemSurface->DrawSetTextureMaterial(m_nTextureID, g_pBIK->GetMaterial(m_nBIKMaterial));
190+
g_pMatSystemSurface->DrawSetTextureMaterial( m_nTextureID, g_pBIK->GetMaterial( m_nBIKMaterial ) );
195191
break;
196192
}
197193

@@ -225,7 +221,7 @@ void CASW_Background_Movie::Update( bool bForce )
225221
else
226222
{
227223
pFilename = ASWGameRules()->m_szBriefingVideo;
228-
if ( pFilename[0] == '\0' )
224+
if ( pFilename[ 0 ] == '\0' )
229225
{
230226
pFilename = NULL;
231227
}
@@ -251,10 +247,10 @@ void CASW_Background_Movie::Update( bool bForce )
251247
}
252248
}
253249

254-
if (m_nMaterialType == MATERIAL_INVALID)
250+
if ( m_nMaterialType == MATERIAL_INVALID )
255251
return;
256252

257-
switch (m_nMaterialType)
253+
switch ( m_nMaterialType )
258254
{
259255
case MATERIAL_WEBM:
260256
if ( !s_bLastReduceMotion && rd_reduce_motion.GetBool() )
@@ -275,24 +271,24 @@ void CASW_Background_Movie::Update( bool bForce )
275271
}
276272
break;
277273
case MATERIAL_BIK:
278-
if (g_pBIK->ReadyForSwap(m_nBIKMaterial))
274+
if ( g_pBIK->ReadyForSwap( m_nBIKMaterial ) )
279275
{
280-
if (g_pBIK->Update(m_nBIKMaterial) == false)
276+
if ( g_pBIK->Update( m_nBIKMaterial ) == false )
281277
{
282-
g_pBIK->DestroyMaterial(m_nBIKMaterial);
278+
g_pBIK->DestroyMaterial( m_nBIKMaterial );
283279
m_nMaterialType = MATERIAL_INVALID;
284280
}
285-
else if (!s_bLastReduceMotion && rd_reduce_motion.GetBool())
281+
else if ( !s_bLastReduceMotion && rd_reduce_motion.GetBool() )
286282
{
287283
s_bLastReduceMotion = true;
288-
bik->Pause(m_nBIKMaterial);
284+
bik->Pause( m_nBIKMaterial );
289285
}
290286
}
291287

292-
if (m_nMaterialType != MATERIAL_INVALID && s_bLastReduceMotion && !rd_reduce_motion.GetBool())
288+
if ( m_nMaterialType != MATERIAL_INVALID && s_bLastReduceMotion && !rd_reduce_motion.GetBool() )
293289
{
294290
s_bLastReduceMotion = false;
295-
bik->Unpause(m_nBIKMaterial);
291+
bik->Unpause( m_nBIKMaterial );
296292
}
297293
break;
298294
}
@@ -304,7 +300,7 @@ CNB_Header_Footer::CNB_Header_Footer( vgui::Panel *parent, const char *name ) :
304300
{
305301
// == MANAGED_MEMBER_CREATION_START: Do not edit by hand ==
306302
m_pBackground = new vgui::Panel( this, "Background" );
307-
m_pBackgroundImage = new vgui::ImagePanel( this, "BackgroundImage" );
303+
m_pBackgroundImage = new vgui::ImagePanel( this, "BackgroundImage" );
308304
m_pTitle = new vgui::Label( this, "Title", "" );
309305
m_pBottomBar = new vgui::Panel( this, "BottomBar" );
310306
m_pBottomBarLine = new vgui::Panel( this, "BottomBarLine" );
@@ -337,61 +333,61 @@ ConVar asw_background_color( "asw_background_color", "16 32 46 128", FCVAR_NONE,
337333
void CNB_Header_Footer::ApplySchemeSettings( vgui::IScheme *pScheme )
338334
{
339335
BaseClass::ApplySchemeSettings( pScheme );
340-
336+
341337
LoadControlSettings( "resource/ui/nb_header_footer.res" );
342338

343339
// TODO: Different image in widescreen to avoid stretching
344340
// this image is no longer used
345341
//m_pBackgroundImage->SetImage( "lobby/swarm_background01" );
346342

347-
switch( m_nTitleStyle )
343+
switch ( m_nTitleStyle )
348344
{
349-
case NB_TITLE_BRIGHT: m_pTitle->SetFgColor( m_TitleBrightColor ); break;
350-
case NB_TITLE_MEDIUM: m_pTitle->SetFgColor( m_TitleMediumColor ); break;
345+
case NB_TITLE_BRIGHT: m_pTitle->SetFgColor( m_TitleBrightColor ); break;
346+
case NB_TITLE_MEDIUM: m_pTitle->SetFgColor( m_TitleMediumColor ); break;
351347
}
352348

353-
switch( m_nBackgroundStyle )
349+
switch ( m_nBackgroundStyle )
354350
{
355-
case NB_BACKGROUND_DARK:
356-
{
357-
m_pBackground->SetVisible( true );
358-
m_pBackgroundImage->SetVisible( false );
359-
m_pBackground->SetBgColor( m_BackgroundColorDark );
360-
break;
361-
}
362-
case NB_BACKGROUND_TRANSPARENT_BLUE:
363-
{
364-
m_pBackground->SetVisible( true );
365-
m_pBackgroundImage->SetVisible( false );
366-
m_pBackground->SetBgColor( asw_background_color.GetColor() );
367-
break;
368-
}
369-
case NB_BACKGROUND_TRANSPARENT_RED:
370-
{
371-
m_pBackground->SetVisible( true );
372-
m_pBackgroundImage->SetVisible( false );
373-
m_pBackground->SetBgColor( m_BackgroundColorRed );
374-
break;
375-
}
376-
case NB_BACKGROUND_BLUE:
377-
{
378-
m_pBackground->SetVisible( true );
379-
m_pBackgroundImage->SetVisible( false );
380-
m_pBackground->SetBgColor( m_BackgroundColorBlue );
381-
break;
382-
}
383-
case NB_BACKGROUND_IMAGE:
384-
{
385-
m_pBackground->SetVisible( false );
386-
m_pBackgroundImage->SetVisible( true );
387-
break;
388-
}
351+
case NB_BACKGROUND_DARK:
352+
{
353+
m_pBackground->SetVisible( true );
354+
m_pBackgroundImage->SetVisible( false );
355+
m_pBackground->SetBgColor( m_BackgroundColorDark );
356+
break;
357+
}
358+
case NB_BACKGROUND_TRANSPARENT_BLUE:
359+
{
360+
m_pBackground->SetVisible( true );
361+
m_pBackgroundImage->SetVisible( false );
362+
m_pBackground->SetBgColor( asw_background_color.GetColor() );
363+
break;
364+
}
365+
case NB_BACKGROUND_TRANSPARENT_RED:
366+
{
367+
m_pBackground->SetVisible( true );
368+
m_pBackgroundImage->SetVisible( false );
369+
m_pBackground->SetBgColor( m_BackgroundColorRed );
370+
break;
371+
}
372+
case NB_BACKGROUND_BLUE:
373+
{
374+
m_pBackground->SetVisible( true );
375+
m_pBackgroundImage->SetVisible( false );
376+
m_pBackground->SetBgColor( m_BackgroundColorBlue );
377+
break;
378+
}
379+
case NB_BACKGROUND_IMAGE:
380+
{
381+
m_pBackground->SetVisible( false );
382+
m_pBackgroundImage->SetVisible( true );
383+
break;
384+
}
389385

390-
case NB_BACKGROUND_NONE:
391-
{
392-
m_pBackground->SetVisible( false );
393-
m_pBackgroundImage->SetVisible( false );
394-
}
386+
case NB_BACKGROUND_NONE:
387+
{
388+
m_pBackground->SetVisible( false );
389+
m_pBackgroundImage->SetVisible( false );
390+
}
395391
}
396392

397393
m_pTopBar->SetVisible( m_bHeaderEnabled );
@@ -510,9 +506,9 @@ void CNB_Header_Footer::PaintBackground()
510506
GetBounds( x, y, w, t );
511507

512508
// center, 16:9 aspect ratio
513-
int width_at_ratio = t * (16.0f / 9.0f);
509+
int width_at_ratio = t * ( 16.0f / 9.0f );
514510
x = ( w * 0.5f ) - ( width_at_ratio * 0.5f );
515-
511+
516512
surface()->DrawTexturedRect( x, y, x + width_at_ratio, y + t );
517513
}
518514
}

0 commit comments

Comments
 (0)