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.

297 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 "expressions.h"
  15. #include "expclass.h"
  16. static CEventParams g_Params;
  17. class CEventPropertiesExpressionDialog : public CBaseEventPropertiesDialog
  18. {
  19. typedef CBaseEventPropertiesDialog BaseClass;
  20. public:
  21. virtual void InitDialog( HWND hwndDlg );
  22. virtual BOOL HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
  23. virtual void SetTitle();
  24. virtual void ShowControlsForEventType( CEventParams *params );
  25. virtual void InitControlData( CEventParams *params );
  26. private:
  27. void PopulateExpressionList( HWND wnd );
  28. void PopulateExpressionClass( HWND control, CEventParams *params );
  29. };
  30. void CEventPropertiesExpressionDialog::SetTitle()
  31. {
  32. SetDialogTitle( &g_Params, "Expression", "Expression" );
  33. }
  34. void CEventPropertiesExpressionDialog::PopulateExpressionList( HWND wnd )
  35. {
  36. for ( int i = 0 ; i < expressions->GetNumClasses() ; i++ )
  37. {
  38. CExpClass *cl = expressions->GetClass( i );
  39. if( !cl )
  40. continue;
  41. // add text to combo box
  42. SendMessage( wnd, CB_ADDSTRING, 0, (LPARAM)cl->GetName() );
  43. }
  44. }
  45. void CEventPropertiesExpressionDialog::InitControlData( CEventParams *params )
  46. {
  47. BaseClass::InitControlData( params );
  48. HWND choices1 = GetControl( IDC_EVENTCHOICES );
  49. SendMessage( choices1, CB_RESETCONTENT, 0, 0 );
  50. SendMessage( choices1, WM_SETTEXT , 0, (LPARAM)params->m_szParameters );
  51. HWND choices2 = GetControl( IDC_EVENTCHOICES2 );
  52. SendMessage( choices2, CB_RESETCONTENT, 0, 0 );
  53. SendMessage( choices2, WM_SETTEXT , 0, (LPARAM)params->m_szParameters2 );
  54. PopulateExpressionList( choices1 );
  55. SendMessage( GetControl( IDC_CHOICES2PROMPT ), WM_SETTEXT, 0, (LPARAM)"Name:" );
  56. PopulateExpressionClass( choices2, params );
  57. }
  58. void CEventPropertiesExpressionDialog::InitDialog( HWND hwndDlg )
  59. {
  60. m_hDialog = hwndDlg;
  61. g_Params.PositionSelf( m_hDialog );
  62. // Set working title for dialog, etc.
  63. SetTitle();
  64. // Show/Hide dialog controls
  65. ShowControlsForEventType( &g_Params );
  66. InitControlData( &g_Params );
  67. UpdateTagRadioButtons( &g_Params );
  68. SetFocus( GetControl( IDC_EVENTNAME ) );
  69. }
  70. static CEventPropertiesExpressionDialog g_EventPropertiesExpressionDialog;
  71. void CEventPropertiesExpressionDialog::PopulateExpressionClass( HWND control, CEventParams *params )
  72. {
  73. // Find parameter 1
  74. for ( int c = 0; c < expressions->GetNumClasses(); c++ )
  75. {
  76. CExpClass *cl = expressions->GetClass( c );
  77. if ( !cl )
  78. continue;
  79. if ( Q_stricmp( cl->GetName(), params->m_szParameters ) )
  80. continue;
  81. for ( int i = 0 ; i < cl->GetNumExpressions() ; i++ )
  82. {
  83. CExpression *exp = cl->GetExpression( i );
  84. if ( exp )
  85. {
  86. // add text to combo box
  87. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)exp->name );
  88. }
  89. }
  90. break;
  91. }
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose:
  95. // Input : wnd -
  96. // *params -
  97. // Output : static
  98. //-----------------------------------------------------------------------------
  99. void CEventPropertiesExpressionDialog::ShowControlsForEventType( CEventParams *params )
  100. {
  101. BaseClass::ShowControlsForEventType( params );
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose:
  105. // Input : hwndDlg -
  106. // uMsg -
  107. // wParam -
  108. // lParam -
  109. // Output : static BOOL CALLBACK
  110. //-----------------------------------------------------------------------------
  111. static BOOL CALLBACK EventPropertiesExpressionDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  112. {
  113. return g_EventPropertiesExpressionDialog.HandleMessage( hwndDlg, uMsg, wParam, lParam );
  114. };
  115. BOOL CEventPropertiesExpressionDialog::HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  116. {
  117. m_hDialog = hwndDlg;
  118. bool handled = false;
  119. BOOL bret = InternalHandleMessage( &g_Params, hwndDlg, uMsg, wParam, lParam, handled );
  120. if ( handled )
  121. return bret;
  122. switch(uMsg)
  123. {
  124. case WM_PAINT:
  125. {
  126. PAINTSTRUCT ps;
  127. HDC hdc;
  128. hdc = BeginPaint(hwndDlg, &ps);
  129. DrawSpline( hdc, GetControl( IDC_STATIC_SPLINE ), g_Params.m_pEvent );
  130. EndPaint(hwndDlg, &ps);
  131. return FALSE;
  132. }
  133. break;
  134. case WM_VSCROLL:
  135. {
  136. RECT rcOut;
  137. GetSplineRect( GetControl( IDC_STATIC_SPLINE ), rcOut );
  138. InvalidateRect( hwndDlg, &rcOut, TRUE );
  139. UpdateWindow( hwndDlg );
  140. return FALSE;
  141. }
  142. break;
  143. case WM_INITDIALOG:
  144. {
  145. InitDialog( hwndDlg );
  146. }
  147. return FALSE;
  148. case WM_COMMAND:
  149. switch (LOWORD(wParam))
  150. {
  151. case IDOK:
  152. {
  153. HWND control = GetControl( IDC_EVENTCHOICES );
  154. if ( control )
  155. {
  156. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  157. }
  158. GetDlgItemText( m_hDialog, IDC_EVENTNAME, g_Params.m_szName, sizeof( g_Params.m_szName ) );
  159. if ( !g_Params.m_szName[ 0 ] )
  160. {
  161. Q_snprintf( g_Params.m_szName, sizeof( g_Params.m_szName ), "%s/%s", g_Params.m_szParameters, g_Params.m_szParameters2 );
  162. }
  163. char szTime[ 32 ];
  164. GetDlgItemText( m_hDialog, IDC_STARTTIME, szTime, sizeof( szTime ) );
  165. g_Params.m_flStartTime = atof( szTime );
  166. GetDlgItemText( m_hDialog, IDC_ENDTIME, szTime, sizeof( szTime ) );
  167. g_Params.m_flEndTime = atof( szTime );
  168. // Parse tokens from tags
  169. ParseTags( &g_Params );
  170. EndDialog( hwndDlg, 1 );
  171. }
  172. break;
  173. case IDCANCEL:
  174. EndDialog( hwndDlg, 0 );
  175. break;
  176. case IDC_CHECK_ENDTIME:
  177. {
  178. g_Params.m_bHasEndTime = SendMessage( GetControl( IDC_CHECK_ENDTIME ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  179. if ( !g_Params.m_bHasEndTime )
  180. {
  181. ShowWindow( GetControl( IDC_ENDTIME ), SW_HIDE );
  182. }
  183. else
  184. {
  185. ShowWindow( GetControl( IDC_ENDTIME ), SW_RESTORE );
  186. }
  187. }
  188. break;
  189. case IDC_CHECK_RESUMECONDITION:
  190. {
  191. g_Params.m_bResumeCondition = SendMessage( GetControl( IDC_CHECK_RESUMECONDITION ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  192. }
  193. break;
  194. case IDC_EVENTCHOICES:
  195. {
  196. HWND control = (HWND)lParam;
  197. if ( control )
  198. {
  199. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  200. PopulateExpressionClass( GetControl( IDC_EVENTCHOICES2 ), &g_Params );
  201. }
  202. }
  203. break;
  204. case IDC_EVENTCHOICES2:
  205. {
  206. HWND control = (HWND)lParam;
  207. if ( control )
  208. {
  209. if ( g_Params.m_nType != CChoreoEvent::MOVETO )
  210. {
  211. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters2 ), (LPARAM)g_Params.m_szParameters2 );
  212. }
  213. else
  214. {
  215. char buf1[ 256 ];
  216. SendMessage( GetControl( IDC_EVENTCHOICES2 ), WM_GETTEXT, (WPARAM)sizeof( buf1 ), (LPARAM)buf1 );
  217. Q_snprintf( g_Params.m_szParameters2, sizeof( g_Params.m_szParameters2 ), "%s", buf1 );
  218. }
  219. }
  220. }
  221. break;
  222. case IDC_ABSOLUTESTART:
  223. {
  224. g_Params.m_bUsesTag = false;
  225. UpdateTagRadioButtons( &g_Params );
  226. }
  227. break;
  228. case IDC_RELATIVESTART:
  229. {
  230. g_Params.m_bUsesTag = true;
  231. UpdateTagRadioButtons( &g_Params );
  232. }
  233. break;
  234. }
  235. return TRUE;
  236. }
  237. return FALSE;
  238. }
  239. //-----------------------------------------------------------------------------
  240. // Purpose:
  241. // Input : *view -
  242. // *actor -
  243. // Output : int
  244. //-----------------------------------------------------------------------------
  245. int EventProperties_Expression( CEventParams *params )
  246. {
  247. g_Params = *params;
  248. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  249. MAKEINTRESOURCE( IDD_EVENTPROPERTIES_EXPRESSION ),
  250. (HWND)g_MDLViewer->getHandle(),
  251. (DLGPROC)EventPropertiesExpressionDialogProc );
  252. *params = g_Params;
  253. return retval;
  254. }