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.

107 lines
3.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "loadgamedialog.h"
  8. #include "engineinterface.h"
  9. #include "vgui/ISystem.h"
  10. #include "vgui/ISurface.h"
  11. #include "vgui/IVGui.h"
  12. #include "keyvalues.h"
  13. #include "filesystem.h"
  14. #include "vgui_controls/Button.h"
  15. #include "vgui_controls/PanelListPanel.h"
  16. #include "vgui_controls/QueryBox.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. using namespace vgui;
  20. //-----------------------------------------------------------------------------
  21. // Purpose:Constructor
  22. //-----------------------------------------------------------------------------
  23. CLoadGameDialog::CLoadGameDialog(vgui::Panel *parent) : BaseClass(parent, "LoadGameDialog")
  24. {
  25. SetDeleteSelfOnClose(true);
  26. SetBounds(0, 0, 512, 384);
  27. SetMinimumSize( 256, 300 );
  28. SetSizeable( true );
  29. SetTitle("#GameUI_LoadGame", true);
  30. vgui::Button *cancel = new vgui::Button( this, "Cancel", "#GameUI_Cancel" );
  31. cancel->SetCommand( "Close" );
  32. LoadControlSettings("resource/LoadGameDialog.res");
  33. SetControlEnabled( "delete", false );
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose: Destructor
  37. //-----------------------------------------------------------------------------
  38. CLoadGameDialog::~CLoadGameDialog()
  39. {
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. void CLoadGameDialog::OnCommand( const char *command )
  45. {
  46. if ( !stricmp( command, "loadsave" ) )
  47. {
  48. int saveIndex = GetSelectedItemSaveIndex();
  49. if ( m_SaveGames.IsValidIndex(saveIndex) )
  50. {
  51. const char *shortName = m_SaveGames[saveIndex].szShortName;
  52. if ( shortName && shortName[ 0 ] )
  53. {
  54. // Load the game, return to top and switch to engine
  55. char sz[ 256 ];
  56. Q_snprintf(sz, sizeof( sz ), "progress_enable\nload %s\n", shortName );
  57. engine->ClientCmd_Unrestricted( sz );
  58. // Close this dialog
  59. OnClose();
  60. }
  61. }
  62. }
  63. else if ( !stricmp( command, "Delete" ) )
  64. {
  65. int saveIndex = GetSelectedItemSaveIndex();
  66. if ( m_SaveGames.IsValidIndex(saveIndex) )
  67. {
  68. // confirm the deletion
  69. QueryBox *box = new QueryBox( "#GameUI_ConfirmDeleteSaveGame_Title", "#GameUI_ConfirmDeleteSaveGame_Info" );
  70. box->AddActionSignalTarget(this);
  71. box->SetOKButtonText("#GameUI_ConfirmDeleteSaveGame_OK");
  72. box->SetOKCommand(new KeyValues("Command", "command", "DeleteConfirmed"));
  73. box->DoModal();
  74. }
  75. }
  76. else if ( !stricmp( command, "DeleteConfirmed" ) )
  77. {
  78. int saveIndex = GetSelectedItemSaveIndex();
  79. if ( m_SaveGames.IsValidIndex(saveIndex) )
  80. {
  81. DeleteSaveGame( m_SaveGames[saveIndex].szFileName );
  82. // reset the list
  83. ScanSavedGames();
  84. m_pGameList->MoveScrollBarToTop();
  85. }
  86. }
  87. else
  88. {
  89. BaseClass::OnCommand( command );
  90. }
  91. }