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.

192 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef SAVEGAMEBROWSERDIALOG_H
  7. #define SAVEGAMEBROWSERDIALOG_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "vgui/IScheme.h"
  12. #include "vgui/ILocalize.h"
  13. #include "vgui/ISurface.h"
  14. #include "vgui/ISystem.h"
  15. #include "vgui/IVGui.h"
  16. #include "vgui_controls/ImagePanel.h"
  17. #include "vgui_controls/KeyRepeat.h"
  18. #include "BasePanel.h"
  19. class CSaveGameBrowserDialog;
  20. using namespace vgui;
  21. //-----------------------------------------------------------------------------
  22. // Purpose: selectable item with screenshot for an individual chapter in the dialog
  23. //-----------------------------------------------------------------------------
  24. class CGameSavePanel : public vgui::EditablePanel
  25. {
  26. DECLARE_CLASS_SIMPLE( CGameSavePanel, vgui::EditablePanel );
  27. public:
  28. CGameSavePanel( CSaveGameBrowserDialog *parent, SaveGameDescription_t *pSaveDesc, bool bCommandPanel = false );
  29. ~CGameSavePanel( void );
  30. virtual void ApplySchemeSettings( IScheme *pScheme );
  31. bool IsAutoSaveType( void ) { return ( Q_stristr( m_SaveInfo.szType, "autosave" ) != 0 ); }
  32. const SaveGameDescription_t *GetSaveInfo( void ) { return ( const SaveGameDescription_t * ) &m_SaveInfo; }
  33. void SetDescription( SaveGameDescription_t *pDesc );
  34. protected:
  35. SaveGameDescription_t m_SaveInfo; // Stored internally for easy access
  36. ImagePanel *m_pLevelPicBorder;
  37. ImagePanel *m_pLevelPic;
  38. ImagePanel *m_pCommentaryIcon;
  39. Label *m_pChapterTitle;
  40. Label *m_pTime;
  41. Label *m_pElapsedTime;
  42. Label *m_pType;
  43. Color m_TextColor;
  44. Color m_DisabledColor;
  45. Color m_SelectedColor;
  46. Color m_FillColor;
  47. bool m_bNewSavePanel;
  48. };
  49. // Slot indices in new game menu
  50. #define INVALID_INDEX -1
  51. #define SLOT_OFFLEFT 0
  52. #define SLOT_LEFT 1
  53. #define SLOT_CENTER 2
  54. #define SLOT_RIGHT 3
  55. #define SLOT_OFFRIGHT 4
  56. #define NUM_SLOTS 5
  57. //-----------------------------------------------------------------------------
  58. // Purpose: Handles starting a new game, skill and chapter selection
  59. //-----------------------------------------------------------------------------
  60. class CSaveGameBrowserDialog : public vgui::Frame
  61. {
  62. DECLARE_CLASS_SIMPLE( CSaveGameBrowserDialog, vgui::Frame );
  63. public:
  64. MESSAGE_FUNC( FinishScroll, "FinishScroll" );
  65. MESSAGE_FUNC( FinishDelete, "FinishDelete" );
  66. MESSAGE_FUNC( FinishInsert, "FinishInsert" );
  67. MESSAGE_FUNC( FinishOverwriteFadeDown, "FinishOverwriteFadeDown" );
  68. MESSAGE_FUNC( CloseAfterSave, "CloseAfterSave" );
  69. CSaveGameBrowserDialog(vgui::Panel *parent );
  70. ~CSaveGameBrowserDialog();
  71. virtual void OnKeyCodePressed( vgui::KeyCode code );
  72. virtual void Activate( void );
  73. virtual void ApplySettings( KeyValues *inResourceData );
  74. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  75. virtual void OnClose( void );
  76. virtual void PaintBackground();
  77. virtual void PerformSelectedAction( void );
  78. virtual void PerformDeletion( void );
  79. virtual void UpdateFooterOptions( void );
  80. virtual void SortSaveGames( SaveGameDescription_t *pSaves, unsigned int nNumSaves );
  81. virtual void OnThink( void );
  82. virtual void OnKeyCodeReleased( vgui::KeyCode code );
  83. virtual void OnDoneScanningSaveGames( void ) {}
  84. virtual void RefreshSaveGames( void );
  85. unsigned int GetNumPanels( void ) { return m_SavePanels.Count(); }
  86. bool HasActivePanels( void ) { return ( m_SavePanels.Count() != 0 ); }
  87. CGameSavePanel *GetActivePanel( void );
  88. int GetActivePanelIndex( void ) { return m_iSelectedSave; }
  89. CFooterPanel *GetFooterPanel( void ) { return m_pFooter; }
  90. const SaveGameDescription_t *GetPanelSaveDecription( int idx ) { return ( IsValidPanel(idx) ? m_SavePanels[idx]->GetSaveInfo() : NULL ); }
  91. const SaveGameDescription_t *GetActivePanelSaveDescription( void ) { return GetPanelSaveDecription( m_iSelectedSave ); }
  92. uint GetStorageSpaceUsed( void ) { return m_nUsedStorageSpace; }
  93. void SetSelectedSaveIndex( int index );
  94. void SetSelectedSave( const char *chapter );
  95. void AddPanel( CGameSavePanel *pPanel ) { m_SavePanels.AddToHead( pPanel ); }
  96. void RemoveActivePanel( void );
  97. void AnimateInsertNewPanel( const SaveGameDescription_t *pDesc );
  98. void AnimateOverwriteActivePanel( const SaveGameDescription_t *pNewDesc );
  99. void SetControlDisabled( bool bState ) { m_bControlDisabled = bState; }
  100. // Xbox: Defined values are also used to shift the slot indices
  101. enum EScrollDirection
  102. {
  103. SCROLL_RIGHT = -1,
  104. SCROLL_NONE = 0,
  105. SCROLL_LEFT = 1
  106. };
  107. EScrollDirection m_ScrollDirection;
  108. protected:
  109. bool m_bFilterAutosaves;
  110. CKeyRepeatHandler m_KeyRepeat;
  111. bool ParseSaveData( char const *pszFileName, char const *pszShortName, SaveGameDescription_t *save );
  112. private:
  113. CUtlVector<CGameSavePanel *> m_SavePanels;
  114. int m_iSelectedSave;
  115. float m_ScrollSpeedSlow;
  116. float m_ScrollSpeedFast;
  117. int m_nDeletedPanel; // Panel being subtracted
  118. int m_nAddedPanel; // Panel being added
  119. SaveGameDescription_t m_NewSaveGameDesc; // Held for panel animations
  120. uint m_nUsedStorageSpace; // Amount of disk space used by save games
  121. vgui::Panel *m_pCenterBg;
  122. CFooterPanel *m_pFooter;
  123. // Xbox
  124. void ScrollSelectionPanels( EScrollDirection dir );
  125. void PreScroll( EScrollDirection dir );
  126. void PostScroll( EScrollDirection dir );
  127. void SetFastScroll( bool fast );
  128. void ContinueScrolling( void );
  129. void AnimateSelectionPanels( void );
  130. void ShiftPanelIndices( int offset );
  131. bool IsValidPanel( const int idx );
  132. void InitPanelIndexForDisplay( const int idx );
  133. void UpdateMenuComponents( EScrollDirection dir );
  134. void ScanSavedGames( bool bIgnoreAutosave );
  135. void LayoutPanels( void );
  136. // "No Save Games" label
  137. void ShowNoSaveGameUI( void );
  138. void HideNoSaveGameUI( void );
  139. void PerformSlideAction( int nPanelIndex, int nNextPanelIndex );
  140. void AnimateDialogStart( void );
  141. int m_nCenterBgTallDefault;
  142. int m_PanelXPos[ NUM_SLOTS ];
  143. int m_PanelYPos[ NUM_SLOTS ];
  144. float m_PanelAlpha[ NUM_SLOTS ];
  145. int m_PanelIndex[ NUM_SLOTS ];
  146. float m_ScrollSpeed;
  147. int m_ButtonPressed;
  148. int m_ScrollCt;
  149. bool m_bScrolling : 1;
  150. bool m_bSaveGameIsCorrupt : 1;
  151. bool m_bControlDisabled : 1;
  152. };
  153. #endif // SAVEGAMEBROWSERDIALOG_H