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.

240 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #if defined( REPLAY_ENABLED )
  8. #ifndef REPLAYPERFORMANCEEDITOR_H
  9. #define REPLAYPERFORMANCEEDITOR_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "vgui_controls/EditablePanel.h"
  14. #include "vgui_controls/ImagePanel.h"
  15. #include "vgui_controls/ImageList.h"
  16. #include "tf/vgui/tf_controls.h"
  17. #include "replay/replayhandle.h"
  18. #include "replay/ireplayperformanceeditor.h"
  19. #include "replay/ireplayperformancecontroller.h"
  20. //-----------------------------------------------------------------------------
  21. class CPlayerCell;
  22. class CCameraOptionsPanel;
  23. class CRecLightPanel;
  24. class CReplay;
  25. class CReplayPerformance;
  26. class CReplayTipLabel;
  27. class CSavingDialog;
  28. //-----------------------------------------------------------------------------
  29. // NOTE: Should not change order here - if you do, you need to modify g_pCamNames.
  30. enum CameraMode_t
  31. {
  32. CAM_INVALID = -1,
  33. CAM_FREE,
  34. CAM_THIRD,
  35. CAM_FIRST,
  36. COMPONENT_TIMESCALE,
  37. NCAMS
  38. };
  39. //-----------------------------------------------------------------------------
  40. class CReplayPerformanceEditorPanel : public vgui::EditablePanel,
  41. public IReplayPerformanceEditor
  42. {
  43. DECLARE_CLASS_SIMPLE( CReplayPerformanceEditorPanel, vgui::EditablePanel );
  44. public:
  45. CReplayPerformanceEditorPanel( Panel *parent, ReplayHandle_t hReplay );
  46. virtual ~CReplayPerformanceEditorPanel();
  47. virtual void ShowPanel( bool bShow );
  48. bool OnEndOfReplayReached();
  49. void OnInGameMouseWheelEvent( int nDelta );
  50. void UpdateCameraSelectionPosition( CameraMode_t nCameraMode );
  51. void UpdateFreeCamSettings( const SetViewParams_t &params );
  52. void UpdateTimeScale( float flScale );
  53. void HandleUiToggle();
  54. void Exit();
  55. void Exit_ShowDialogs();
  56. private:
  57. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  58. virtual void ApplySettings( KeyValues *pInResourceData );
  59. virtual void PerformLayout();
  60. virtual void OnCommand( const char *command );
  61. virtual void OnMouseWheeled( int nDelta );
  62. virtual void OnTick();
  63. void Achievements_Think( float flElapsed );
  64. void Achievements_OnSpaceBarPressed();
  65. void Achievements_Grant();
  66. friend class CReplayButton;
  67. friend class CSavingDialog;
  68. void SetButtonTip( wchar_t *pTipText, Panel *pContextPanel );
  69. void ShowButtonTip( bool bShow );
  70. void ShowSavingDialog();
  71. //
  72. // IReplayPerformanceEditor:
  73. //
  74. virtual CReplay *GetReplay();
  75. virtual void OnRewindComplete();
  76. // Called when the user attempts to change to a different camera, etc.
  77. // Returns true if request is immediately granted - false means the event
  78. // was queued and the user has been asked if they are OK with nuking any
  79. // changes after the current time.
  80. bool OnStateChangeRequested( const char *pEventStr );
  81. void EnsureRecording( bool bShouldSnip = true ); // Start recording now if not already doing so
  82. bool IsPaused();
  83. void UpdateCameraButtonImages( bool bForceUseUnselected = false );
  84. void LayoutPlayerCells();
  85. void SetupHighlightPanel( EditablePanel *pPanel, CPlayerCell *pPlayerCell );
  86. void UpdateTimeLabels();
  87. void ClearPlayerCellData();
  88. void HandleMouseWheel( int nDelta );
  89. private:
  90. enum ControlButtons_t
  91. {
  92. CTRLBUTTON_IN,
  93. CTRLBUTTON_GOTOBEGINNING,
  94. CTRLBUTTON_REWIND,
  95. CTRLBUTTON_PLAY,
  96. CTRLBUTTON_FF,
  97. CTRLBUTTON_GOTOEND,
  98. CTRLBUTTON_OUT,
  99. NUM_CTRLBUTTONS
  100. };
  101. CReplayPerformance *GetPerformance() const;
  102. CReplayPerformance *GetSavedPerformance() const;
  103. int GetCameraModeFromButtonIndex( CameraMode_t iCamera );
  104. void AddSetViewEvent();
  105. void AddTimeScaleEvent( float flTimeScale );
  106. void AddPanelKeyboardInputDisableList( vgui::Panel *pPanel );
  107. CameraMode_t IsMouseOverActiveCameraOptionsPanel( int nMouseX, int nMouseY );
  108. void SetOrRemoveInTick( int nTick, bool bRemoveIfSet );
  109. void SetOrRemoveOutTick( int nTick, bool bRemoveIfSet );
  110. void SetOrRemoveTick( int nTick, bool bUseInTick, bool bRemoveIfSet );
  111. void ToggleMenu();
  112. void OnMenuCommand_Save( bool bExitEditorWhenDone = false );
  113. void OnMenuCommand_SaveAs( bool bExitEditorWhenDone = false );
  114. void OnMenuCommand_Exit();
  115. void DisplaySavedTip( bool bSucceess );
  116. void OnSaveComplete();
  117. void SaveAs( const wchar_t *pTitle );
  118. void ShowRewindConfirmMessage();
  119. static void OnConfirmSaveAs( bool bShouldSave, wchar_t *pTitle, void *pContext );
  120. static void OnConfirmDestroyChanges( bool bConfirmed, void *pContext );
  121. static void OnConfirmDiscard( bool bConfirmed, void *pContext );
  122. static void OnConfirmExit( bool bConfirmed, void *pContext );
  123. static void OnConfirmRewind( bool bConfirmed, void *pContext );
  124. MESSAGE_FUNC_PARAMS( OnSliderMoved, "SliderMoved", pParams );
  125. ReplayHandle_t m_hReplay;
  126. float m_flLastTime; // Can't use gpGlobals->frametime when playback is paused
  127. float m_flOldFps;
  128. CExLabel *m_pCurTimeLabel;
  129. CExLabel *m_pTotalTimeLabel;
  130. CExLabel *m_pPlayerNameLabel;
  131. KeyValues *m_pPlayerCellData;
  132. CPlayerCell *m_pPlayerCells[2][MAX_PLAYERS+1];
  133. vgui::ImageList *m_pImageList;
  134. EditablePanel *m_pMouseTargetPanel;
  135. EditablePanel *m_pBottom;
  136. CPlayerCell *m_pCurTargetCell;
  137. CExImageButton *m_pCameraButtons[NCAMS];
  138. CExImageButton *m_pCtrlButtons[NUM_CTRLBUTTONS];
  139. float m_flTimeScaleProxy;
  140. EditablePanel *m_pPlayerCellsPanel;
  141. vgui::ImagePanel *m_pCameraSelection;
  142. CameraMode_t m_iCameraSelection; // NOTE: Indexes into some arrays
  143. CReplayTipLabel *m_pButtonTip;
  144. CSavingDialog *m_pSavingDlg;
  145. enum MenuItems_t
  146. {
  147. MENU_SAVE,
  148. MENU_SAVEAS,
  149. MENU_EXIT,
  150. NUM_MENUITEMS
  151. };
  152. CExImageButton *m_pMenuButton;
  153. vgui::Menu *m_pMenu;
  154. int m_aMenuItemIds[ NUM_MENUITEMS ];
  155. CExButton *m_pSlowMoButton;
  156. CCameraOptionsPanel *m_pCameraOptionsPanels[NCAMS];
  157. CUtlLinkedList< vgui::Panel *, int > m_lstDisableKeyboardInputPanels;
  158. int m_nRedBlueLabelRightX;
  159. int m_nBottomPanelStartY;
  160. int m_nBottomPanelHeight;
  161. int m_nRedBlueSigns[2];
  162. int m_iCurPlayerTarget;
  163. float m_flSpaceDownStart; // The time at which user started holding down space bar
  164. bool m_bSpaceDown;
  165. bool m_bSpacePressed;
  166. int m_nLastRoundedTime;
  167. bool m_bMousePressed;
  168. bool m_bMouseDown;
  169. float m_flDefaultFramerate; // host_framerate before perf editor started mucking about with it
  170. CameraMode_t m_nMouseClickedOverCameraSettingsPanel; // Allows user to drag slider outside of camera settings panel w/o the panel disappearing
  171. CRecLightPanel *m_pRecLightPanel;
  172. bool m_bShownAtLeastOnce; // Has the replay editor shown at least once? In other words, has the user hit the space bar at all yet?
  173. char m_szSuspendedEvent[128];
  174. bool m_bAchievementAwarded; // Was an achievement awarded during this editing session?
  175. float m_flLastTimeSpaceBarPressed;
  176. float m_flActiveTimeInEditor; // Will be zero'd out if user is idle (ie if they don't press space bar often enough)
  177. CPanelAnimationVarAliasType( int, m_nRightMarginWidth, "right_margin_width", "0", "proportional_xpos" );
  178. bool m_bCurrentTargetNeedsVisibilityUpdate;
  179. };
  180. //-----------------------------------------------------------------------------
  181. CReplayPerformanceEditorPanel *ReplayUI_InitPerformanceEditor( ReplayHandle_t hReplay );
  182. CReplayPerformanceEditorPanel *ReplayUI_GetPerformanceEditor();
  183. void ReplayUI_ClosePerformanceEditor();
  184. //-----------------------------------------------------------------------------
  185. #endif // REPLAYPERFORMANCEEDITOR_H
  186. #endif