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.

296 lines
7.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include <mxtk/mx.h>
  9. #include <stdio.h>
  10. #include "resource.h"
  11. #include "EventProperties.h"
  12. #include "mdlviewer.h"
  13. #include "choreoevent.h"
  14. #include "StudioModel.h"
  15. #include "faceposer_models.h"
  16. #include "KeyValues.h"
  17. static CEventParams g_Params;
  18. class CEventPropertiesGestureDialog : public CBaseEventPropertiesDialog
  19. {
  20. typedef CBaseEventPropertiesDialog BaseClass;
  21. public:
  22. virtual void InitDialog( HWND hwndDlg );
  23. virtual BOOL HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
  24. virtual void SetTitle();
  25. virtual void ShowControlsForEventType( CEventParams *params );
  26. virtual void InitControlData( CEventParams *params );
  27. private:
  28. void PopulateGestureList( HWND wnd );
  29. bool CheckSequenceType( StudioModel *model, int iSequence, char *szType );
  30. };
  31. void CEventPropertiesGestureDialog::SetTitle()
  32. {
  33. SetDialogTitle( &g_Params, "Gesture", "Gesture" );
  34. }
  35. void CEventPropertiesGestureDialog::PopulateGestureList( HWND wnd )
  36. {
  37. CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr();
  38. if (hdr)
  39. {
  40. int i;
  41. for (i = 0; i < hdr->GetNumSeq(); i++)
  42. {
  43. if (CheckSequenceType( models->GetActiveStudioModel(), i, "gesture" ))
  44. {
  45. SendMessage( wnd, CB_ADDSTRING, 0, (LPARAM)hdr->pSeqdesc(i).pszLabel() );
  46. }
  47. }
  48. for (i = 0; i < hdr->GetNumSeq(); i++)
  49. {
  50. if (CheckSequenceType( models->GetActiveStudioModel(), i, "posture" ))
  51. {
  52. SendMessage( wnd, CB_ADDSTRING, 0, (LPARAM)hdr->pSeqdesc(i).pszLabel() );
  53. }
  54. }
  55. }
  56. }
  57. void CEventPropertiesGestureDialog::InitControlData( CEventParams *params )
  58. {
  59. BaseClass::InitControlData( params );
  60. HWND choices1 = GetControl( IDC_EVENTCHOICES );
  61. SendMessage( choices1, CB_RESETCONTENT, 0, 0 );
  62. SendMessage( choices1, WM_SETTEXT , 0, (LPARAM)params->m_szParameters );
  63. SendMessage( GetControl( IDC_CHECK_SYNCTOFOLLOWINGGESTURE ), BM_SETCHECK,
  64. ( WPARAM ) g_Params.m_bSyncToFollowingGesture ? BST_CHECKED : BST_UNCHECKED,
  65. ( LPARAM )0 );
  66. PopulateGestureList( choices1 );
  67. }
  68. void CEventPropertiesGestureDialog::InitDialog( HWND hwndDlg )
  69. {
  70. m_hDialog = hwndDlg;
  71. g_Params.PositionSelf( m_hDialog );
  72. // Set working title for dialog, etc.
  73. SetTitle();
  74. // Show/Hide dialog controls
  75. ShowControlsForEventType( &g_Params );
  76. InitControlData( &g_Params );
  77. UpdateTagRadioButtons( &g_Params );
  78. SetFocus( GetControl( IDC_EVENTNAME ) );
  79. }
  80. static CEventPropertiesGestureDialog g_EventPropertiesGestureDialog;
  81. bool CEventPropertiesGestureDialog::CheckSequenceType( StudioModel *model, int iSequence, char *szType )
  82. {
  83. KeyValues *seqKeyValues = new KeyValues("");
  84. bool isType = false;
  85. if ( seqKeyValues->LoadFromBuffer( model->GetFileName( ), model->GetKeyValueText( iSequence ) ) )
  86. {
  87. // Do we have a build point section?
  88. KeyValues *pkvAllFaceposer = seqKeyValues->FindKey("faceposer");
  89. if ( pkvAllFaceposer )
  90. {
  91. KeyValues *pkvType = pkvAllFaceposer->FindKey("type");
  92. if (pkvType)
  93. {
  94. isType = (stricmp( pkvType->GetString(), szType ) == 0) ? true : false;
  95. }
  96. }
  97. }
  98. seqKeyValues->deleteThis();
  99. return isType;
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose:
  103. // Input : wnd -
  104. // *params -
  105. // Output : static
  106. //-----------------------------------------------------------------------------
  107. void CEventPropertiesGestureDialog::ShowControlsForEventType( CEventParams *params )
  108. {
  109. BaseClass::ShowControlsForEventType( params );
  110. // NULL Gesture doesn't have these controls either
  111. if ( g_Params.m_nType == CChoreoEvent::GESTURE &&
  112. !Q_stricmp( g_Params.m_szName, "NULL" ) )
  113. {
  114. ShowWindow( GetControl( IDC_EVENTNAME ), SW_HIDE );
  115. ShowWindow( GetControl( IDC_TAGS ), SW_HIDE );
  116. }
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose:
  120. // Input : hwndDlg -
  121. // uMsg -
  122. // wParam -
  123. // lParam -
  124. // Output : static BOOL CALLBACK
  125. //-----------------------------------------------------------------------------
  126. static BOOL CALLBACK EventPropertiesGestureDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  127. {
  128. return g_EventPropertiesGestureDialog.HandleMessage( hwndDlg, uMsg, wParam, lParam );
  129. };
  130. BOOL CEventPropertiesGestureDialog::HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  131. {
  132. m_hDialog = hwndDlg;
  133. bool handled = false;
  134. BOOL bret = InternalHandleMessage( &g_Params, hwndDlg, uMsg, wParam, lParam, handled );
  135. if ( handled )
  136. return bret;
  137. switch(uMsg)
  138. {
  139. case WM_PAINT:
  140. {
  141. PAINTSTRUCT ps;
  142. HDC hdc;
  143. hdc = BeginPaint(hwndDlg, &ps);
  144. DrawSpline( hdc, GetControl( IDC_STATIC_SPLINE ), g_Params.m_pEvent );
  145. EndPaint(hwndDlg, &ps);
  146. return FALSE;
  147. }
  148. break;
  149. case WM_VSCROLL:
  150. {
  151. RECT rcOut;
  152. GetSplineRect( GetControl( IDC_STATIC_SPLINE ), rcOut );
  153. InvalidateRect( hwndDlg, &rcOut, TRUE );
  154. UpdateWindow( hwndDlg );
  155. return FALSE;
  156. }
  157. break;
  158. case WM_INITDIALOG:
  159. {
  160. InitDialog( hwndDlg );
  161. }
  162. return FALSE;
  163. case WM_COMMAND:
  164. switch (LOWORD(wParam))
  165. {
  166. case IDOK:
  167. {
  168. HWND control = GetControl( IDC_EVENTCHOICES );
  169. if ( control )
  170. {
  171. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  172. }
  173. GetDlgItemText( m_hDialog, IDC_EVENTNAME, g_Params.m_szName, sizeof( g_Params.m_szName ) );
  174. if ( !g_Params.m_szName[ 0 ] )
  175. {
  176. Q_strncpy( g_Params.m_szName, g_Params.m_szParameters, sizeof( g_Params.m_szName ) );
  177. }
  178. char szTime[ 32 ];
  179. GetDlgItemText( m_hDialog, IDC_STARTTIME, szTime, sizeof( szTime ) );
  180. g_Params.m_flStartTime = atof( szTime );
  181. GetDlgItemText( m_hDialog, IDC_ENDTIME, szTime, sizeof( szTime ) );
  182. g_Params.m_flEndTime = atof( szTime );
  183. // Parse tokens from tags
  184. ParseTags( &g_Params );
  185. EndDialog( hwndDlg, 1 );
  186. }
  187. break;
  188. case IDCANCEL:
  189. EndDialog( hwndDlg, 0 );
  190. break;
  191. case IDC_CHECK_ENDTIME:
  192. {
  193. g_Params.m_bHasEndTime = SendMessage( GetControl( IDC_CHECK_ENDTIME ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  194. if ( !g_Params.m_bHasEndTime )
  195. {
  196. ShowWindow( GetControl( IDC_ENDTIME ), SW_HIDE );
  197. }
  198. else
  199. {
  200. ShowWindow( GetControl( IDC_ENDTIME ), SW_RESTORE );
  201. }
  202. }
  203. break;
  204. case IDC_CHECK_RESUMECONDITION:
  205. {
  206. g_Params.m_bResumeCondition = SendMessage( GetControl( IDC_CHECK_RESUMECONDITION ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  207. }
  208. break;
  209. case IDC_EVENTCHOICES:
  210. {
  211. HWND control = (HWND)lParam;
  212. if ( control )
  213. {
  214. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  215. }
  216. }
  217. break;
  218. case IDC_ABSOLUTESTART:
  219. {
  220. g_Params.m_bUsesTag = false;
  221. UpdateTagRadioButtons( &g_Params );
  222. }
  223. break;
  224. case IDC_RELATIVESTART:
  225. {
  226. g_Params.m_bUsesTag = true;
  227. UpdateTagRadioButtons( &g_Params );
  228. }
  229. break;
  230. case IDC_CHECK_SYNCTOFOLLOWINGGESTURE:
  231. {
  232. g_Params.m_bSyncToFollowingGesture = SendMessage( GetControl( IDC_CHECK_SYNCTOFOLLOWINGGESTURE ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  233. }
  234. break;
  235. }
  236. return TRUE;
  237. }
  238. return FALSE;
  239. }
  240. //-----------------------------------------------------------------------------
  241. // Purpose:
  242. // Input : *view -
  243. // *actor -
  244. // Output : int
  245. //-----------------------------------------------------------------------------
  246. int EventProperties_Gesture( CEventParams *params )
  247. {
  248. g_Params = *params;
  249. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  250. MAKEINTRESOURCE( IDD_EVENTPROPERTIES_GESTURE ),
  251. (HWND)g_MDLViewer->getHandle(),
  252. (DLGPROC)EventPropertiesGestureDialogProc );
  253. *params = g_Params;
  254. return retval;
  255. }