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.

426 lines
14 KiB

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