Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
6.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "basepanel.h"
  7. #include "loadgamedialog.h"
  8. #include "winlite.h"
  9. #include "vgui/ISurface.h"
  10. #include "engineinterface.h"
  11. #include "gameui_interface.h"
  12. #include "ixboxsystem.h"
  13. #include "filesystem.h"
  14. #include "savegamebrowserdialog.h"
  15. using namespace vgui;
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include <tier0/memdbgon.h>
  18. CLoadGameDialogXbox::CLoadGameDialogXbox( vgui::Panel *parent ) : BaseClass( parent )
  19. {
  20. m_bFilterAutosaves = false;
  21. }
  22. //-----------------------------------------------------------------------------
  23. // Purpose:
  24. //-----------------------------------------------------------------------------
  25. void CLoadGameDialogXbox::ApplySchemeSettings( vgui::IScheme *pScheme )
  26. {
  27. BaseClass::ApplySchemeSettings( pScheme );
  28. vgui::Label *pTitle = (Label *) FindChildByName( "TitleLabel" );
  29. if ( pTitle )
  30. {
  31. pTitle->SetText( "#GameUI_LoadGame" );
  32. }
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. //-----------------------------------------------------------------------------
  37. void CLoadGameDialogXbox::PerformSelectedAction( void )
  38. {
  39. BaseClass::PerformSelectedAction();
  40. if ( !GetNumPanels() )
  41. return;
  42. SetControlDisabled( true );
  43. // Warn the player if they're already in a map
  44. if ( !GameUI().HasSavedThisMenuSession() && GameUI().IsInLevel() && engine->GetMaxClients() == 1 )
  45. {
  46. BasePanel()->ShowMessageDialog( MD_SAVE_BEFORE_LOAD, this );
  47. }
  48. else
  49. {
  50. // Otherwise just do it
  51. OnCommand( "LoadGame" );
  52. }
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose:
  56. //-----------------------------------------------------------------------------
  57. void CLoadGameDialogXbox::PerformDeletion( void )
  58. {
  59. // Cannot delete autosaves!
  60. CGameSavePanel *pPanel = GetActivePanel();
  61. if ( pPanel == NULL || ( pPanel && pPanel->IsAutoSaveType() ) )
  62. return;
  63. BaseClass::PerformDeletion();
  64. SetControlDisabled( true );
  65. vgui::surface()->PlaySound( "UI/buttonclickrelease.wav" );
  66. BasePanel()->ShowMessageDialog( MD_DELETE_SAVE_CONFIRM, this );
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. // Input : bNewSaveSelected -
  71. //-----------------------------------------------------------------------------
  72. void CLoadGameDialogXbox::UpdateFooterOptions( void )
  73. {
  74. CFooterPanel *pFooter = GetFooterPanel();
  75. // Show available buttons
  76. pFooter->ClearButtons();
  77. // Make sure we have panels to show
  78. if ( HasActivePanels() )
  79. {
  80. pFooter->AddNewButtonLabel( "#GameUI_Load", "#GameUI_Icons_A_BUTTON" );
  81. // Don't allow deletions of autosaves!
  82. CGameSavePanel *pPanel = GetActivePanel();
  83. if ( pPanel && pPanel->IsAutoSaveType() == false )
  84. {
  85. pFooter->AddNewButtonLabel( "#GameUI_Delete", "#GameUI_Icons_X_BUTTON" );
  86. }
  87. }
  88. // Always allow storage devices changes and cancelling
  89. pFooter->AddNewButtonLabel( "#GameUI_Close", "#GameUI_Icons_B_BUTTON" );
  90. pFooter->AddNewButtonLabel( "#GameUI_Console_StorageChange", "#GameUI_Icons_Y_BUTTON" );
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose:
  94. // Input : *command -
  95. //-----------------------------------------------------------------------------
  96. void CLoadGameDialogXbox::OnCommand( const char *command )
  97. {
  98. if ( !Q_stricmp( command, "LoadGame" ) )
  99. {
  100. // Must have an active panel to perform this action
  101. if ( GetNumPanels() == 0 )
  102. {
  103. SetControlDisabled( false );
  104. return;
  105. }
  106. const SaveGameDescription_t *pSave = GetActivePanelSaveDescription();
  107. // Load the saved game
  108. char szCmd[ 256 ];
  109. Q_snprintf( szCmd, sizeof( szCmd ), "xload %s", pSave->szShortName );
  110. engine->ClientCmd_Unrestricted( szCmd );
  111. // Ignore all other input while we're open
  112. OnClose();
  113. }
  114. else if ( !Q_stricmp( command, "DeleteGame" ) )
  115. {
  116. // Must have an active panel to perform this action
  117. if ( GetNumPanels() == 0 )
  118. {
  119. SetControlDisabled( false );
  120. return;
  121. }
  122. // Delete the game they've selected
  123. const SaveGameDescription_t *pSave = GetActivePanelSaveDescription();
  124. DeleteSaveGame( pSave );
  125. RemoveActivePanel();
  126. }
  127. else if ( !Q_stricmp( command, "RefreshSaveGames" ) )
  128. {
  129. // FIXME: At this point the rug has been pulled out from undereath us!
  130. RefreshSaveGames();
  131. }
  132. else if ( !Q_stricmp( command, "LoadGameCancelled" ) )
  133. {
  134. SetControlDisabled( false );
  135. }
  136. else if ( !Q_stricmp( command, "ReleaseModalWindow" ) )
  137. {
  138. vgui::surface()->RestrictPaintToSinglePanel( NULL );
  139. }
  140. else if ( !Q_stricmp( command, "DeleteGameCancelled" ) )
  141. {
  142. SetControlDisabled( false );
  143. }
  144. else
  145. {
  146. BaseClass::OnCommand(command);
  147. }
  148. }
  149. //-----------------------------------------------------------------------------
  150. // Purpose: deletes an existing save game
  151. //-----------------------------------------------------------------------------
  152. void CLoadGameDialogXbox::DeleteSaveGame( const SaveGameDescription_t *pSaveDesc )
  153. {
  154. if ( pSaveDesc == NULL )
  155. {
  156. SetControlDisabled( false );
  157. return;
  158. }
  159. // 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
  160. if ( Q_stristr( engine->GetMostRecentSaveGame(), pSaveDesc->szShortName ) )
  161. {
  162. // We must have at least two active save games that we know about
  163. if ( GetNumPanels() > 1 )
  164. {
  165. // The panels are sorted by how recent they are, so the first element is the most recent
  166. const SaveGameDescription_t *pDesc = GetPanelSaveDecription( 0 );
  167. if ( pDesc == pSaveDesc )
  168. {
  169. // If we're deleting our most recent, we need to pick the next most recent
  170. pDesc = GetPanelSaveDecription( 1 );
  171. }
  172. // Remember this filename for the next time we need to reload
  173. if ( pDesc )
  174. {
  175. engine->SetMostRecentSaveGame( pDesc->szShortName );
  176. }
  177. }
  178. }
  179. // Delete the save game file
  180. g_pFullFileSystem->RemoveFile( pSaveDesc->szFileName, "MOD" );
  181. vgui::surface()->PlaySound( "UI/buttonclick.wav" );
  182. // Return control
  183. SetControlDisabled( false );
  184. }