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.

271 lines
7.5 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. static CEventParams g_Params;
  15. class CEventPropertiesGenericDialog : 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 PopulateAIGeneric( HWND control, CEventParams *params );
  26. };
  27. void CEventPropertiesGenericDialog::SetTitle()
  28. {
  29. SetDialogTitle( &g_Params, "Generic", "Generic AI Event (text)" );
  30. }
  31. void CEventPropertiesGenericDialog::InitControlData( CEventParams *params )
  32. {
  33. BaseClass::InitControlData( params );
  34. HWND choices1 = GetControl( IDC_EVENTCHOICES );
  35. SendMessage( choices1, CB_RESETCONTENT, 0, 0 );
  36. SendMessage( choices1, WM_SETTEXT , 0, (LPARAM)params->m_szParameters );
  37. HWND choices2 = GetControl( IDC_EVENTCHOICES2 );
  38. SendMessage( choices2, CB_RESETCONTENT, 0, 0 );
  39. SendMessage( choices2, WM_SETTEXT , 0, (LPARAM)params->m_szParameters2 );
  40. SendMessage( GetControl( IDC_FILENAME ), WM_SETTEXT, sizeof( params->m_szParameters ), (LPARAM)params->m_szParameters );
  41. PopulateAIGeneric( choices1, params );
  42. PopulateNamedActorList( choices2, params );
  43. }
  44. void CEventPropertiesGenericDialog::InitDialog( HWND hwndDlg )
  45. {
  46. m_hDialog = hwndDlg;
  47. g_Params.PositionSelf( m_hDialog );
  48. // Set working title for dialog, etc.
  49. SetTitle();
  50. // Show/Hide dialog controls
  51. ShowControlsForEventType( &g_Params );
  52. InitControlData( &g_Params );
  53. UpdateTagRadioButtons( &g_Params );
  54. SetFocus( GetControl( IDC_EVENTNAME ) );
  55. }
  56. static CEventPropertiesGenericDialog g_EventPropertiesGenericDialog;
  57. void CEventPropertiesGenericDialog::PopulateAIGeneric( HWND control, CEventParams *params )
  58. {
  59. // FIXME: this should load from a config file
  60. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"AI_BLINK" );
  61. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"AI_HOLSTER" );
  62. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"AI_UNHOLSTER" );
  63. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"AI_AIM" );
  64. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"AI_RANDOMLOOK" );
  65. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"AI_RANDOMFACEFLEX" );
  66. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"AI_RANDOMHEADFLEX" );
  67. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"AI_IGNORECOLLISION" );
  68. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)"AI_DISABLEAI" );
  69. SendMessage( control, WM_SETTEXT , 0, (LPARAM)params->m_szParameters );
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose:
  73. // Input : wnd -
  74. // *params -
  75. // Output : static
  76. //-----------------------------------------------------------------------------
  77. void CEventPropertiesGenericDialog::ShowControlsForEventType( CEventParams *params )
  78. {
  79. BaseClass::ShowControlsForEventType( params );
  80. }
  81. //-----------------------------------------------------------------------------
  82. // Purpose:
  83. // Input : hwndDlg -
  84. // uMsg -
  85. // wParam -
  86. // lParam -
  87. // Output : static BOOL CALLBACK
  88. //-----------------------------------------------------------------------------
  89. static BOOL CALLBACK EventPropertiesGenericDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  90. {
  91. return g_EventPropertiesGenericDialog.HandleMessage( hwndDlg, uMsg, wParam, lParam );
  92. };
  93. BOOL CEventPropertiesGenericDialog::HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  94. {
  95. m_hDialog = hwndDlg;
  96. bool handled = false;
  97. BOOL bret = InternalHandleMessage( &g_Params, hwndDlg, uMsg, wParam, lParam, handled );
  98. if ( handled )
  99. return bret;
  100. switch(uMsg)
  101. {
  102. case WM_PAINT:
  103. {
  104. PAINTSTRUCT ps;
  105. HDC hdc;
  106. hdc = BeginPaint(hwndDlg, &ps);
  107. DrawSpline( hdc, GetControl( IDC_STATIC_SPLINE ), g_Params.m_pEvent );
  108. EndPaint(hwndDlg, &ps);
  109. return FALSE;
  110. }
  111. break;
  112. case WM_VSCROLL:
  113. {
  114. RECT rcOut;
  115. GetSplineRect( GetControl( IDC_STATIC_SPLINE ), rcOut );
  116. InvalidateRect( hwndDlg, &rcOut, TRUE );
  117. UpdateWindow( hwndDlg );
  118. return FALSE;
  119. }
  120. break;
  121. case WM_INITDIALOG:
  122. {
  123. InitDialog( hwndDlg );
  124. }
  125. return FALSE;
  126. case WM_COMMAND:
  127. switch (LOWORD(wParam))
  128. {
  129. case IDOK:
  130. {
  131. HWND control = GetControl( IDC_EVENTCHOICES );
  132. if ( control )
  133. {
  134. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  135. }
  136. GetDlgItemText( m_hDialog, IDC_EVENTNAME, g_Params.m_szName, sizeof( g_Params.m_szName ) );
  137. if ( !g_Params.m_szName[ 0 ] )
  138. {
  139. Q_snprintf( g_Params.m_szName, sizeof( g_Params.m_szName ), "%s to %s", g_Params.m_szParameters, g_Params.m_szParameters2 );
  140. }
  141. char szTime[ 32 ];
  142. GetDlgItemText( m_hDialog, IDC_STARTTIME, szTime, sizeof( szTime ) );
  143. g_Params.m_flStartTime = atof( szTime );
  144. GetDlgItemText( m_hDialog, IDC_ENDTIME, szTime, sizeof( szTime ) );
  145. g_Params.m_flEndTime = atof( szTime );
  146. // Parse tokens from tags
  147. ParseTags( &g_Params );
  148. EndDialog( hwndDlg, 1 );
  149. }
  150. break;
  151. case IDCANCEL:
  152. EndDialog( hwndDlg, 0 );
  153. break;
  154. case IDC_CHECK_ENDTIME:
  155. {
  156. g_Params.m_bHasEndTime = SendMessage( GetControl( IDC_CHECK_ENDTIME ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  157. if ( !g_Params.m_bHasEndTime )
  158. {
  159. ShowWindow( GetControl( IDC_ENDTIME ), SW_HIDE );
  160. }
  161. else
  162. {
  163. ShowWindow( GetControl( IDC_ENDTIME ), SW_RESTORE );
  164. }
  165. }
  166. break;
  167. case IDC_CHECK_RESUMECONDITION:
  168. {
  169. g_Params.m_bResumeCondition = SendMessage( GetControl( IDC_CHECK_RESUMECONDITION ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  170. }
  171. break;
  172. case IDC_EVENTCHOICES:
  173. {
  174. HWND control = (HWND)lParam;
  175. if ( control )
  176. {
  177. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  178. }
  179. }
  180. break;
  181. case IDC_EVENTCHOICES2:
  182. {
  183. HWND control = (HWND)lParam;
  184. if ( control )
  185. {
  186. if ( g_Params.m_nType != CChoreoEvent::MOVETO )
  187. {
  188. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters2 ), (LPARAM)g_Params.m_szParameters2 );
  189. }
  190. else
  191. {
  192. char buf1[ 256 ];
  193. SendMessage( GetControl( IDC_EVENTCHOICES2 ), WM_GETTEXT, (WPARAM)sizeof( buf1 ), (LPARAM)buf1 );
  194. Q_snprintf( g_Params.m_szParameters2, sizeof( g_Params.m_szParameters2 ), "%s", buf1 );
  195. }
  196. }
  197. }
  198. break;
  199. case IDC_ABSOLUTESTART:
  200. {
  201. g_Params.m_bUsesTag = false;
  202. UpdateTagRadioButtons( &g_Params );
  203. }
  204. break;
  205. case IDC_RELATIVESTART:
  206. {
  207. g_Params.m_bUsesTag = true;
  208. UpdateTagRadioButtons( &g_Params );
  209. }
  210. break;
  211. }
  212. return TRUE;
  213. }
  214. return FALSE;
  215. }
  216. //-----------------------------------------------------------------------------
  217. // Purpose:
  218. // Input : *view -
  219. // *actor -
  220. // Output : int
  221. //-----------------------------------------------------------------------------
  222. int EventProperties_Generic( CEventParams *params )
  223. {
  224. g_Params = *params;
  225. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  226. MAKEINTRESOURCE( IDD_EVENTPROPERTIES_GENERIC ),
  227. (HWND)g_MDLViewer->getHandle(),
  228. (DLGPROC)EventPropertiesGenericDialogProc );
  229. *params = g_Params;
  230. return retval;
  231. }