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.

239 lines
6.1 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. static CEventParams g_Params;
  14. class CEventPropertiesFireTriggerDialog : public CBaseEventPropertiesDialog
  15. {
  16. typedef CBaseEventPropertiesDialog BaseClass;
  17. public:
  18. virtual void InitDialog( HWND hwndDlg );
  19. virtual BOOL HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
  20. virtual void SetTitle();
  21. virtual void ShowControlsForEventType( CEventParams *params );
  22. virtual void InitControlData( CEventParams *params );
  23. private:
  24. void PopulateTriggerList( HWND wnd );
  25. };
  26. void CEventPropertiesFireTriggerDialog::SetTitle()
  27. {
  28. SetDialogTitle( &g_Params, "FireTrigger", "Scene Trigger" );
  29. }
  30. void CEventPropertiesFireTriggerDialog::PopulateTriggerList( HWND wnd )
  31. {
  32. for ( int i = 0 ; i < 16; i++ )
  33. {
  34. char szName[256];
  35. sprintf( szName, "%d", i + 1 );
  36. // add text to combo box
  37. SendMessage( wnd, CB_ADDSTRING, 0, (LPARAM)szName );
  38. }
  39. }
  40. void CEventPropertiesFireTriggerDialog::InitControlData( CEventParams *params )
  41. {
  42. BaseClass::InitControlData( params );
  43. HWND choices1 = GetControl( IDC_EVENTCHOICES );
  44. SendMessage( choices1, CB_RESETCONTENT, 0, 0 );
  45. SendMessage( choices1, WM_SETTEXT , 0, (LPARAM)params->m_szParameters );
  46. PopulateTriggerList( choices1 );
  47. }
  48. void CEventPropertiesFireTriggerDialog::InitDialog( HWND hwndDlg )
  49. {
  50. m_hDialog = hwndDlg;
  51. g_Params.PositionSelf( m_hDialog );
  52. // Set working title for dialog, etc.
  53. SetTitle();
  54. // Show/Hide dialog controls
  55. ShowControlsForEventType( &g_Params );
  56. InitControlData( &g_Params );
  57. UpdateTagRadioButtons( &g_Params );
  58. SetFocus( GetControl( IDC_EVENTNAME ) );
  59. }
  60. static CEventPropertiesFireTriggerDialog g_EventPropertiesFireTriggerDialog;
  61. //-----------------------------------------------------------------------------
  62. // Purpose:
  63. // Input : wnd -
  64. // *params -
  65. // Output : static
  66. //-----------------------------------------------------------------------------
  67. void CEventPropertiesFireTriggerDialog::ShowControlsForEventType( CEventParams *params )
  68. {
  69. BaseClass::ShowControlsForEventType( params );
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose:
  73. // Input : hwndDlg -
  74. // uMsg -
  75. // wParam -
  76. // lParam -
  77. // Output : static BOOL CALLBACK
  78. //-----------------------------------------------------------------------------
  79. static BOOL CALLBACK EventPropertiesFireTriggerDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  80. {
  81. return g_EventPropertiesFireTriggerDialog.HandleMessage( hwndDlg, uMsg, wParam, lParam );
  82. };
  83. BOOL CEventPropertiesFireTriggerDialog::HandleMessage( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  84. {
  85. m_hDialog = hwndDlg;
  86. bool handled = false;
  87. BOOL bret = InternalHandleMessage( &g_Params, hwndDlg, uMsg, wParam, lParam, handled );
  88. if ( handled )
  89. return bret;
  90. switch(uMsg)
  91. {
  92. case WM_PAINT:
  93. {
  94. PAINTSTRUCT ps;
  95. HDC hdc;
  96. hdc = BeginPaint(hwndDlg, &ps);
  97. DrawSpline( hdc, GetControl( IDC_STATIC_SPLINE ), g_Params.m_pEvent );
  98. EndPaint(hwndDlg, &ps);
  99. return FALSE;
  100. }
  101. break;
  102. case WM_VSCROLL:
  103. {
  104. RECT rcOut;
  105. GetSplineRect( GetControl( IDC_STATIC_SPLINE ), rcOut );
  106. InvalidateRect( hwndDlg, &rcOut, TRUE );
  107. UpdateWindow( hwndDlg );
  108. return FALSE;
  109. }
  110. break;
  111. case WM_INITDIALOG:
  112. {
  113. InitDialog( hwndDlg );
  114. }
  115. return FALSE;
  116. case WM_COMMAND:
  117. switch (LOWORD(wParam))
  118. {
  119. case IDOK:
  120. {
  121. HWND control = GetControl( IDC_EVENTCHOICES );
  122. if ( control )
  123. {
  124. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  125. }
  126. GetDlgItemText( m_hDialog, IDC_EVENTNAME, g_Params.m_szName, sizeof( g_Params.m_szName ) );
  127. if ( !g_Params.m_szName[ 0 ] )
  128. {
  129. Q_snprintf( g_Params.m_szName, sizeof( g_Params.m_szName ), "Firetrigger %s", g_Params.m_szParameters );
  130. }
  131. char szTime[ 32 ];
  132. GetDlgItemText( m_hDialog, IDC_STARTTIME, szTime, sizeof( szTime ) );
  133. g_Params.m_flStartTime = atof( szTime );
  134. GetDlgItemText( m_hDialog, IDC_ENDTIME, szTime, sizeof( szTime ) );
  135. g_Params.m_flEndTime = atof( szTime );
  136. // Parse tokens from tags
  137. ParseTags( &g_Params );
  138. EndDialog( hwndDlg, 1 );
  139. }
  140. break;
  141. case IDCANCEL:
  142. EndDialog( hwndDlg, 0 );
  143. break;
  144. case IDC_CHECK_ENDTIME:
  145. {
  146. g_Params.m_bHasEndTime = SendMessage( GetControl( IDC_CHECK_ENDTIME ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  147. if ( !g_Params.m_bHasEndTime )
  148. {
  149. ShowWindow( GetControl( IDC_ENDTIME ), SW_HIDE );
  150. }
  151. else
  152. {
  153. ShowWindow( GetControl( IDC_ENDTIME ), SW_RESTORE );
  154. }
  155. }
  156. break;
  157. case IDC_CHECK_RESUMECONDITION:
  158. {
  159. g_Params.m_bResumeCondition = SendMessage( GetControl( IDC_CHECK_RESUMECONDITION ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  160. }
  161. break;
  162. case IDC_EVENTCHOICES:
  163. {
  164. HWND control = (HWND)lParam;
  165. if ( control )
  166. {
  167. SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szParameters ), (LPARAM)g_Params.m_szParameters );
  168. }
  169. }
  170. break;
  171. case IDC_ABSOLUTESTART:
  172. {
  173. g_Params.m_bUsesTag = false;
  174. UpdateTagRadioButtons( &g_Params );
  175. }
  176. break;
  177. case IDC_RELATIVESTART:
  178. {
  179. g_Params.m_bUsesTag = true;
  180. UpdateTagRadioButtons( &g_Params );
  181. }
  182. break;
  183. }
  184. return TRUE;
  185. }
  186. return FALSE;
  187. }
  188. //-----------------------------------------------------------------------------
  189. // Purpose:
  190. // Input : *view -
  191. // *actor -
  192. // Output : int
  193. //-----------------------------------------------------------------------------
  194. int EventProperties_FireTrigger( CEventParams *params )
  195. {
  196. g_Params = *params;
  197. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  198. MAKEINTRESOURCE( IDD_EVENTPROPERTIES_FIRETRIGGER ),
  199. (HWND)g_MDLViewer->getHandle(),
  200. (DLGPROC)EventPropertiesFireTriggerDialogProc );
  201. *params = g_Params;
  202. return retval;
  203. }