summaryrefslogtreecommitdiff
path: root/gameui/SaveGameBrowserDialog.h
blob: 1e66f26e1783d15a81dd885f6077b9094f30bfe9 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef SAVEGAMEBROWSERDIALOG_H
#define SAVEGAMEBROWSERDIALOG_H
#ifdef _WIN32
#pragma once
#endif

#include "vgui/IScheme.h"
#include "vgui/ILocalize.h"
#include "vgui/ISurface.h"
#include "vgui/ISystem.h"
#include "vgui/IVGui.h"

#include "vgui_controls/ImagePanel.h"
#include "vgui_controls/KeyRepeat.h"

#include "BasePanel.h"

class CSaveGameBrowserDialog;

using namespace vgui;

//-----------------------------------------------------------------------------
// Purpose: selectable item with screenshot for an individual chapter in the dialog
//-----------------------------------------------------------------------------
class CGameSavePanel : public vgui::EditablePanel
{
	DECLARE_CLASS_SIMPLE( CGameSavePanel, vgui::EditablePanel );

public:
	
					CGameSavePanel( CSaveGameBrowserDialog *parent, SaveGameDescription_t *pSaveDesc, bool bCommandPanel = false );
					~CGameSavePanel( void );

	virtual	void	ApplySchemeSettings( IScheme *pScheme );
	
	bool IsAutoSaveType( void ) { return ( Q_stristr( m_SaveInfo.szType, "autosave" ) != 0 ); }

	const SaveGameDescription_t *GetSaveInfo( void ) { return ( const SaveGameDescription_t * ) &m_SaveInfo; }
	void SetDescription( SaveGameDescription_t *pDesc );

protected:

	SaveGameDescription_t	m_SaveInfo;	// Stored internally for easy access

	ImagePanel	*m_pLevelPicBorder;
	ImagePanel	*m_pLevelPic;
	ImagePanel	*m_pCommentaryIcon;
	Label		*m_pChapterTitle;
	Label		*m_pTime;
	Label		*m_pElapsedTime;
	Label		*m_pType;

	Color	m_TextColor;
	Color	m_DisabledColor;
	Color	m_SelectedColor;
	Color	m_FillColor;

	bool	m_bNewSavePanel;
};

// Slot indices in new game menu
#define INVALID_INDEX	-1
#define SLOT_OFFLEFT	0
#define SLOT_LEFT		1
#define SLOT_CENTER		2
#define SLOT_RIGHT		3
#define SLOT_OFFRIGHT	4
#define	NUM_SLOTS		5

//-----------------------------------------------------------------------------
// Purpose: Handles starting a new game, skill and chapter selection
//-----------------------------------------------------------------------------
class CSaveGameBrowserDialog : public vgui::Frame
{
	DECLARE_CLASS_SIMPLE( CSaveGameBrowserDialog, vgui::Frame );

public:
	MESSAGE_FUNC( FinishScroll,	"FinishScroll" );
	MESSAGE_FUNC( FinishDelete,	"FinishDelete" );
	MESSAGE_FUNC( FinishInsert,	"FinishInsert" );
	MESSAGE_FUNC( FinishOverwriteFadeDown, "FinishOverwriteFadeDown" );
	MESSAGE_FUNC( CloseAfterSave, "CloseAfterSave" );

	CSaveGameBrowserDialog(vgui::Panel *parent );
	~CSaveGameBrowserDialog();

	virtual void	OnKeyCodePressed( vgui::KeyCode code );

	virtual void	Activate( void );
	virtual void	ApplySettings( KeyValues *inResourceData );
	virtual void	ApplySchemeSettings( vgui::IScheme *pScheme );
	virtual void	OnClose( void );
	virtual void	PaintBackground();
	virtual void	PerformSelectedAction( void );
	virtual void	PerformDeletion( void );
	virtual void	UpdateFooterOptions( void );
	virtual void	SortSaveGames( SaveGameDescription_t *pSaves, unsigned int nNumSaves );
	virtual void	OnThink( void );
	virtual void	OnKeyCodeReleased( vgui::KeyCode code );
	virtual void	OnDoneScanningSaveGames( void ) {}
	virtual void	RefreshSaveGames( void );
	
