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.

213 lines
5.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef PUBLISH_FILE_DIALOG_H
  7. #define PUBLISH_FILE_DIALOG_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include <vgui_controls/Frame.h>
  12. #include <vgui_controls/ImageList.h>
  13. #include <vgui_controls/SectionedListPanel.h>
  14. #include <vgui_controls/PHandle.h>
  15. #include <vgui_controls/BitmapImagePanel.h>
  16. #include <filesystem.h>
  17. #include "vgui/MouseCode.h"
  18. #include "vgui/IScheme.h"
  19. #include "steam/steam_api.h"
  20. #include "utlmap.h"
  21. #include "bitmap/bitmap.h"
  22. #include "workshop/ugc_utils.h"
  23. struct PublishedFileDetails_t
  24. {
  25. SteamUGCDetails_t publishedFileDetails;
  26. const char *lpszFilename;
  27. };
  28. #define APPID_PORTAL2 852
  29. using namespace vgui;
  30. class CBitmapPanel;
  31. enum FileOpenMode_t {
  32. FILEOPEN_NONE,
  33. FILEOPEN_MAIN_FILE,
  34. FILEOPEN_PREVIEW
  35. };
  36. struct EntityToTagMap_t
  37. {
  38. const char *lpszEntityName;
  39. const char *lpszTagName;
  40. const char *lpszKey;
  41. const char *lpszValue;
  42. };
  43. enum PublishedFileDetailsField_t
  44. {
  45. PFILE_FIELD_TITLE = (1<<0),
  46. PFILE_FIELD_DESCRIPTION = (1<<1),
  47. PFILE_FIELD_FILE = (1<<2),
  48. PFILE_FIELD_PREVIEW = (1<<3),
  49. };
  50. enum eFilterType_t
  51. {
  52. IMPORT_FILTER_NONE = 0,
  53. IMPORT_FILTER_COSMETIC,
  54. IMPORT_FILTER_OTHER,
  55. IMPORT_FILTER_MAP,
  56. };
  57. // TODO: Move to P2 version
  58. #define TAG_GAME_MODE_SINGLEPLAYER "Singleplayer"
  59. #define TAG_GAME_MODE_COOP "Co-Op"
  60. //
  61. // This is the size for the preview for P2 map preview images
  62. #define PREVIEW_WIDTH 225
  63. #define PREVIEW_HEIGHT 152
  64. //-----------------------------------------------------------------------------
  65. // Purpose: Main dialog for media browser
  66. //-----------------------------------------------------------------------------
  67. class CPrepareFileThread;
  68. class CFilePublishDialog : public Frame
  69. {
  70. DECLARE_CLASS_SIMPLE( CFilePublishDialog, Frame );
  71. public:
  72. enum ErrorCode_t
  73. {
  74. kNoError,
  75. kFailedToPublishFile,
  76. kFailedToUpdateFile,
  77. kFailedToPrepareFile,
  78. kSteamCloudNotAvailable,
  79. kSteamExceededCloudQuota,
  80. kFailedToWriteToSteamCloud,
  81. kFileNotFound,
  82. kNeedTitleAndDescription,
  83. kFailedFileValidation,
  84. kFailedFileTooLarge,
  85. kFailedFileNotFound,
  86. kFailedUserModifiedFile,
  87. kInvalidMapName
  88. };
  89. enum StatusCode_t
  90. {
  91. kPublishing,
  92. kUpdating,
  93. };
  94. CFilePublishDialog( Panel *parent, const char *name, PublishedFileDetails_t *pDetails );
  95. virtual ~CFilePublishDialog();
  96. virtual void PerformLayout();
  97. virtual void SetFile( const char *lpszFilename, bool bImported = false );
  98. protected:
  99. virtual void OnCommand( const char *command );
  100. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  101. virtual void OnTick( void );
  102. // Override these functions to publish files for different app types
  103. virtual ErrorCode_t ValidateFile( const char *lpszFilename );
  104. virtual AppId_t GetTargetAppID( void ) { return APPID_PORTAL2; }
  105. virtual unsigned int DesiredPreviewHeight( void ) { return PREVIEW_HEIGHT; }
  106. virtual unsigned int DesiredPreviewWidth( void ) { return PREVIEW_WIDTH; }
  107. // Decides which type to use for publishing this file
  108. virtual EWorkshopFileType WorkshipFileTypeForFile( const char *pszFileName ) { return k_EWorkshopFileTypeCommunity; }
  109. virtual bool BForceSquarePreviewImage( void ) { return false; } // Force preview images to be square
  110. virtual const char *GetPreviewFileTypes( void ) { return "*.jpg"; }
  111. virtual const char *GetPreviewFileTypeDescriptions( void ) { return "JPEG Files (*.jpg)"; }
  112. virtual const char *GetFileTypes( eFilterType_t eType = IMPORT_FILTER_NONE ) { return "*.bsp"; }
  113. virtual const char *GetFileTypeDescriptions( eFilterType_t eType = IMPORT_FILTER_NONE ) { return "BSP Files (*.bsp)"; }
  114. virtual const char *GetResFile() const { return "PublishFileDialog.res"; }
  115. virtual void ErrorMessage( ErrorCode_t errorCode, KeyValues *pkvTokens = NULL );
  116. virtual void PopulateTags( SteamParamStringArray_t &strArray ) {}
  117. virtual const char* GetStatusString( StatusCode_t statusCode );
  118. virtual void ShowStatusWindow( StatusCode_t statusCode );
  119. virtual void HideStatusWindow( void );
  120. virtual void PopulateEditFields( void );
  121. void DownloadPreviewImage( void );
  122. void SetPublishButtonState( void );
  123. bool UpdateFile( void );
  124. bool UpdateFileInternal( void );
  125. void GetPreviewFilename( char *szOut, size_t outLen );
  126. bool PublishFile();
  127. void SetPreviewImage( const char *lpszFilename );
  128. void PerformSquarize();
  129. Bitmap_t &GetPreviewBitmap();
  130. void ErrorMessage( const char *lpszText );
  131. void StartPrepareFile();
  132. void OnFilePrepared( bool bSucceeded );
  133. inline bool IsSourceImageSquare() const
  134. {
  135. // We must know the size
  136. Assert( m_imgSource.IsValid() );
  137. return
  138. m_imgSource.Width()*99 < m_imgSource.Height()*100
  139. && m_imgSource.Height()*99 < m_imgSource.Width()*100;
  140. }
  141. FileOpenMode_t m_fileOpenMode;
  142. bool m_bValidFile;
  143. bool m_bValidJpeg;
  144. CBitmapPanel *m_pCroppedTextureImagePanel;
  145. Bitmap_t m_imgSource; // original resolution and aspect
  146. Bitmap_t m_imgSquare;
  147. Bitmap_t m_imgTemp;
  148. PublishedFileId_t m_nFileID;
  149. PublishedFileDetails_t m_FileDetails;
  150. unsigned int m_nFileDetailsChanges;
  151. vgui::MessageBox *m_pStatusBox;
  152. vgui::TextEntry *m_pFileTitle;
  153. vgui::TextEntry *m_pFileDescription;
  154. vgui::Label *m_pFilename;
  155. vgui::Button *m_pPublishButton;
  156. CCallResult<CFilePublishDialog, CreateItemResult_t> m_callbackCreateItem;
  157. void Steam_OnCreateItem( CreateItemResult_t *pResult, bool bError );
  158. CCallResult<CFilePublishDialog, SubmitItemUpdateResult_t> m_callbackPublishFile;
  159. void Steam_OnPublishFile( SubmitItemUpdateResult_t *pResult, bool bError );
  160. // TODO Switch to using the auto-downloaded ISteamUGC previews
  161. CUGCFileRequest m_UGCPreviewFileRequest;
  162. bool m_bPreviewDownloadPending;
  163. bool m_bAddingNewFile;
  164. CPrepareFileThread *m_pPrepareFileThread;
  165. MESSAGE_FUNC_CHARPTR( OnFileSelected, "FileSelected", fullpath );
  166. };
  167. extern CFilePublishDialog *g_pSteamFilePublishDialog;
  168. #endif // PUBLISH_FILE_DIALOG_H