Team Fortress 2 Source Code as on 22/4/2020
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.

219 lines
6.0 KiB

  1. //========= Copyright 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. m_KeyRepeat.Reset();
  99. if ( !Q_stricmp( command, "LoadGame" ) )
  100. {
  101. // Must have an active panel to perform this action
  102. if ( GetNumPanels() == 0 )
  103. {
  104. SetControlDisabled( false );
  105. return;
  106. }
  107. const SaveGameDescription_t *pSave = GetActivePanelSaveDescription();
  108. // Load the saved game
  109. char szCmd[ 256 ];
  110. Q_snprintf( szCmd, sizeof( szCmd ), "xload %s", pSave->szShortName );
  111. engine->ClientCmd_Unrestricted( szCmd );
  112. // Ignore all other input while we're open
  113. OnClose();
  114. }
  115. else if ( !Q_stricmp( command, "DeleteGame" ) )
  116. {
  117. // Must have an active panel to perform this action
  118. if ( GetNumPanels() == 0 )
  119. {
  120. SetControlDisabled( false );
  121. return;
  122. }
  123. // Delete the game they've selected
  124. const SaveGameDescription_t *pSave = GetActivePanelSaveDescription();
  125. DeleteSaveGame( pSave );
  126. RemoveActivePanel();
  127. }
  128. else if ( !Q_stricmp( command, "RefreshSaveGames" ) )
  129. {
  130. // FIXME: At this point the rug has been pulled out from undereath us!
  131. RefreshSaveGames();
  132. }
  133. else if ( !Q_stricmp( command, "LoadGameCancelled" ) )
  134. {
  135. SetControlDisabled( false );
  136. }
  137. else if ( !Q_stricmp( command, "ReleaseModalWindow" ) )
  138. {
  139. vgui::surface()->RestrictPaintToSinglePanel( NULL );
  140. }
  141. else if ( !Q_stricmp( command, "DeleteGameCancelled" ) )
  142. {
  143. SetControlDisabled( false );
  144. }
  145. else
  146. {
  147. BaseClass::OnCommand(command);
  148. }
  149. }
  150. //-----------------------------------------------------------------------------
  151. // Purpose: deletes an existing save game
  152. //-----------------------------------------------------------------------------
  153. void CLoadGameDialogXbox::DeleteSaveGame( const SaveGameDescription_t *pSaveDesc )
  154. {
  155. if ( pSaveDesc == NULL )
  156. {
  157. SetControlDisabled( false );
  158. return;
  159. }
  160. // 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
  161. if ( Q_stristr( engine->GetMostRecentSaveGame(), pSaveDesc->szShortName ) )
  162. {
  163. // We must have at least two active save games that we know about
  164. if ( GetNumPanels() > 1 )
  165. {
  166. // The panels are sorted by how recent they are, so the first element is the most recent
  167. const SaveGameDescription_t *pDesc = GetPanelSaveDecription( 0 );
  168. if ( pDesc == pSaveDesc )
  169. {
  170. // If we're deleting our most recent, we need to pick the next most recent
  171. pDesc = GetPanelSaveDecription( 1 );
  172. }
  173. // Remember this filename for the next time we need to reload
  174. if ( pDesc )
  175. {
  176. engine->SetMostRecentSaveGame( pDesc->szShortName );
  177. }
  178. }
  179. }
  180. // Delete the save game file
  181. g_pFullFileSystem->RemoveFile( pSaveDesc->szFileName, "MOD" );
  182. vgui::surface()->PlaySound( "UI/buttonclick.wav" );
  183. // Return control
  184. SetControlDisabled( false );
  185. }