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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "BasePanel.h"
#include "LoadGameDialog.h"
#include "winlite.h"
#include "vgui/ISurface.h"
#include "EngineInterface.h"
#include "GameUI_Interface.h"
#include "ixboxsystem.h"
#include "filesystem.h"
#include "SaveGameBrowserDialog.h"
using namespace vgui;
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
CLoadGameDialogXbox::CLoadGameDialogXbox( vgui::Panel *parent ) : BaseClass( parent )
{
m_bFilterAutosaves = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CLoadGameDialogXbox::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
vgui::Label *pTitle = (Label *) FindChildByName( "TitleLabel" );
if ( pTitle )
{
pTitle->SetText( "#GameUI_LoadGame" );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CLoadGameDialogXbox::PerformSelectedAction( void )
{
BaseClass::PerformSelectedAction();
if ( !GetNumPanels() )
return;
SetControlDisabled( true );
// Warn the player if they're already in a map
if ( !GameUI().HasSavedThisMenuSession() && GameUI().IsInLevel() && engine->GetMaxClients() == 1 )
{
BasePanel()->ShowMessageDialog( MD_SAVE_BEFORE_LOAD, this );
}
else
{
// Otherwise just do it
OnCommand( "LoadGame" );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CLoadGameDialogXbox::PerformDeletion( void )
{
// Cannot delete autosaves!
CGameSavePanel *pPanel = GetActivePanel();
if ( pPanel == NULL || ( pPanel && pPanel->IsAutoSaveType() ) )
return;
BaseClass::PerformDeletion();
SetControlDisabled( true );
vgui::surface()->PlaySound( "UI/buttonclickrelease.wav" );
BasePanel()->ShowMessageDialog( MD_DELETE_SAVE_CONFIRM, this );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : bNewSaveSelected -
//-----------------------------------------------------------------------------
void CLoadGameDialogXbox::UpdateFooterOptions( void )
{
CFooterPanel *pFooter = GetFooterPanel();
// Show available buttons
pFooter->ClearButtons();
// Make sure we have panels to show
if ( HasActivePanels() )
{
pFooter->AddNewButtonLabel( "#GameUI_Load", "#GameUI_Icons_A_BUTTON" );
// Don't allow deletions of autosaves!
CGameSavePanel *pPanel = GetActivePanel();
if ( pPanel && pPanel->IsAutoSaveType() == false )
{
pFooter->AddNewButtonLabel( "#GameUI_Delete", "#GameUI_Icons_X_BUTTON" );
}
}
// Always allow storage devices changes and cancelling
pFooter->AddNewButtonLabel( "#GameUI_Close", "#GameUI_Icons_B_BUTTON" );
pFooter->AddNewButtonLabel( "#GameUI_Console_StorageChange", "#GameUI_Icons_Y_BUTTON" );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *command -
//-----------------------------------------------------------------------------
void CLoadGameDialogXbox::OnCommand( const char *command )
{
m_KeyRepeat.Reset();
if ( !Q_stricmp( command, "LoadGame" ) )
{
// Must have an active panel to perform this action
if ( GetNumPanels() == 0 )
{
SetControlDisabled( false );
return;
}
const SaveGameDescription_t *pSave = GetActivePanelSaveDescription();
// Load the saved game
char szCmd[ 256 ];
Q_snprintf( szCmd, sizeof( szCmd ), "xload %s", pSave->szShortName );
engine->ClientCmd_Unrestricted( szCmd );
// Ignore all other input while we're open
OnClose();
}
else if ( !Q_stricmp( command, "DeleteGame" ) )
{
// Must have an active panel to perform this action
if ( GetNumPanels() == 0 )
{
SetControlDisabled( false );
return;
}
// Delete the game they've selected
const SaveGameDescription_t *pSave = GetActivePanelSaveDescription();
DeleteSaveGame( pSave );
RemoveActivePanel();
}
else if ( !Q_stricmp( command, "RefreshSaveGames" ) )
{
// FIXME: At this point the rug has been pulled out from undereath us!
RefreshSaveGames();
}
else if ( !Q_stricmp( command, "LoadGameCancelled" ) )
{
SetControlDisabled( false );
}
else if ( !Q_stricmp( command, "ReleaseModalWindow" ) )
{
vgui::surface()->RestrictPaintToSinglePanel( NULL );
}
else if ( !Q_stricmp( command, "DeleteGameCancelled" ) )
{
SetControlDisabled( false );
}
else
{
BaseClass::OnCommand(command);
}
}
//-----------------------------------------------------------------------------
// Purpose: deletes an existing save game
//-----------------------------------------------------------------------------
void CLoadGameDialogXbox::DeleteSaveGame( const SaveGameDescription_t *pSaveDesc )
{
if ( pSaveDesc == NULL )
{
SetControlDisabled( false );
return;
}
// If we're deleting our more recent save game, we need to make sure we setup the engine to properly load the last most recent
if ( Q_stristr( engine->GetMostRecentSaveGame(), pSaveDesc->szShortName ) )
{
// We must have at least two active save games that we know about
if ( GetNumPanels() > 1 )
{
// The panels are sorted by how recent they are, so the first element is the most recent
const SaveGameDescription_t *pDesc = GetPanelSaveDecription( 0 );
if ( pDesc == pSaveDesc )
{
// If we're deleting our most recent, we need to pick the next most recent
pDesc = GetPanelSaveDecription( 1 );
}
// Remember this filename for the next time we need to reload
if ( pDesc )
{
engine->SetMostRecentSaveGame( pDesc->szShortName );
}
}
}
// Delete the save game file
g_pFullFileSystem->RemoveFile( pSaveDesc->szFileName, "MOD" );
vgui::surface()->PlaySound( "UI/buttonclick.wav" );
// Return control
SetControlDisabled( false );
}
|