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.

367 lines
10 KiB

  1. //========= Copyright 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 "filesystem.h"
  15. #include <commctrl.h>
  16. #include "scriplib.h"
  17. static CEventParams g_Params;
  18. class CEventPropertiesMoveToDialog : 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 PopulateMovementStyle( HWND control, CEventParams *params );
  29. void SetDistanceToTargetText( CEventParams *params );
  30. };
  31. void CEventPropertiesMoveToDialog::SetTitle()
  32. {
  33. SetDialogTitle( &g_Params, "MoveTo", "Move To Actor" );
  34. }
  35. void CEventPropertiesMoveToDialog::InitControlData( CEventParams *params )
  36. {
  37. SetDlgItemText( m_hDialog, IDC_STARTTIME, va( "%f", g_Params.m_flStartTime ) );
  38. SetDlgItemText( m_hDialog, IDC_ENDTIME, va( "%f", g_Params.m_flEndTime ) );
  39. SendMessage( GetControl( IDC_CHECK_ENDTIME ), BM_SETCHECK,
  40. ( WPARAM ) g_Params.m_bHasEndTime ? BST_CHECKED : BST_UNCHECKED,
  41. ( LPARAM )0 );
  42. SendMessage( GetControl( IDC_CHECK_RESUMECONDITION ), BM_SETCHECK,
  43. ( WPARAM ) g_Params.m_bResumeCondition ? BST_CHECKED : BST_UNCHECKED,
  44. ( LPARAM )0 );
  45. PopulateTagList( params );
  46. HWND choices1 = GetControl( IDC_EVENTCHOICES );
  47. SendMessage( choices1, CB_RESETCONTENT, 0, 0 );
  48. SendMessage( choices1, WM_SETTEXT , 0, (LPARAM)params->m_szParameters );
  49. HWND choices2 = GetControl( IDC_EVENTCHOICES2 );
  50. SendMessage( choices2, CB_RESETCONTENT, 0, 0 );
  51. SendMessage( choices2, WM_SETTEXT , 0, (LPARAM)params->m_szParameters2 );
  52. HWND choices3 = GetControl( IDC_EVENTCHOICES3 );
  53. SendMessage( choices3, CB_RESETCONTENT, 0, 0 );
  54. SendMessage( choices3, WM_SETTEXT , 0, (LPARAM)params->m_szParameters3 );
  55. HWND control = GetControl( IDC_SLIDER_DISTANCE );
  56. SendMessage( control, TBM_SETRANGE, 0, (LPARAM)MAKELONG( 0, 200 ) );
  57. SendMessage( control, TBM_SETPOS, 1, (LPARAM)(LONG)params->m_flDistanceToTarget );
  58. SendMessage( GetControl( IDC_CHECK_FORCESHORTMOVEMENT ), BM_SETCHECK,
  59. ( WPARAM ) g_Params.m_bForceShortMovement ? BST_CHECKED : BST_UNCHECKED,
  60. ( LPARAM )0 );
  61. PopulateNamedActorList( choices1, params );
  62. SendMessage( GetControl( IDC_CHOICES2PROMPT ), WM_SETTEXT, 0, (LPARAM)"Movement Style:" );
  63. PopulateMovementStyle( choices2, params );
  64. if (strlen( params->m_szParameters3 ) != 0)
  65. {
  66. // make sure blank is a valid choice
  67. SendMessage( choices3, CB_ADDSTRING, 0, (LPARAM)"" );
  68. }
  69. PopulateNamedActorList( choices3, params );
  70. SetDistanceToTargetText( params );
  71. }
  72. void CEventPropertiesMoveToDialog::InitDialog( HWND hwndDlg )
  73. {
  74. m_hDialog = hwndDlg;
  75. g_Params.PositionSelf( m_hDialog );
  76. // Set working title for dialog, etc.
  77. SetTitle();
  78. // Show/Hide dialog controls
  79. ShowControlsForEventType( &g_Params );
  80. InitControlData( &g_Params );
  81. UpdateTagRadioButtons( &g_Params );
  82. SetFocus( GetControl( IDC_EVENTNAME ) );
  83. }
  84. static CEventPropertiesMoveToDialog g_EventPropertiesMoveToDialog;
  85. void CEventPropertiesMoveToDialog::PopulateMovementStyle( HWND control, CEventParams *params )
  86. {
  87. char movement_style[ 256 ];
  88. char distance_to_target[ 256 ];
  89. movement_style[0] = 0;
  90. distance_to_target[0]= 0;
  91. ParseFromMemory( params->m_szParameters2, strlen( params->m_szParameters2 ) );
  92. if ( TokenAvailable() )
  93. {
  94. GetToken( false );
  95. strcpy( movement_style, token );
  96. if ( TokenAvailable() )
  97. {
  98. GetToken( false );
  99. strcpy( distance_to_target, token );
  100. }
  101. }
  102. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"Walk" );
  103. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"Run" );
  104. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"CrouchWalk" );
  105. SendMessage( control, WM_SETTEXT , 0, (LPARAM)movement_style );
  106. }
  107. void CEventPropertiesMoveToDialog::SetDistanceToTargetText( CEventParams *params )
  108. {
  109. HWND control;
  110. control = GetControl( IDC_STATIC_DISTANCEVAL );
  111. SendMessage( control, WM_SETTEXT , 0, (LPARAM)va( "%i", (int)params->m_flDistanceToTarget ) );
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Purpose:
  115. // Input : wnd -
  116. // *params -
  117. // Output : static
  118. //-----------------------------------------------------------------------------
  119. void CEventPropertiesMoveToDialog::ShowControlsForEventType( CEventParams *params )
  120. {
  121. BaseClass::ShowControlsForEventType( params );
  122. }
  123. //-----------------------------------------------------------------------------
  124. // Purpose:
  125. // Input : hwndDlg -
  126. // uMsg -
  127. // wParam -
  128. // lParam -
  129. // Output : static BOOL CALLBACK
  130. //-----------------------------------------------------------------------------
  131. static BOOL CALLBACK EventPropertiesMoveToDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  132. {
  133. return g_EventPropertiesMoveToDialog.HandleMessage( hwndDlg, uMsg, wParam, lParam );
  134. };
  135. BOOL CEventPropertiesMoveToDialog::HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  136. {
  137. m_hDialog = hwndDlg;
  138. bool handled = false;
  139. BOOL bret = InternalHandleMessage( &g_Params, hwndDlg, uMsg, wParam, lParam, handled );
  140. if ( handled )
  141. return bret;
  142. switch(uMsg)
  143. {
  144. case WM_PAINT:
  145. {
  146. PAINTSTRUCT ps;
  147. HDC hdc;
  148. hdc = BeginPaint(hwndDlg, &ps);
  149. DrawSpline( hdc, GetControl( IDC_STATIC_SPLINE ), g_Params.m_pEvent );
  150. EndPaint(hwndDlg, &ps);
  151. return FALSE;
  152. }
  153. break;
  154. case WM_VSCROLL:
  155. {
  156. RECT rcOut;
  157. GetSplineRect( GetControl( IDC_STATIC_SPLINE ), rcOut );
  158. InvalidateRect( hwndDlg, &rcOut, TRUE );
  159. UpdateWindow( hwndDlg );
  160. return FALSE;
  161. }
  162. break;
  163. case WM_INITDIALOG:
  164. {
  165. InitDialog( hwndDlg );
  166. }
  167. return FALSE;
  168. case WM_HSCROLL:
  169. {
  170. HWND control = (HWND)lParam;
  171. if ( control == GetControl( IDC_SLIDER_DISTANCE ))
  172. {
  173. g_Params.m_flDistanceToTarget = (float)SendMessage( GetControl( IDC_SLIDER_DISTANCE ), TBM_GETPOS, 0, 0 );
  174. SetDistanceToTargetText( &g_Params );
  175. return TRUE;
  176. }
  177. }
  178. return FALSE;
  179. case WM_COMMAND:
  180. switch (LOWORD(wParam))
  181. {
  182. case IDOK:
  183. {
  184. HWND control = GetControl( IDC_EVENTCHOICES );
  185. if ( control )
  186. {
  187. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  188. }
  189. GetDlgItemText( m_hDialog, IDC_EVENTNAME, g_Params.m_szName, sizeof( g_Params.m_szName ) );
  190. if ( !g_Params.m_szName[ 0 ] )
  191. {
  192. Q_snprintf( g_Params.m_szName, sizeof( g_Params.m_szName ), "Moveto %s", g_Params.m_szParameters );
  193. }
  194. char szTime[ 32 ];
  195. GetDlgItemText( m_hDialog, IDC_STARTTIME, szTime, sizeof( szTime ) );
  196. g_Params.m_flStartTime = atof( szTime );
  197. GetDlgItemText( m_hDialog, IDC_ENDTIME, szTime, sizeof( szTime ) );
  198. g_Params.m_flEndTime = atof( szTime );
  199. // Parse tokens from tags
  200. ParseTags( &g_Params );
  201. EndDialog( hwndDlg, 1 );
  202. }
  203. break;
  204. case IDCANCEL:
  205. EndDialog( hwndDlg, 0 );
  206. break;
  207. case IDC_CHECK_ENDTIME:
  208. {
  209. g_Params.m_bHasEndTime = SendMessage( GetControl( IDC_CHECK_ENDTIME ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  210. if ( !g_Params.m_bHasEndTime )
  211. {
  212. ShowWindow( GetControl( IDC_ENDTIME ), SW_HIDE );
  213. }
  214. else
  215. {
  216. ShowWindow( GetControl( IDC_ENDTIME ), SW_RESTORE );
  217. }
  218. }
  219. break;
  220. case IDC_CHECK_RESUMECONDITION:
  221. {
  222. g_Params.m_bResumeCondition = SendMessage( GetControl( IDC_CHECK_RESUMECONDITION ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  223. }
  224. break;
  225. case IDC_EVENTCHOICES:
  226. {
  227. HWND control = (HWND)lParam;
  228. if ( control )
  229. {
  230. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  231. }
  232. }
  233. break;
  234. case IDC_EVENTCHOICES2:
  235. {
  236. HWND control = (HWND)lParam;
  237. if ( control )
  238. {
  239. if ( g_Params.m_nType != CChoreoEvent::MOVETO )
  240. {
  241. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters2 ), (LPARAM)g_Params.m_szParameters2 );
  242. }
  243. else
  244. {
  245. char buf1[ 256 ];
  246. SendMessage( GetControl( IDC_EVENTCHOICES2 ), WM_GETTEXT, (WPARAM)sizeof( buf1 ), (LPARAM)buf1 );
  247. Q_snprintf( g_Params.m_szParameters2, sizeof( g_Params.m_szParameters2 ), "%s", buf1 );
  248. }
  249. }
  250. }
  251. break;
  252. case IDC_EVENTCHOICES3:
  253. {
  254. HWND control = (HWND)lParam;
  255. if ( control )
  256. {
  257. if ( g_Params.m_nType != CChoreoEvent::MOVETO )
  258. {
  259. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters3 ), (LPARAM)g_Params.m_szParameters3 );
  260. }
  261. else
  262. {
  263. char buf1[ 256 ];
  264. SendMessage( GetControl( IDC_EVENTCHOICES3 ), WM_GETTEXT, (WPARAM)sizeof( buf1 ), (LPARAM)buf1 );
  265. Q_snprintf( g_Params.m_szParameters3, sizeof( g_Params.m_szParameters3 ), "%s", buf1 );
  266. }
  267. }
  268. }
  269. break;
  270. case IDC_ABSOLUTESTART:
  271. {
  272. g_Params.m_bUsesTag = false;
  273. UpdateTagRadioButtons( &g_Params );
  274. }
  275. break;
  276. case IDC_RELATIVESTART:
  277. {
  278. g_Params.m_bUsesTag = true;
  279. UpdateTagRadioButtons( &g_Params );
  280. }
  281. break;
  282. case IDC_CHECK_FORCESHORTMOVEMENT:
  283. {
  284. g_Params.m_bForceShortMovement = SendMessage( GetControl( IDC_CHECK_FORCESHORTMOVEMENT ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  285. }
  286. break;
  287. default:
  288. return FALSE;
  289. }
  290. return TRUE;
  291. }
  292. return FALSE;
  293. }
  294. //-----------------------------------------------------------------------------
  295. // Purpose:
  296. // Input : *view -
  297. // *actor -
  298. // Output : int
  299. //-----------------------------------------------------------------------------
  300. int EventProperties_MoveTo( CEventParams *params )
  301. {
  302. g_Params = *params;
  303. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  304. MAKEINTRESOURCE( IDD_EVENTPROPERTIES_MOVETO ),
  305. (HWND)g_MDLViewer->getHandle(),
  306. (DLGPROC)EventPropertiesMoveToDialogProc );
  307. *params = g_Params;
  308. return retval;
  309. }