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.

297 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "stdafx.h"
  7. #include "hammer.h"
  8. #include "MapEntity.h"
  9. #include "MapStudioModel.h"
  10. #include "OP_Model.h"
  11. #include "ObjectProperties.h"
  12. #include "mapdoc.h"
  13. #include "options.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include <tier0/memdbgon.h>
  16. #pragma warning( disable : 4355 )
  17. IMPLEMENT_DYNCREATE(COP_Model, CObjectPage)
  18. BEGIN_MESSAGE_MAP(COP_Model, CObjectPage)
  19. //{{AFX_MSG_MAP(COP_Model)
  20. ON_WM_HSCROLL()
  21. //}}AFX_MSG_MAP
  22. END_MESSAGE_MAP()
  23. const int FRAME_SCROLLBAR_RANGE = 1000;
  24. //-----------------------------------------------------------------------------
  25. // Purpose:
  26. //-----------------------------------------------------------------------------
  27. COP_Model::COP_Model() : CObjectPage(COP_Model::IDD), m_ComboSequence( this )
  28. {
  29. //{{AFX_DATA_INIT(COP_Model)
  30. //}}AFX_DATA_INIT
  31. m_pEditObjectRuntimeClass = RUNTIME_CLASS(editCEditGameClass);
  32. m_ComboSequence.SetOnlyProvideSuggestions( true );
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. //-----------------------------------------------------------------------------
  37. COP_Model::~COP_Model()
  38. {
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Purpose:
  42. // Input : pDX -
  43. //-----------------------------------------------------------------------------
  44. void COP_Model::DoDataExchange(CDataExchange* pDX)
  45. {
  46. CObjectPage::DoDataExchange(pDX);
  47. //{{AFX_DATA_MAP(COP_Model)
  48. DDX_Control(pDX, IDC_SEQUENCE, m_ComboSequence);
  49. DDX_Control(pDX, IDC_FRAME_SCROLLBAR, m_ScrollBarFrame);
  50. //}}AFX_DATA_MAP
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. // Input : Mode -
  55. // pData -
  56. //-----------------------------------------------------------------------------
  57. void COP_Model::UpdateData( int Mode, PVOID pData, bool bCanEdit )
  58. {
  59. __super::UpdateData( Mode, pData, bCanEdit );
  60. if (!IsWindow(m_hWnd) || !pData)
  61. {
  62. return;
  63. }
  64. if (Mode == LoadFirstData)
  65. {
  66. CMapStudioModel *pModel = GetModelHelper();
  67. if ( pModel )
  68. {
  69. // If they were on a previous animation, remember it and we'll set the combo box to that after
  70. // we tell it the list of suggestions.
  71. char txt[512];
  72. txt[0] = 0;
  73. int iSequence = pModel->GetSequence();
  74. if ( iSequence )
  75. pModel->GetSequenceName( iSequence, txt );
  76. // Set the list of suggestions.
  77. CUtlVector<CString> suggestions;
  78. int nCount = pModel->GetSequenceCount();
  79. for ( int i = 0; i < nCount; i++ )
  80. {
  81. char szName[MAX_PATH];
  82. pModel->GetSequenceName(i, szName);
  83. suggestions.AddToTail( szName );
  84. }
  85. m_ComboSequence.SetSuggestions( suggestions, 0 );
  86. // Tell it to go to the last sequence the model was on.
  87. if ( txt[0] )
  88. {
  89. m_ComboSequence.SelectItem( txt );
  90. }
  91. }
  92. }
  93. else if (Mode == LoadData)
  94. {
  95. Assert(false);
  96. }
  97. SetReadOnly( !m_bCanEdit );
  98. }
  99. BOOL COP_Model::OnSetActive()
  100. {
  101. m_bOldAnimatedModels = Options.view3d.bAnimateModels;
  102. Options.view3d.bAnimateModels = true;
  103. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  104. if ( pDoc )
  105. {
  106. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ANIMATION|MAPVIEW_OPTIONS_CHANGED );
  107. }
  108. return CObjectPage::OnSetActive();
  109. }
  110. BOOL COP_Model::OnKillActive()
  111. {
  112. Options.view3d.bAnimateModels = m_bOldAnimatedModels;
  113. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  114. if ( pDoc )
  115. {
  116. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ANIMATION|MAPVIEW_OPTIONS_CHANGED );
  117. }
  118. return CObjectPage::OnKillActive();
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose:
  122. // Output : Returns true on success, false on failure.
  123. //-----------------------------------------------------------------------------
  124. bool COP_Model::SaveData(void)
  125. {
  126. if (!IsWindow(m_hWnd))
  127. {
  128. return false;
  129. }
  130. // Apply the dialog data to all the objects being edited.
  131. return true;
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Purpose:
  135. // Input : pszClass -
  136. //-----------------------------------------------------------------------------
  137. void COP_Model::UpdateForClass(LPCTSTR pszClass)
  138. {
  139. if (!IsWindow(m_hWnd))
  140. {
  141. return;
  142. }
  143. }
  144. //-----------------------------------------------------------------------------
  145. // Purpose:
  146. // Input : flFrame -
  147. //-----------------------------------------------------------------------------
  148. void COP_Model::UpdateFrameText(float flFrame)
  149. {
  150. char szFrame[40];
  151. sprintf(szFrame, "%0.2f", flFrame);
  152. GetDlgItem(IDC_FRAME_TEXT)->SetWindowText(szFrame);
  153. }
  154. //-----------------------------------------------------------------------------
  155. // Purpose:
  156. // Output : Returns TRUE on success, FALSE on failure.
  157. //-----------------------------------------------------------------------------
  158. BOOL COP_Model::OnInitDialog()
  159. {
  160. CObjectPage::OnInitDialog();
  161. //
  162. // Set the frame number scrollbar range.
  163. //
  164. m_ScrollBarFrame.SetRange(0, FRAME_SCROLLBAR_RANGE);
  165. return TRUE;
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose:
  169. // Input : nSBCode -
  170. // nPos -
  171. // pScrollBar -
  172. //-----------------------------------------------------------------------------
  173. void COP_Model::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
  174. {
  175. if (pScrollBar == (CScrollBar *)&m_ScrollBarFrame)
  176. {
  177. CMapStudioModel *pModel = GetModelHelper();
  178. if (pModel != NULL)
  179. {
  180. float flFrame = (float)nPos / (float)FRAME_SCROLLBAR_RANGE;
  181. pModel->SetFrame(flFrame);
  182. UpdateFrameText(flFrame);
  183. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  184. if ( pDoc )
  185. {
  186. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ANIMATION );
  187. }
  188. }
  189. }
  190. CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Purpose:
  194. //-----------------------------------------------------------------------------
  195. void COP_Model::OnTextChanged( const char *pText )
  196. {
  197. CMapStudioModel *pModel = GetModelHelper();
  198. if (pModel != NULL)
  199. {
  200. int iSequence = pModel->GetSequenceIndex( pText );
  201. if ( iSequence != -1 )
  202. pModel->SetSequence( iSequence );
  203. UpdateFrameText(pModel->GetFrame());
  204. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  205. if ( pDoc )
  206. {
  207. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ANIMATION );
  208. }
  209. }
  210. }
  211. //-----------------------------------------------------------------------------
  212. // Purpose:
  213. //-----------------------------------------------------------------------------
  214. CMapStudioModel *COP_Model::GetModelHelper(void)
  215. {
  216. if ( m_pObjectList->Count() == 0 )
  217. return NULL;
  218. CMapClass *pObject = m_pObjectList->Element( 0 );
  219. if (pObject != NULL)
  220. {
  221. CMapEntity *pEntity = dynamic_cast <CMapEntity *>(pObject);
  222. if (pEntity != NULL)
  223. {
  224. CMapStudioModel *pModel = pEntity->GetChildOfType((CMapStudioModel *)NULL);
  225. return pModel;
  226. }
  227. }
  228. return NULL;
  229. }
  230. //-----------------------------------------------------------------------------
  231. // Purpose: sets the controls to be read only
  232. // Input : bReadOnly - indicates if the controls should be read only
  233. //-----------------------------------------------------------------------------
  234. void COP_Model::SetReadOnly( bool bReadOnly )
  235. {
  236. m_ComboSequence.EnableWindow( bReadOnly ? FALSE : TRUE );
  237. m_ScrollBarFrame.EnableWindow( bReadOnly ? FALSE : TRUE );
  238. }