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.

436 lines
14 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef OP_ENTITY_H
  7. #define OP_ENTITY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "AutoSelCombo.h"
  12. #include "ChunkFile.h"
  13. #include "ListBoxEx.h"
  14. #include "AngleBox.h"
  15. #include "fgdlib/WCKeyValues.h"
  16. #include "MapFace.h"
  17. #include "ObjectPage.h"
  18. #include "ToolPickAngles.h"
  19. #include "ToolPickEntity.h"
  20. #include "ToolPickFace.h"
  21. #include "FilteredComboBox.h"
  22. #include "AnchorMgr.h"
  23. #include "ModelBrowser.h"
  24. #include "dlglistmanage.h"
  25. #include "particlebrowser.h"
  26. class CEditGameClass;
  27. class COP_Entity;
  28. class COP_Flags;
  29. class CMyComboBox;
  30. //-----------------------------------------------------------------------------
  31. // Owner-draw list control that uses cool colors to show
  32. // the state of items.
  33. //-----------------------------------------------------------------------------
  34. class CColoredListCtrl : public CListCtrl
  35. {
  36. public:
  37. class IItemColorCallback
  38. {
  39. public:
  40. // This is called for every item to get its colors.
  41. virtual void GetItemColor( int iItem, COLORREF *pBackgroundColor, COLORREF *pTextColor ) = 0;
  42. // This is called for every item so you can draw custom stuff in its value column.
  43. // The RECT inside the DRAWITEMSTRUCT contains the whole row, and pRect contains the rect for the value column only.
  44. // Return true if you don't want CColoredListControl to draw its value.
  45. virtual bool CustomDrawItemValue( const LPDRAWITEMSTRUCT p, const RECT *pRect ) = 0;
  46. };
  47. public:
  48. CColoredListCtrl( IItemColorCallback *pCallback );
  49. virtual void DrawItem( LPDRAWITEMSTRUCT p );
  50. private:
  51. IItemColorCallback *m_pCallback;
  52. };
  53. //-----------------------------------------------------------------------------
  54. // Purpose: A little glue object that connects the angles picker tool to our dialog.
  55. //-----------------------------------------------------------------------------
  56. class CPickAnglesTarget : public IPickAnglesTarget
  57. {
  58. public:
  59. void AttachEntityDlg(COP_Entity *pDlg) { m_pDlg = pDlg; }
  60. void OnNotifyPickAngles(const Vector &vecPos);
  61. private:
  62. COP_Entity *m_pDlg;
  63. };
  64. //-----------------------------------------------------------------------------
  65. // Purpose: A little glue object that connects the entity picker tool to our dialog.
  66. // Currently this gets the value of a given key and puts that into the smart
  67. // control.
  68. //-----------------------------------------------------------------------------
  69. class CPickEntityTarget : public IPickEntityTarget
  70. {
  71. public:
  72. inline CPickEntityTarget();
  73. void AttachEntityDlg(COP_Entity *pDlg) { m_pDlg = pDlg; }
  74. inline void SetKeyToRetrieve(const char *pszKey);
  75. void OnNotifyPickEntity(CToolPickEntity *pTool);
  76. private:
  77. char m_szKey[MAX_KEYVALUE_LEN]; // The name of the key we are going to slurp out of the entity.
  78. COP_Entity *m_pDlg; // The dialog to receive the key value.
  79. };
  80. //-----------------------------------------------------------------------------
  81. // Purpose:
  82. //-----------------------------------------------------------------------------
  83. CPickEntityTarget::CPickEntityTarget()
  84. {
  85. m_szKey[0] = '\0';
  86. m_pDlg = NULL;
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose:
  90. // Input : pszKey -
  91. //-----------------------------------------------------------------------------
  92. void CPickEntityTarget::SetKeyToRetrieve(const char *pszKey)
  93. {
  94. strncpy(m_szKey, pszKey, sizeof(m_szKey) - 1);
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose: A little glue object that connects the face picker tool to our dialog.
  98. //-----------------------------------------------------------------------------
  99. class CPickFaceTarget : public IPickFaceTarget
  100. {
  101. public:
  102. void AttachEntityDlg(COP_Entity *pDlg) { m_pDlg = pDlg; }
  103. void OnNotifyPickFace(CToolPickFace *pTool);
  104. private:
  105. COP_Entity *m_pDlg;
  106. };
  107. enum EKeyState
  108. {
  109. k_EKeyState_DefaultFGDValue=0, // This key is unmodified from its default value in the FGD.
  110. k_EKeyState_Modified=1, // This key is in the FGD, and its value has been modified.
  111. k_EKeyState_AddedManually, // This key was added manually (i.e. it does not exist in the FGD).
  112. k_EKeyState_InstanceParm,
  113. };
  114. class CInstanceParmData
  115. {
  116. public:
  117. GDinputvariable *m_ParmVariable;
  118. CString m_ParmKey;
  119. CString m_VariableName;
  120. };
  121. // This class just routes the OnTextChanged call into COP_Entity.
  122. class CSmartControlTargetNameRouter : public CFilteredComboBox::ICallbacks
  123. {
  124. public:
  125. CSmartControlTargetNameRouter( COP_Entity *pDlg );
  126. virtual void OnTextChanged( const char *pText );
  127. private:
  128. COP_Entity *m_pDlg;
  129. };
  130. class COP_Entity : public CObjectPage, CFilteredComboBox::ICallbacks, public CColoredListCtrl::IItemColorCallback, public IDlgListManageBrowse
  131. {
  132. DECLARE_DYNCREATE(COP_Entity)
  133. typedef CObjectPage BaseClass;
  134. friend int InternalSortByColumn( COP_Entity *pDlg, const char *pShortName1, const char *pShortName2, int iColumn );
  135. friend int CALLBACK SortByItemEditedState( LPARAM iItem1, LPARAM iItem2, LPARAM lpParam );
  136. friend class CColoredListCtrl;
  137. // Construction
  138. public:
  139. COP_Entity();
  140. ~COP_Entity();
  141. virtual void MarkDataDirty();
  142. //
  143. // Interface for property sheet.
  144. //
  145. virtual bool SaveData( SaveData_Reason_t reason );
  146. virtual void UpdateData( int Mode, PVOID pData, bool bCanEdit );
  147. virtual void RememberState(void);
  148. //
  149. // Interface for custom edit control.
  150. //
  151. void SetNextVar(int cmd);
  152. void SetFlagsPage( COP_Flags *pFlagsPage );
  153. void OnUpdateSpawnFlags( unsigned long preserveMask, unsigned long newValues );
  154. //{{AFX_DATA(COP_Entity)
  155. enum { IDD = IDD_OBJPAGE_ENTITYKV };
  156. CAngleCombo m_AngleEdit;
  157. CAngleCombo m_SmartAngleEdit;
  158. CEdit m_cValue;
  159. CColoredListCtrl m_VarList;
  160. CEdit m_cKey;
  161. CFilteredComboBox m_cClasses;
  162. CEdit m_Comments;
  163. CEdit m_KeyValueHelpText;
  164. CButton m_PasteControl;
  165. //}}AFX_DATA
  166. // ClassWizard generate virtual function overrides
  167. //{{AFX_VIRTUAL(COP_Entity)
  168. protected:
  169. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  170. virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
  171. //}}AFX_VIRTUAL
  172. protected:
  173. // Implementation of CFilteredComboBox::ICallbacks for m_cClasses.
  174. virtual void OnTextChanged( const char *pText );
  175. virtual bool OnUnknownEntry( const char *pText );
  176. // This gets routed from m_pSmartControl (for target names).
  177. virtual void OnSmartControlTargetNameChanged( const char *pText );
  178. // Implementation of CColoredListCtrl::IItemColorCallback.
  179. virtual void GetItemColor( int iItem, COLORREF *pBackgroundColor, COLORREF *pTextColor );
  180. virtual bool CustomDrawItemValue( const LPDRAWITEMSTRUCT p, const RECT *pRect );
  181. // Implementation of IDlgListManageBrowse
  182. virtual bool HandleBrowse( CStringList &lstBrowse );
  183. // Other functions.
  184. // If pMissingTarget is set to true, then it is a
  185. void GetKeyState( const char *pShortName, EKeyState *pState, bool *pMissingTarget );
  186. void ResortItems();
  187. void LoadClassList();
  188. void SetSmartedit(bool bSet);
  189. void RemoveBlankKeys();
  190. void EnableAnglesControl(bool bEnable);
  191. void CreateSmartControls(GDinputvariable *pVar, CUtlVector<const char *> *pHelperType);
  192. void DestroySmartControls(void);
  193. CRect CalculateSmartControlRect();
  194. void CreateSmartControls_Angle( GDinputvariable *pVar, CRect &ctrlrect, HFONT hControlFont, bool *bShowSmartAngles );
  195. void CreateSmartControls_Choices( GDinputvariable *pVar, CRect &ctrlrect, HFONT hControlFont );
  196. void CreateSmartControls_TargetName( GDinputvariable *pVar, CRect &ctrlrect, HFONT hControlFont );
  197. void CreateSmartControls_BasicEditControl( GDinputvariable *pVar, CRect &ctrlrect, HFONT hControlFont, CUtlVector<const char *> *pHelperType );
  198. void CreateSmartControls_BrowseAndPlayButtons( GDinputvariable *pVar, CRect &ctrlrect, HFONT hControlFont );
  199. void CreateSmartControls_MarkAndEyedropperButtons( GDinputvariable *pVar, CRect &ctrlrect, HFONT hControlFont );
  200. void CreateSmartControls_PickButton( GDinputvariable *pVar, CRect &ctrlrect, HFONT hControlFont );
  201. void CreateSmartControls_InstanceVariable( GDinputvariable *pVar, CRect &ctrlrect, HFONT hControlFont );
  202. void CreateSmartControls_InstanceParm( GDinputvariable *pVar, CRect &ctrlrect, HFONT hControlFont );
  203. void UpdateDisplayClass(const char *pszClass);
  204. void UpdateDisplayClass(GDclass *pClass);
  205. void UpdateEditClass(const char *pszClass, bool bForce);
  206. void UpdateKeyValue(const char *szKey, const char *szValue);
  207. virtual void UpdatePickFaceText(CToolPickFace *pTool);
  208. void GetFaceIDListsForKey(CMapFaceIDList &FullFaces, CMapFaceIDList &PartialFaces, const char *pszKey);
  209. void GetFaceListsForKey(CMapFaceList &FullFaces, CMapFaceList &PartialFaces, const char *pszKey);
  210. void ApplyKeyValueToObject(CEditGameClass *pObject, const char *pszKey, const char *pszValue);
  211. void InternalOnChangeSmartcontrol( const char *szValue );
  212. // Generated message map functions
  213. //{{AFX_MSG(COP_Entity)
  214. afx_msg void OnAddkeyvalue();
  215. afx_msg BOOL OnApply(void);
  216. afx_msg void OnBrowse(void);
  217. afx_msg void OnBrowseInstance(void);
  218. afx_msg void OnPlaySound(void);
  219. afx_msg void OnManageList(void);
  220. virtual BOOL OnInitDialog();
  221. afx_msg void OnSelchangeKeyvalues();
  222. afx_msg void OnRemovekeyvalue();
  223. afx_msg void OnSelChangeAngleEdit(void);
  224. afx_msg void OnChangeAngleedit();
  225. afx_msg void OnSmartedit();
  226. afx_msg void OnChangeKeyorValue();
  227. afx_msg void OnCopy();
  228. afx_msg void OnPaste();
  229. afx_msg void OnSetfocusKey();
  230. afx_msg void OnKillfocusKey();
  231. afx_msg LRESULT OnChangeAngleBox(WPARAM, LPARAM);
  232. afx_msg void OnChangeSmartcontrol();
  233. afx_msg void OnChangeSmartcontrolSel();
  234. afx_msg void OnChangeInstanceVariableControl();
  235. afx_msg void OnChangeInstanceParmControl();
  236. afx_msg void OnPickFaces(void);
  237. afx_msg void OnPickColor();
  238. afx_msg void OnMark();
  239. afx_msg void OnSize( UINT nType, int cx, int cy );
  240. afx_msg void OnMarkAndAdd();
  241. afx_msg void OnEntityHelp(void);
  242. afx_msg void OnPickAngles(void);
  243. afx_msg void OnPickEntity(void);
  244. afx_msg void OnCameraDistance(void);
  245. afx_msg void OnItemChangedKeyValues(NMHDR* pNMHDR, LRESULT* pResult);
  246. afx_msg void OnDblClickKeyValues(NMHDR* pNMHDR, LRESULT* pResult);
  247. //}}AFX_MSG
  248. void BrowseTextures( const char *szFilter, bool bIsSprite = false );
  249. bool BrowseModels( char *szModelName, int length, int &nSkin );
  250. bool BrowseParticles( char *szParticleSysName, int length );
  251. void MergeObjectKeyValues(CEditGameClass *pEdit);
  252. void MergeKeyValue(char const *pszKey);
  253. void SetCurKey(LPCTSTR pszKey);
  254. void GetCurKey(CString& strKey);
  255. void SetCurVarListSelection( int iSel );
  256. int GetCurVarListSelection();
  257. void OnShowPropertySheet(BOOL bShow, UINT nStatus);
  258. void StopPicking(void);
  259. DECLARE_MESSAGE_MAP()
  260. private:
  261. void UpdateAnchors();
  262. void AssignClassDefaults(GDclass *pClass, GDclass *pOldClass);
  263. int GetKeyValueRowByShortName( const char *pShortName ); // Find the row in the listctrl that the var is at. Returns -1 if not found.
  264. void RefreshKVListValues( const char *pOnlyThisVar = NULL );
  265. void PresentProperties();
  266. void ClearVarList();
  267. void SetReadOnly(bool bReadOnly);
  268. void SetSmartControlText(const char *pszText);
  269. void PerformMark(const char *pTargetName, bool bClear, bool bNameOrClass);
  270. void LoadCustomColors();
  271. void SaveCustomColors();
  272. GDinputvariable *GetVariableAt( int index );
  273. private:
  274. CAnchorMgr m_AnchorMgr;
  275. CString m_szOldKeyName;
  276. bool m_bWantSmartedit;
  277. bool m_bEnableControlUpdate; // Whether to reflect changes to the edit control into other controls.
  278. CAngleBox m_Angle;
  279. CAngleBox m_SmartAngle;
  280. CButton m_cPickColor;
  281. bool m_bSmartedit;
  282. int m_nNewKeyCount;
  283. CEdit *m_pEditInstanceVariable, *m_pEditInstanceValue, *m_pEditInstanceDefault;
  284. CMyComboBox *m_pComboInstanceParmType;
  285. // Used to prevent unnecessary calls to PresentProperties.
  286. int m_nPresentPropertiesCalls;
  287. bool m_bAllowPresentProperties;
  288. GDclass *m_pDisplayClass; // The class that the dialog is showing. Can be different from m_pEditClass
  289. // until the user hits Apply.
  290. GDinputvariable *m_pInstanceVar;
  291. short m_VarMap[GD_MAX_VARIABLES];
  292. CWnd *m_pSmartControl; // current smartedit control
  293. CButton *m_pSmartBrowseButton;
  294. CUtlVector<CWnd *> m_SmartControls;
  295. // The last variable we setup smart controls for.
  296. GDinputvariable *m_pLastSmartControlVar;
  297. CString m_LastSmartControlVarValue;
  298. CString m_strLastKey; // Active key when SaveData was called.
  299. GDclass *m_pEditClass; // The class of the object that we are editing.
  300. WCKeyValues m_kv; // Our kv storage. Holds merged keyvalues for multiselect.
  301. WCKeyValues m_kvAdded; // Corresponding keys set to value "1" if they were added
  302. GDIV_TYPE m_eEditType; // The type of the currently selected key when SmartEdit is enabled.
  303. bool m_bIgnoreKVChange; // Set to ignore Windows notifications when setting up controls.
  304. bool m_bChangingKeyName;
  305. int m_iLastClassListSolidClasses; // Used to prevent reinitializing the class list unnecessarily.
  306. bool m_bPicking; // A picking tool is currently active.
  307. ToolID_t m_ToolPrePick; // The tool that was active before we activated the picking tool.
  308. int m_iSortColumn; // Which column we're sorting the keyvalues by.
  309. CPickAnglesTarget m_PickAnglesTarget;
  310. CPickEntityTarget m_PickEntityTarget;
  311. CPickFaceTarget m_PickFaceTarget;
  312. COP_Flags *m_pFlagsPage;
  313. CSmartControlTargetNameRouter m_SmartControlTargetNameRouter;
  314. CUtlMap<CString, CInstanceParmData> m_InstanceParmData;
  315. // Used when multiselecting classes to remember whether they've selected a class
  316. // or not yet.
  317. bool m_bClassSelectionEmpty;
  318. CModelBrowser *m_pModelBrowser;
  319. CParticleBrowser *m_pParticleBrowser;
  320. friend class CPickAnglesTarget;
  321. friend class CPickEntityTarget;
  322. friend class CPickFaceTarget;
  323. friend class CSmartControlTargetNameRouter;
  324. COLORREF CustomColors[16];
  325. bool m_bCustomColorsLoaded;
  326. };
  327. // These are used to load the filesystem open dialog.
  328. void LoadFileSystemDialogModule();
  329. void UnloadFileSystemDialogModule();
  330. #endif // OP_ENTITY_H