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.

241 lines
10 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: interface for the Portal2 puzzle maker within client.dll
  4. //
  5. //==========================================================================//
  6. #ifndef PUZZLEMAKER_H
  7. #define PUZZLEMAKER_H
  8. typedef unsigned long long uint64;
  9. // QT needs to think these are QStrings, and the engine needs to think these
  10. // are CUtlStrings, but we're going to define QStrings as a derived class in
  11. // puzzlemaker_internal later
  12. #if defined (QT_DLL)
  13. #define CUtlString QString
  14. #endif
  15. #define SAVE_FILE_VERSION_NUMBER 14
  16. struct PuzzleFilesInfo_t
  17. {
  18. CUtlString m_strPuzzleTitle;
  19. CUtlString m_strDescription;
  20. CUtlString m_strPuzzleFileName;
  21. CUtlString m_strMapFileName;
  22. CUtlString m_strScreenshotFileName;
  23. CUtlString m_strSteamIDPath;
  24. uint64 m_uTimeStamp_Created;
  25. uint64 m_uTimeStamp_Modified;
  26. uint64 m_uFileID;
  27. bool m_bIsCoop;
  28. };
  29. enum PuzzleCompileSteps
  30. {
  31. PUZZLE_COMPILE_NONE = 0,
  32. PUZZLE_COMPILE_EXPORT,
  33. PUZZLE_COMPILE_VBSP,
  34. PUZZLE_COMPILE_VVIS,
  35. PUZZLE_COMPILE_VRAD
  36. };
  37. enum PuzzleMakerQuitReason_t
  38. {
  39. PUZZLEMAKER_QUIT_TO_MAINMENU = 0,
  40. PUZZLEMAKER_QUIT_APPLICATION,
  41. PUZZLEMAKER_QUIT_TO_ACCEPT_COOP_INVITE
  42. };
  43. #if defined (QT_DLL)
  44. #undef CUtlString
  45. #endif
  46. #if !defined( QT_DLL ) && defined( PORTAL2_PUZZLEMAKER )
  47. #include "vgui_controls/frame.h"
  48. #include "materialsystem/materialsystemutil.h"
  49. // forward declarations
  50. enum ButtonCode_t;
  51. class CBaseGameSystem;
  52. struct GLGlobalState;
  53. class CPuzzleMakerFrame;
  54. class CPuzzleTexture;
  55. class CPuzzleModel;
  56. class QString;
  57. class IQEvent;
  58. class QKeyEvent;
  59. class CQP2EditorMainWindow;
  60. class KeyValues;
  61. class IGameEventManager2;
  62. #if defined( PUZZLEMAKER_DLL_IMPORT )
  63. // The Client DLL imports g_pPuzzleMaker from the PuzzleMaker DLL
  64. #define PUZZLEMAKER_EXPORT DLL_IMPORT
  65. #define PUZZLEMAKER_CLASS_EXPORT DLL_CLASS_IMPORT
  66. #elif defined( PUZZLEMAKER_DLL_EXPORT )
  67. // The PuzzleMaker DLL exports g_pPuzzleMaker
  68. #define PUZZLEMAKER_EXPORT DLL_EXPORT
  69. #define PUZZLEMAKER_CLASS_EXPORT DLL_CLASS_EXPORT
  70. #else
  71. // g_pPuzzleMaker is linked directly via the PuzzleMaker static LIB
  72. #define PUZZLEMAKER_EXPORT extern
  73. #define PUZZLEMAKER_CLASS_EXPORT
  74. #endif
  75. typedef void(*ScreenshotCallback_t)( const char * );
  76. //-----------------------------------------------------------------------------
  77. // IPuzzleMaker is the puzzlemaker interface for client.dll
  78. //-----------------------------------------------------------------------------
  79. abstract_class PUZZLEMAKER_CLASS_EXPORT IPuzzleMaker
  80. {
  81. public:
  82. // 'AppSystem lite' Connect function, to set up global interface pointers for the PuzzleMaker DLL:
  83. virtual void Connect( IFileSystem *_g_pFullFileSystem, IVEngineClient *_engine, IMaterialSystem *_materials, CGlobalVarsBase *_gpGlobals,
  84. IMDLCache *_g_pMDLCache, IVModelInfoClient *_modelinfo, IVModelRender *_modelrender, IStudioRender *_g_pStudioRender,
  85. vgui::ISurface *_g_pVGuiSurface, vgui::IInput *_g_pVGuiInput, vgui::IVGUILocalize *_g_pVGuiLocalize,
  86. IProcessUtils *_g_pProcessUtils, ICvar *_g_pCVar, IGameEventManager2 *_g_pGameEventManager ) = 0;
  87. // Call this from the parent frame's 'ApplySchemeSettings' to set up the puzzlemaker's UI (fonts, etc)
  88. virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) = 0;
  89. // Show/hide the puzzlemaker
  90. virtual void Show( bool bShow ) = 0;
  91. // Returns FALSE if the puzzlemaker is fully inactive (invisible), otherwise TRUE
  92. virtual bool IsVisible( void ) = 0;
  93. // Update state once per frame (only render the puzzlemaker if this returns TRUE)
  94. virtual bool FrameUpdate( bool bIgnore = false ) = 0;
  95. // Puzzlemaker render calls, in the order in which they should be called:
  96. // 1. Render the puzzlemaker's main 3D view (optionally with shadows)
  97. // 2. Render geometry to be highlighted with a screen-space glow outline
  98. // 3. Render the UI and localized UI text (call this from the parent frame's 'Paint')
  99. virtual void RenderPuzzleMaker( FlashlightState_t *pFlashlight = NULL,
  100. CTextureReference *pDepthTexture = NULL,
  101. CTextureReference *pColorTexture = NULL,
  102. VMatrix *pWorldToShadow = NULL) = 0;
  103. virtual void RenderPuzzleMakerGlow( void ) = 0;
  104. virtual void RenderPuzzleMakerUI( int xOrigin, int yOrigin ) = 0;
  105. // Should the main in-game world be rendered? (sometimes returns true even while the puzzlemaker is visible)
  106. virtual bool ShouldRenderWorld( void ) = 0;
  107. // Call this after rendering the main in-game world, so the puzzlemaker can update the full-frame texture
  108. virtual void UpdateSnapshot( ITexture *pTexture ) = 0;
  109. // Get the parameters for the shadow camera (returns FALSE if no shadows desired):
  110. virtual bool GetDepthShadowState( FlashlightState_t &flashlightState ) = 0;
  111. // Input-handling
  112. virtual void OnKeyCodeTyped( ButtonCode_t code ) = 0;
  113. virtual void OnKeyCodeReleased( ButtonCode_t code ) = 0;
  114. virtual void OnMousePressed( ButtonCode_t code ) = 0;
  115. virtual void OnMouseReleased( ButtonCode_t code ) = 0;
  116. virtual void OnMouseDoublePressed( ButtonCode_t code ) = 0;
  117. virtual void OnMouseWheeled( int delta ) = 0;
  118. virtual void OnCursorMoved( int x, int y ) = 0;
  119. // UI communication
  120. virtual void NewPuzzle( bool bFromGameMenu ) = 0;
  121. virtual void LoadPuzzle( const char *name ) = 0;
  122. virtual void SavePuzzle( bool bGenerateFileName ) = 0;
  123. virtual void CompilePuzzle( void ) = 0;
  124. virtual void CancelCompile( void ) = 0;
  125. virtual bool IsCompiling( void ) = 0;
  126. virtual void SetActive( bool bActive ) = 0;
  127. virtual bool GetActive() const = 0;
  128. virtual bool HasUnsavedChanges( void ) = 0;
  129. virtual bool HasUncompiledChanges( void ) = 0;
  130. virtual bool HasErrors( void ) = 0;
  131. virtual bool IsOverLimits( void ) = 0;
  132. virtual bool IsSaving( void ) = 0;
  133. virtual void TakeScreenshotAsync( void(*pt2Callback)( const char * ), bool bUsePuzzleName, bool bAutoSave = false ) = 0;
  134. virtual const PuzzleFilesInfo_t& GetPuzzleInfo() const = 0;
  135. virtual void SetPuzzleInfo( const PuzzleFilesInfo_t &publishInfo ) = 0;
  136. virtual bool CanShowInGameMenu( void ) = 0;
  137. virtual void RestartSounds( void ) = 0;
  138. virtual void StopSounds( void ) = 0;
  139. virtual float GetCurrentCompileProgress( int *pnFailedErrorCode, CUtlString *pstrFailedProcess, PuzzleCompileSteps *peCompileStep ) = 0;
  140. virtual void GetTagsForCurrentPuzzle( CUtlVector< const char * > &vecTags ) = 0;
  141. virtual bool RequestQuitGame( PuzzleMakerQuitReason_t reason ) = 0;
  142. virtual bool CanQuitGame( void ) = 0;
  143. virtual void QuitGame( void ) = 0;
  144. // CBaseGameSystem hooks (should be called by a wrapper gamesystem)
  145. // NOTES: PostInit must happen after all other VGui initialization (i.e after InitGameSystems).
  146. // Assets are loaded on entry to puzzlemaker mode and unloaded on exit to the main menu.
  147. virtual void PostInit( CPuzzleMakerFrame *pFrame ) = 0;
  148. virtual void LevelInitPreEntity( void ) = 0;
  149. virtual void LevelInitPostEntity( void ) = 0;
  150. virtual void LevelShutdownPostEntity( void ) = 0;
  151. virtual void Shutdown( void ) = 0;
  152. // Methods for development-only concommands (non-UI backdoors for Load/Save/Export/Compile/Publish):
  153. virtual void LoadPuzzle_Dev( const char *name ) = 0;
  154. virtual void SavePuzzle_Dev( const char *name ) = 0;
  155. virtual void ExportPuzzle_Dev( const char *name ) = 0;
  156. virtual void PublishPuzzle_Dev( void ) = 0;
  157. virtual void AutoSave_Dev( void ) = 0;
  158. virtual void UpdateSaveFileVersion( KeyValues *pKeyValues, const char* pFileName ) = 0;
  159. virtual bool IsInCoopSession( void ) = 0;
  160. };
  161. // Global puzzlemaker singleton (exported from the PuzzleMaker DLL/LIB to the client DLL):
  162. PUZZLEMAKER_EXPORT IPuzzleMaker * g_pPuzzleMaker;
  163. // Global puzzlemaker gamesystem singleton (implemented in vpuzzlemaker.cpp in the client dll)
  164. extern CBaseGameSystem* g_pPuzzleMakerGameSystem;
  165. //-----------------------------------------------------------------------------
  166. // CPuzzleMakerFrame - the fullscreen UI frame which wraps the puzzlemaker
  167. // (implemented in vpuzzlemaker.cpp in the client dll)
  168. //-----------------------------------------------------------------------------
  169. class CPuzzleMakerFrame : public vgui::Frame
  170. {
  171. DECLARE_CLASS_SIMPLE( CPuzzleMakerFrame, vgui::Frame );
  172. public:
  173. CPuzzleMakerFrame( void );
  174. virtual ~CPuzzleMakerFrame();
  175. virtual void Paint() OVERRIDE;
  176. virtual void PrecacheSound( const char *pszSoundName );
  177. virtual int PlaySoundEffect( const char *pszSoundName );
  178. virtual void StopSoundByGUID( int nGUID );
  179. protected:
  180. virtual void ApplySchemeSettings( vgui::IScheme *pScheme ) OVERRIDE;
  181. virtual void PerformLayout( void ) OVERRIDE;
  182. virtual void OnThink( void ) OVERRIDE;
  183. // Forward input events to g_pPuzzleMaker (from our parent panel):
  184. // [NOTE: MOUSE_WHEEL_UP and MOUSE_WHEEL_DOWN are received by OnMousePressed (with no associated 'release' event), OnMouseWheeled is not called]
  185. virtual void OnKeyCodeTyped( vgui::KeyCode code ) OVERRIDE { g_pPuzzleMaker->OnKeyCodeTyped( code ); }
  186. virtual void OnKeyCodeReleased( vgui::KeyCode code ) OVERRIDE { g_pPuzzleMaker->OnKeyCodeReleased( code ); }
  187. virtual void OnMousePressed( vgui::MouseCode code ) OVERRIDE { g_pPuzzleMaker->OnMousePressed( code ); }
  188. virtual void OnMouseReleased( vgui::MouseCode code ) OVERRIDE { g_pPuzzleMaker->OnMouseReleased( code ); }
  189. virtual void OnMouseDoublePressed( vgui::MouseCode code ) OVERRIDE { g_pPuzzleMaker->OnMouseDoublePressed(code ); }
  190. virtual void OnMouseWheeled( int delta ) OVERRIDE { g_pPuzzleMaker->OnMouseWheeled( delta ); }
  191. virtual void OnCursorMoved( int x, int y );
  192. // Forward the 'show' message to g_pPuzzleMaker (from our parent panel):
  193. MESSAGE_FUNC_INT( OnShow, "Show", show ) { g_pPuzzleMaker->Show( !!show ); }
  194. private:
  195. void AdjustBounds( void );
  196. bool ShadowMapPreRender( FlashlightState_t &flashlightState, CTextureReference &shadowDepthTexture, CTextureReference &shadowColorTexture, VMatrix &worldToShadow );
  197. vgui::VPANEL m_hLastFocusPanel;
  198. };
  199. #endif // PORTAL2_PUZZLEMAKER
  200. #endif // PUZZLEMAKER_H