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.

326 lines
8.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 <commctrl.h>
  14. static CEventParams g_Params;
  15. class CEventPropertiesLookAtDialog : public CBaseEventPropertiesDialog
  16. {
  17. typedef CBaseEventPropertiesDialog BaseClass;
  18. public:
  19. virtual void InitDialog( HWND hwndDlg );
  20. virtual BOOL HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
  21. virtual void SetTitle();
  22. virtual void ShowControlsForEventType( CEventParams *params );
  23. virtual void InitControlData( CEventParams *params );
  24. private:
  25. void SetupLookAtControls( CEventParams *params );
  26. void SetPitchYawText( CEventParams *params );
  27. };
  28. void CEventPropertiesLookAtDialog::SetTitle()
  29. {
  30. SetDialogTitle( &g_Params, "LookAt", "Look At Actor" );
  31. }
  32. void CEventPropertiesLookAtDialog::SetupLookAtControls( CEventParams *params )
  33. {
  34. SetPitchYawText( params );
  35. if ( params->pitch != 0 ||
  36. params->yaw != 0 )
  37. {
  38. params->usepitchyaw = true;
  39. }
  40. else
  41. {
  42. params->usepitchyaw = false;
  43. }
  44. HWND control = GetControl( IDC_CHECK_LOOKAT );
  45. SendMessage( control, BM_SETCHECK, (WPARAM) params->usepitchyaw ? BST_CHECKED : BST_UNCHECKED, 0 );
  46. // Set up sliders
  47. control = GetControl( IDC_SLIDER_PITCH );
  48. SendMessage( control, TBM_SETRANGE, 0, (LPARAM)MAKELONG( -100, 100 ) );
  49. SendMessage( control, TBM_SETPOS, 1, (LPARAM)(LONG)params->pitch );
  50. control = GetControl( IDC_SLIDER_YAW );
  51. SendMessage( control, TBM_SETRANGE, 0, (LPARAM)MAKELONG( -100, 100 ) );
  52. SendMessage( control, TBM_SETPOS, 1, (LPARAM)(LONG)params->yaw );
  53. }
  54. void CEventPropertiesLookAtDialog::InitControlData( CEventParams *params )
  55. {
  56. SetDlgItemText( m_hDialog, IDC_STARTTIME, va( "%f", g_Params.m_flStartTime ) );
  57. SetDlgItemText( m_hDialog, IDC_ENDTIME, va( "%f", g_Params.m_flEndTime ) );
  58. SendMessage( GetControl( IDC_CHECK_ENDTIME ), BM_SETCHECK,
  59. ( WPARAM ) g_Params.m_bHasEndTime ? BST_CHECKED : BST_UNCHECKED,
  60. ( LPARAM )0 );
  61. SendMessage( GetControl( IDC_CHECK_RESUMECONDITION ), BM_SETCHECK,
  62. ( WPARAM ) g_Params.m_bResumeCondition ? BST_CHECKED : BST_UNCHECKED,
  63. ( LPARAM )0 );
  64. PopulateTagList( params );
  65. HWND choices1 = GetControl( IDC_EVENTCHOICES );
  66. SendMessage( choices1, CB_RESETCONTENT, 0, 0 );
  67. SendMessage( choices1, WM_SETTEXT , 0, (LPARAM)params->m_szParameters );
  68. SetupLookAtControls( params );
  69. PopulateNamedActorList( choices1, params );
  70. }
  71. void CEventPropertiesLookAtDialog::InitDialog( HWND hwndDlg )
  72. {
  73. m_hDialog = hwndDlg;
  74. g_Params.PositionSelf( m_hDialog );
  75. // Set working title for dialog, etc.
  76. SetTitle();
  77. // Show/Hide dialog controls
  78. ShowControlsForEventType( &g_Params );
  79. InitControlData( &g_Params );
  80. UpdateTagRadioButtons( &g_Params );
  81. SetFocus( GetControl( IDC_EVENTNAME ) );
  82. }
  83. static CEventPropertiesLookAtDialog g_EventPropertiesLookAtDialog;
  84. void CEventPropertiesLookAtDialog::SetPitchYawText( CEventParams *params )
  85. {
  86. HWND control;
  87. control = GetControl( IDC_STATIC_PITCHVAL );
  88. SendMessage( control, WM_SETTEXT , 0, (LPARAM)va( "%i", params->pitch ) );
  89. control = GetControl( IDC_STATIC_YAWVAL );
  90. SendMessage( control, WM_SETTEXT , 0, (LPARAM)va( "%i", params->yaw ) );
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose:
  94. // Input : wnd -
  95. // *params -
  96. // Output : static
  97. //-----------------------------------------------------------------------------
  98. void CEventPropertiesLookAtDialog::ShowControlsForEventType( CEventParams *params )
  99. {
  100. BaseClass::ShowControlsForEventType( params );
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Purpose:
  104. // Input : hwndDlg -
  105. // uMsg -
  106. // wParam -
  107. // lParam -
  108. // Output : static BOOL CALLBACK
  109. //-----------------------------------------------------------------------------
  110. static BOOL CALLBACK EventPropertiesLookAtDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  111. {
  112. return g_EventPropertiesLookAtDialog.HandleMessage( hwndDlg, uMsg, wParam, lParam );
  113. };
  114. BOOL CEventPropertiesLookAtDialog::HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  115. {
  116. m_hDialog = hwndDlg;
  117. bool handled = false;
  118. BOOL bret = InternalHandleMessage( &g_Params, hwndDlg, uMsg, wParam, lParam, handled );
  119. if ( handled )
  120. return bret;
  121. switch(uMsg)
  122. {
  123. case WM_PAINT:
  124. {
  125. PAINTSTRUCT ps;
  126. HDC hdc;
  127. hdc = BeginPaint(hwndDlg, &ps);
  128. DrawSpline( hdc, GetControl( IDC_STATIC_SPLINE ), g_Params.m_pEvent );
  129. EndPaint(hwndDlg, &ps);
  130. return FALSE;
  131. }
  132. break;
  133. case WM_VSCROLL:
  134. {
  135. RECT rcOut;
  136. GetSplineRect( GetControl( IDC_STATIC_SPLINE ), rcOut );
  137. InvalidateRect( hwndDlg, &rcOut, TRUE );
  138. UpdateWindow( hwndDlg );
  139. return FALSE;
  140. }
  141. break;
  142. case WM_INITDIALOG:
  143. {
  144. InitDialog( hwndDlg );
  145. }
  146. return FALSE;
  147. case WM_COMMAND:
  148. switch (LOWORD(wParam))
  149. {
  150. case IDOK:
  151. {
  152. HWND control = GetControl( IDC_EVENTCHOICES );
  153. if ( control )
  154. {
  155. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  156. }
  157. GetDlgItemText( m_hDialog, IDC_EVENTNAME, g_Params.m_szName, sizeof( g_Params.m_szName ) );
  158. if ( !g_Params.m_szName[ 0 ] )
  159. {
  160. Q_snprintf( g_Params.m_szName, sizeof( g_Params.m_szName ), "Look at %s", g_Params.m_szParameters );
  161. }
  162. char szTime[ 32 ];
  163. GetDlgItemText( m_hDialog, IDC_STARTTIME, szTime, sizeof( szTime ) );
  164. g_Params.m_flStartTime = atof( szTime );
  165. GetDlgItemText( m_hDialog, IDC_ENDTIME, szTime, sizeof( szTime ) );
  166. g_Params.m_flEndTime = atof( szTime );
  167. // Parse tokens from tags
  168. ParseTags( &g_Params );
  169. EndDialog( hwndDlg, 1 );
  170. }
  171. break;
  172. case IDCANCEL:
  173. EndDialog( hwndDlg, 0 );
  174. break;
  175. case IDC_CHECK_ENDTIME:
  176. {
  177. g_Params.m_bHasEndTime = SendMessage( GetControl( IDC_CHECK_ENDTIME ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  178. if ( !g_Params.m_bHasEndTime )
  179. {
  180. ShowWindow( GetControl( IDC_ENDTIME ), SW_HIDE );
  181. }
  182. else
  183. {
  184. ShowWindow( GetControl( IDC_ENDTIME ), SW_RESTORE );
  185. }
  186. }
  187. break;
  188. case IDC_CHECK_RESUMECONDITION:
  189. {
  190. g_Params.m_bResumeCondition = SendMessage( GetControl( IDC_CHECK_RESUMECONDITION ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  191. }
  192. break;
  193. case IDC_EVENTCHOICES:
  194. {
  195. HWND control = (HWND)lParam;
  196. if ( control )
  197. {
  198. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  199. }
  200. }
  201. break;
  202. case IDC_ABSOLUTESTART:
  203. {
  204. g_Params.m_bUsesTag = false;
  205. UpdateTagRadioButtons( &g_Params );
  206. }
  207. break;
  208. case IDC_RELATIVESTART:
  209. {
  210. g_Params.m_bUsesTag = true;
  211. UpdateTagRadioButtons( &g_Params );
  212. }
  213. break;
  214. case IDC_CHECK_LOOKAT:
  215. {
  216. HWND control = GetControl( IDC_CHECK_LOOKAT );
  217. bool checked = SendMessage( control, BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  218. if ( !checked )
  219. {
  220. g_Params.yaw = 0;
  221. g_Params.pitch = 0;
  222. SetPitchYawText( &g_Params );
  223. control = GetControl( IDC_SLIDER_PITCH );
  224. SendMessage( control, TBM_SETPOS, 1, (LPARAM)(LONG)g_Params.pitch );
  225. control = GetControl( IDC_SLIDER_YAW );
  226. SendMessage( control, TBM_SETPOS, 1, (LPARAM)(LONG)g_Params.yaw );
  227. }
  228. }
  229. break;
  230. }
  231. return TRUE;
  232. case WM_HSCROLL:
  233. {
  234. HWND control = (HWND)lParam;
  235. if ( control == GetControl( IDC_SLIDER_YAW ) ||
  236. control == GetControl( IDC_SLIDER_PITCH ) )
  237. {
  238. g_Params.yaw = (float)SendMessage( GetControl( IDC_SLIDER_YAW ), TBM_GETPOS, 0, 0 );
  239. g_Params.pitch = (float)SendMessage( GetControl( IDC_SLIDER_PITCH ), TBM_GETPOS, 0, 0 );
  240. SetPitchYawText( &g_Params );
  241. control = GetControl( IDC_CHECK_LOOKAT );
  242. if ( g_Params.pitch != 0 ||
  243. g_Params.yaw != 0 )
  244. {
  245. g_Params.usepitchyaw = true;
  246. }
  247. else
  248. {
  249. g_Params.usepitchyaw = false;
  250. }
  251. SendMessage( control, BM_SETCHECK, (WPARAM) g_Params.usepitchyaw ? BST_CHECKED : BST_UNCHECKED, 0 );
  252. return TRUE;
  253. }
  254. }
  255. return FALSE;
  256. }
  257. return FALSE;
  258. }
  259. //-----------------------------------------------------------------------------
  260. // Purpose:
  261. // Input : *view -
  262. // *actor -
  263. // Output : int
  264. //-----------------------------------------------------------------------------
  265. int EventProperties_LookAt( CEventParams *params )
  266. {
  267. g_Params = *params;
  268. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  269. MAKEINTRESOURCE( IDD_EVENTPROPERTIES_LOOKAT ),
  270. (HWND)g_MDLViewer->getHandle(),
  271. (DLGPROC)EventPropertiesLookAtDialogProc );
  272. *params = g_Params;
  273. return retval;
  274. }