	unsigned int	GetNumPanels( void ) { return m_SavePanels.Count(); }
	bool			HasActivePanels( void ) { return ( m_SavePanels.Count() != 0 ); }
	CGameSavePanel	*GetActivePanel( void );
	int				GetActivePanelIndex( void ) { return m_iSelectedSave; }
	CFooterPanel	*GetFooterPanel( void ) { return m_pFooter; }
	const SaveGameDescription_t *GetPanelSaveDecription( int idx ) { return ( IsValidPanel(idx) ? m_SavePanels[idx]->GetSaveInfo() : NULL ); }
	const SaveGameDescription_t *GetActivePanelSaveDescription( void ) { return GetPanelSaveDecription( m_iSelectedSave ); }

	uint			GetStorageSpaceUsed( void ) { return m_nUsedStorageSpace; }

	void			SetSelectedSaveIndex( int index );
	void			SetSelectedSave( const char *chapter );
	void			AddPanel( CGameSavePanel *pPanel ) { m_SavePanels.AddToHead( pPanel ); }
	
	void			RemoveActivePanel( void );
	void			AnimateInsertNewPanel( const SaveGameDescription_t *pDesc );
	void			AnimateOverwriteActivePanel( const SaveGameDescription_t *pNewDesc );

	void			SetControlDisabled( bool bState ) { m_bControlDisabled = bState; }

	// Xbox: Defined values are also used to shift the slot indices
	enum EScrollDirection
	{
		SCROLL_RIGHT	= -1,
		SCROLL_NONE		=  0,
		SCROLL_LEFT		=  1
	};
	EScrollDirection	m_ScrollDirection;

protected:

	bool				m_bFilterAutosaves;
	CKeyRepeatHandler	m_KeyRepeat;

	bool				ParseSaveData( char const *pszFileName, char const *pszShortName, SaveGameDescription_t *save );

private:
	
	CUtlVector<CGameSavePanel *>	m_SavePanels;
	int								m_iSelectedSave;
	float							m_ScrollSpeedSlow;
	float							m_ScrollSpeedFast;
	int								m_nDeletedPanel;	// Panel being subtracted
	int								m_nAddedPanel;		// Panel being added
	SaveGameDescription_t			m_NewSaveGameDesc;	// Held for panel animations
	uint							m_nUsedStorageSpace;	// Amount of disk space used by save games 
	
	vgui::Panel			*m_pCenterBg;
	CFooterPanel		*m_pFooter;

	// Xbox
	void	ScrollSelectionPanels( EScrollDirection dir );
	void	PreScroll( EScrollDirection dir );
	void	PostScroll( EScrollDirection dir );
	void	SetFastScroll( bool fast );
	void	ContinueScrolling( void );
	void	AnimateSelectionPanels( void );
	void	ShiftPanelIndices( int offset );
	bool	IsValidPanel( const int idx );
	void	InitPanelIndexForDisplay( const int idx );
	void	UpdateMenuComponents( EScrollDirection dir );
	void	ScanSavedGames( bool bIgnoreAutosave );
	void	LayoutPanels( void );
	
	// "No Save Games" label
	void	ShowNoSaveGameUI( void );
	void	HideNoSaveGameUI( void );
	void	PerformSlideAction( int nPanelIndex, int nNextPanelIndex );
	void	AnimateDialogStart( void );

	int		m_nCenterBgTallDefault;
	int		m_PanelXPos[ NUM_SLOTS ];
	int		m_PanelYPos[ NUM_SLOTS ];
	float	m_PanelAlpha[ NUM_SLOTS ];
	int		m_PanelIndex[ NUM_SLOTS ];
	float	m_ScrollSpeed;
	int		m_ButtonPressed;
	int		m_ScrollCt;
	bool	m_bScrolling : 1;
	bool	m_bSaveGameIsCorrupt : 1;
	bool	m_bControlDisabled : 1;
};


#endif // SAVEGAMEBROWSERDIALOG_H