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.

342 lines
8.4 KiB

  1. //========= Copyright � 1996-2005, 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. m_ComboSequence.Clear();
  67. CMapStudioModel *pModel = GetModelHelper();
  68. if ( pModel )
  69. {
  70. // If they were on a previous animation, remember it and we'll set the combo box to that after
  71. // we tell it the list of suggestions.
  72. char txt[512];
  73. txt[0] = 0;
  74. int iSequence = pModel->GetSequence();
  75. if ( iSequence )
  76. pModel->GetSequenceName( iSequence, txt );
  77. // Set the list of suggestions.
  78. CUtlVector<CString> suggestions;
  79. int nCount = pModel->GetSequenceCount();
  80. for ( int i = 0; i < nCount; i++ )
  81. {
  82. char szName[MAX_PATH];
  83. pModel->GetSequenceName(i, szName);
  84. suggestions.AddToTail( szName );
  85. }
  86. m_ComboSequence.SetSuggestions( suggestions, 0 );
  87. m_ComboSequence.SetCurSel( iSequence );
  88. }
  89. // Reset the scroll bar
  90. InitScrollRange();
  91. }
  92. else if (Mode == LoadData)
  93. {
  94. Assert(false);
  95. }
  96. SetReadOnly( !m_bCanEdit );
  97. }
  98. BOOL COP_Model::OnSetActive()
  99. {
  100. m_bOldAnimatedModels = Options.view3d.bAnimateModels;
  101. Options.view3d.bAnimateModels = true;
  102. CMapStudioModel *pModel = GetModelHelper();
  103. if ( pModel )
  104. {
  105. m_nOldSequence = pModel->GetSequence();
  106. }
  107. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  108. if ( pDoc )
  109. {
  110. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ANIMATION|MAPVIEW_OPTIONS_CHANGED );
  111. }
  112. return CObjectPage::OnSetActive();
  113. }
  114. BOOL COP_Model::OnKillActive()
  115. {
  116. Options.view3d.bAnimateModels = m_bOldAnimatedModels;
  117. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  118. if ( pDoc )
  119. {
  120. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ANIMATION|MAPVIEW_OPTIONS_CHANGED );
  121. }
  122. return CObjectPage::OnKillActive();
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose:
  126. // Output : Returns true on success, false on failure.
  127. //-----------------------------------------------------------------------------
  128. bool COP_Model::SaveData( SaveData_Reason_t reason )
  129. {
  130. if (!IsWindow(m_hWnd))
  131. {
  132. return false;
  133. }
  134. // If we've closed the dialog or changed focus, reset the model now
  135. if ( reason == SAVEDATA_SELECTION_CHANGED || reason == SAVEDATA_CLOSE )
  136. {
  137. CMapStudioModel *pModel = GetModelHelper();
  138. if (pModel != NULL)
  139. {
  140. pModel->SetSequence( m_nOldSequence );
  141. pModel->SetFrame( 0 );
  142. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  143. if ( pDoc )
  144. {
  145. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ANIMATION );
  146. }
  147. }
  148. }
  149. return true;
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Purpose:
  153. // Input : pszClass -
  154. //-----------------------------------------------------------------------------
  155. void COP_Model::UpdateForClass(LPCTSTR pszClass)
  156. {
  157. if (!IsWindow(m_hWnd))
  158. {
  159. return;
  160. }
  161. }
  162. //-----------------------------------------------------------------------------
  163. // Purpose:
  164. // Input : flFrame -
  165. //-----------------------------------------------------------------------------
  166. void COP_Model::UpdateFrameText( int nFrame)
  167. {
  168. char szFrame[40];
  169. sprintf(szFrame, "%d", nFrame);
  170. GetDlgItem(IDC_FRAME_TEXT)->SetWindowText(szFrame);
  171. }
  172. //-----------------------------------------------------------------------------
  173. // Purpose:
  174. // Output : Returns TRUE on success, FALSE on failure.
  175. //-----------------------------------------------------------------------------
  176. BOOL COP_Model::OnInitDialog()
  177. {
  178. CObjectPage::OnInitDialog();
  179. InitScrollRange();
  180. return TRUE;
  181. }
  182. //-----------------------------------------------------------------------------
  183. // Purpose:
  184. //-----------------------------------------------------------------------------
  185. void COP_Model::InitScrollRange( void )
  186. {
  187. // Set the frame number scrollbar range
  188. int nMaxRange = FRAME_SCROLLBAR_RANGE;
  189. CMapStudioModel *pModel = GetModelHelper();
  190. if (pModel != NULL)
  191. {
  192. nMaxRange = pModel->GetMaxFrame();
  193. }
  194. // Setup the bar
  195. m_ScrollBarFrame.SetRange( 0, nMaxRange );
  196. m_ScrollBarFrame.SetPos( 0 );
  197. // Start at the zeroth frame
  198. UpdateFrameText( 0 );
  199. }
  200. //-----------------------------------------------------------------------------
  201. // Purpose:
  202. // Input : nSBCode -
  203. // nPos -
  204. // pScrollBar -
  205. //-----------------------------------------------------------------------------
  206. void COP_Model::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
  207. {
  208. if (pScrollBar == (CScrollBar *)&m_ScrollBarFrame)
  209. {
  210. if ( nSBCode == SB_ENDSCROLL )
  211. return;
  212. CMapStudioModel *pModel = GetModelHelper();
  213. if (pModel != NULL)
  214. {
  215. pModel->SetFrame( nPos );
  216. UpdateFrameText( nPos );
  217. Options.view3d.bAnimateModels = false; // Pause animations while we're scrubbing
  218. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  219. if ( pDoc )
  220. {
  221. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ANIMATION|MAPVIEW_OPTIONS_CHANGED );
  222. }
  223. }
  224. }
  225. CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
  226. }
  227. //-----------------------------------------------------------------------------
  228. // Purpose:
  229. //-----------------------------------------------------------------------------
  230. void COP_Model::OnTextChanged( const char *pText )
  231. {
  232. CMapStudioModel *pModel = GetModelHelper();
  233. if (pModel != NULL)
  234. {
  235. int iSequence = pModel->GetSequenceIndex( pText );
  236. if ( iSequence != -1 )
  237. pModel->SetSequence( iSequence );
  238. pModel->SetFrame( 0 );
  239. InitScrollRange();
  240. Options.view3d.bAnimateModels = true; // They've changed sequences, so allow animation again
  241. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  242. if ( pDoc )
  243. {
  244. pDoc->UpdateAllViews( MAPVIEW_UPDATE_ANIMATION|MAPVIEW_OPTIONS_CHANGED );
  245. }
  246. }
  247. }
  248. //-----------------------------------------------------------------------------
  249. // Purpose:
  250. //-----------------------------------------------------------------------------
  251. CMapStudioModel *COP_Model::GetModelHelper(void)
  252. {
  253. if ( m_pObjectList->Count() == 0 )
  254. return NULL;
  255. CMapClass *pObject = (CUtlReference< CMapClass >)m_pObjectList->Element( 0 );
  256. if (pObject != NULL)
  257. {
  258. CMapEntity *pEntity = dynamic_cast <CMapEntity *>(pObject);
  259. if (pEntity != NULL)
  260. {
  261. CMapStudioModel *pModel = pEntity->GetChildOfType((CMapStudioModel *)NULL);
  262. return pModel;
  263. }
  264. }
  265. return NULL;
  266. }
  267. //-----------------------------------------------------------------------------
  268. // Purpose: sets the controls to be read only
  269. // Input : bReadOnly - indicates if the controls should be read only
  270. //-----------------------------------------------------------------------------
  271. void COP_Model::SetReadOnly( bool bReadOnly )
  272. {
  273. m_ComboSequence.EnableWindow( bReadOnly ? FALSE : TRUE );
  274. m_ScrollBarFrame.EnableWindow( bReadOnly ? FALSE : TRUE );
  275. }