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.

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