From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- gameui/LoadGameDialog.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 gameui/LoadGameDialog.cpp (limited to 'gameui/LoadGameDialog.cpp') diff --git a/gameui/LoadGameDialog.cpp b/gameui/LoadGameDialog.cpp new file mode 100644 index 0000000..0b54cb8 --- /dev/null +++ b/gameui/LoadGameDialog.cpp @@ -0,0 +1,107 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#include "LoadGameDialog.h" +#include "EngineInterface.h" + +#include "vgui/ISystem.h" +#include "vgui/ISurface.h" +#include "vgui/IVGui.h" +#include "KeyValues.h" +#include "filesystem.h" + +#include "vgui_controls/Button.h" +#include "vgui_controls/PanelListPanel.h" +#include "vgui_controls/QueryBox.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +using namespace vgui; + +//----------------------------------------------------------------------------- +// Purpose:Constructor +//----------------------------------------------------------------------------- +CLoadGameDialog::CLoadGameDialog(vgui::Panel *parent) : BaseClass(parent, "LoadGameDialog") +{ + SetDeleteSelfOnClose(true); + SetBounds(0, 0, 512, 384); + SetMinimumSize( 256, 300 ); + SetSizeable( true ); + + SetTitle("#GameUI_LoadGame", true); + + vgui::Button *cancel = new vgui::Button( this, "Cancel", "#GameUI_Cancel" ); + cancel->SetCommand( "Close" ); + + LoadControlSettings("resource/LoadGameDialog.res"); + + SetControlEnabled( "delete", false ); +} + +//----------------------------------------------------------------------------- +// Purpose: Destructor +//----------------------------------------------------------------------------- +CLoadGameDialog::~CLoadGameDialog() +{ +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CLoadGameDialog::OnCommand( const char *command ) +{ + if ( !stricmp( command, "loadsave" ) ) + { + int saveIndex = GetSelectedItemSaveIndex(); + if ( m_SaveGames.IsValidIndex(saveIndex) ) + { + const char *shortName = m_SaveGames[saveIndex].szShortName; + if ( shortName && shortName[ 0 ] ) + { + // Load the game, return to top and switch to engine + char sz[ 256 ]; + Q_snprintf(sz, sizeof( sz ), "progress_enable\nload %s\n", shortName ); + + engine->ClientCmd_Unrestricted( sz ); + + // Close this dialog + OnClose(); + } + } + } + else if ( !stricmp( command, "Delete" ) ) + { + int saveIndex = GetSelectedItemSaveIndex(); + if ( m_SaveGames.IsValidIndex(saveIndex) ) + { + // confirm the deletion + QueryBox *box = new QueryBox( "#GameUI_ConfirmDeleteSaveGame_Title", "#GameUI_ConfirmDeleteSaveGame_Info" ); + box->AddActionSignalTarget(this); + box->SetOKButtonText("#GameUI_ConfirmDeleteSaveGame_OK"); + box->SetOKCommand(new KeyValues("Command", "command", "DeleteConfirmed")); + box->DoModal(); + } + } + else if ( !stricmp( command, "DeleteConfirmed" ) ) + { + int saveIndex = GetSelectedItemSaveIndex(); + if ( m_SaveGames.IsValidIndex(saveIndex) ) + { + DeleteSaveGame( m_SaveGames[saveIndex].szFileName ); + + // reset the list + ScanSavedGames(); + m_pGameList->MoveScrollBarToTop(); + } + } + else + { + BaseClass::OnCommand( command ); + } +} + -- cgit v1.2.3