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.

155 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef SCRIPTOBJECT_H
  8. #define SCRIPTOBJECT_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui_controls/Panel.h>
  13. class CPanelListPanel;
  14. #define SCRIPT_VERSION 1.0f
  15. typedef void * FileHandle_t;
  16. enum objtype_t
  17. {
  18. O_BADTYPE,
  19. O_BOOL,
  20. O_NUMBER,
  21. O_LIST,
  22. O_STRING,
  23. O_OBSOLETE,
  24. O_SLIDER,
  25. O_CATEGORY,
  26. };
  27. typedef struct
  28. {
  29. objtype_t type;
  30. char szDescription[32];
  31. } objtypedesc_t;
  32. class CScriptListItem
  33. {
  34. public:
  35. CScriptListItem();
  36. CScriptListItem( char const *strItem, char const *strValue );
  37. char szItemText[128];
  38. char szValue[256];
  39. CScriptListItem *pNext;
  40. };
  41. class CScriptObject : public vgui::Panel
  42. {
  43. public:
  44. void AddItem( CScriptListItem *pItem );
  45. void RemoveAndDeleteAllItems( void );
  46. CScriptObject( void );
  47. ~CScriptObject();
  48. bool ReadFromBuffer( const char **pBuffer, bool isNewObject );
  49. void WriteToConfig();
  50. void WriteToFile( FileHandle_t fp );
  51. void WriteToScriptFile( FileHandle_t fp );
  52. void SetCurValue( char const *strValue );
  53. objtype_t GetType( char *pszType );
  54. objtype_t type;
  55. char cvarname[64 ];
  56. char prompt[ 256 ];
  57. char tooltip[ 256 ];
  58. CScriptListItem *pListItems;
  59. float fMin, fMax;
  60. char defValue[ 128 ]; // Default value string
  61. float fdefValue; // Float version of default value.
  62. char curValue[ 128 ];
  63. float fcurValue;
  64. bool bSetInfo; // Prepend "Setinfo" to keyvalue pair in config?
  65. // Linked list of default list box items.
  66. CScriptObject *pNext;
  67. };
  68. abstract_class CDescription
  69. {
  70. public:
  71. CDescription( void );
  72. virtual ~CDescription();
  73. bool ReadFromBuffer( const char **pBuffer, bool bAllowNewObject );
  74. bool InitFromFile( const char *pszFileName, bool bAllowNewObject = true );
  75. void TransferCurrentValues( const char *pszConfigFile );
  76. void AddObject( CScriptObject *pItem );
  77. void WriteToConfig();
  78. void WriteToFile( FileHandle_t fp );
  79. void WriteToScriptFile( FileHandle_t fp );
  80. virtual void WriteScriptHeader( FileHandle_t fp ) = 0; // Clients must implement this.
  81. virtual void WriteFileHeader( FileHandle_t fp ) = 0; // Clients must implement this.
  82. void setDescription( const char *pszDesc );
  83. void setHint( const char *pszHint );
  84. const char *GetDescription( void ) { return m_pszDescriptionType; };
  85. const char *getHint( void ) { return m_pszHintText; } ;
  86. public:
  87. CScriptObject *pObjList;
  88. CScriptObject *FindObject( const char *pszObjectName );
  89. private:
  90. char *m_pszHintText;
  91. char *m_pszDescriptionType;
  92. };
  93. namespace vgui
  94. {
  95. class Label;
  96. class Panel;
  97. }
  98. class mpcontrol_t : public vgui::Panel
  99. {
  100. public:
  101. mpcontrol_t( vgui::Panel *parent, char const *panelName );
  102. virtual void OnSizeChanged( int wide, int tall ) OVERRIDE;
  103. objtype_t type;
  104. vgui::Panel *pControl;
  105. vgui::Label *pPrompt;
  106. CScriptObject *pScrObj;
  107. mpcontrol_t *next;
  108. };
  109. class CInfoDescription : public CDescription
  110. {
  111. public:
  112. CInfoDescription( void );
  113. virtual void WriteScriptHeader( FileHandle_t fp ) OVERRIDE;
  114. virtual void WriteFileHeader( FileHandle_t fp ) OVERRIDE;
  115. };
  116. void UTIL_StripInvalidCharacters( char *pszInput, int maxlen );
  117. #endif // SCRIPTOBJECT_H