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.

204 lines
6.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <mxtk/mx.h>
  8. #include <stdio.h>
  9. #include "resource.h"
  10. #include "GlobalEventProperties.h"
  11. #include "mdlviewer.h"
  12. #include "hlfaceposer.h"
  13. #include "choreoevent.h"
  14. #include "choreoscene.h"
  15. #include "expressions.h"
  16. #include "choreoactor.h"
  17. #include "ifaceposersound.h"
  18. #include "expclass.h"
  19. #include "scriplib.h"
  20. static CGlobalEventParams g_Params;
  21. static void ExtractAutoStateFromParams( CGlobalEventParams *params )
  22. {
  23. ParseFromMemory( params->m_szAction, strlen( params->m_szAction ) );
  24. params->m_bAutomate = false;
  25. if ( TokenAvailable() )
  26. {
  27. GetToken( false );
  28. params->m_bAutomate = !stricmp( token, "automate" ) ? true : false;
  29. }
  30. if ( params->m_bAutomate )
  31. {
  32. params->m_szType[ 0 ] = 0;
  33. if ( TokenAvailable() )
  34. {
  35. GetToken( false );
  36. strcpy( params->m_szType, token );
  37. }
  38. params->m_flWaitTime = 0.0f;
  39. if ( TokenAvailable() )
  40. {
  41. GetToken( false );
  42. params->m_flWaitTime = (float)atof( token );
  43. }
  44. }
  45. }
  46. static void CreateAutoStateFromControls( CGlobalEventParams *params )
  47. {
  48. if ( params->m_bAutomate )
  49. {
  50. sprintf( params->m_szAction, "automate %s %f", params->m_szType, params->m_flWaitTime );
  51. }
  52. else
  53. {
  54. sprintf( params->m_szAction, "noaction" );
  55. }
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Purpose:
  59. // Input : hwndDlg -
  60. // uMsg -
  61. // wParam -
  62. // lParam -
  63. // Output : static BOOL CALLBACK
  64. //-----------------------------------------------------------------------------
  65. static BOOL CALLBACK GlobalEventPropertiesDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  66. {
  67. switch(uMsg)
  68. {
  69. case WM_INITDIALOG:
  70. {
  71. g_Params.PositionSelf( hwndDlg );
  72. SetDlgItemText( hwndDlg, IDC_EVENTNAME, g_Params.m_szName );
  73. SetDlgItemText( hwndDlg, IDC_STARTTIME, va( "%f", g_Params.m_flStartTime ) );
  74. switch ( g_Params.m_nType )
  75. {
  76. default:
  77. Assert(0);
  78. break;
  79. case CChoreoEvent::SECTION:
  80. {
  81. ShowWindow( GetDlgItem( hwndDlg, IDC_LOOPCOUNT ), SW_HIDE );
  82. ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_LOOPCOUNT ), SW_HIDE );
  83. ShowWindow( GetDlgItem( hwndDlg, IDC_LOOPTIME ), SW_HIDE );
  84. ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_LOOPTIME ), SW_HIDE );
  85. ExtractAutoStateFromParams( &g_Params );
  86. }
  87. break;
  88. case CChoreoEvent::LOOP:
  89. {
  90. SendMessage( GetDlgItem( hwndDlg, IDC_LOOPCOUNT ), WM_SETTEXT , 0, (LPARAM)va( "%i", g_Params.m_nLoopCount ) );
  91. SendMessage( GetDlgItem( hwndDlg, IDC_LOOPTIME ), WM_SETTEXT , 0, (LPARAM)va( "%f", g_Params.m_flLoopTime ) );
  92. ShowWindow( GetDlgItem( hwndDlg, IDC_CB_AUTOACTION ), SW_HIDE );
  93. ShowWindow( GetDlgItem( hwndDlg, IDC_DURATION ), SW_HIDE );
  94. ShowWindow( GetDlgItem( hwndDlg, IDC_CHECK_AUTOCHECK ), SW_HIDE );
  95. ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_AFTER ), SW_HIDE );
  96. ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_SECONDS ), SW_HIDE );
  97. }
  98. break;
  99. case CChoreoEvent::STOPPOINT:
  100. {
  101. ShowWindow( GetDlgItem( hwndDlg, IDC_LOOPCOUNT ), SW_HIDE );
  102. ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_LOOPCOUNT ), SW_HIDE );
  103. ShowWindow( GetDlgItem( hwndDlg, IDC_LOOPTIME ), SW_HIDE );
  104. ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_LOOPTIME ), SW_HIDE );
  105. ShowWindow( GetDlgItem( hwndDlg, IDC_CB_AUTOACTION ), SW_HIDE );
  106. ShowWindow( GetDlgItem( hwndDlg, IDC_DURATION ), SW_HIDE );
  107. ShowWindow( GetDlgItem( hwndDlg, IDC_CHECK_AUTOCHECK ), SW_HIDE );
  108. ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_AFTER ), SW_HIDE );
  109. ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_SECONDS ), SW_HIDE );
  110. }
  111. break;
  112. }
  113. SendMessage( GetDlgItem( hwndDlg, IDC_CHECK_AUTOCHECK ), BM_SETCHECK,
  114. ( WPARAM ) g_Params.m_bAutomate ? BST_CHECKED : BST_UNCHECKED,
  115. ( LPARAM )0 );
  116. SetDlgItemText( hwndDlg, IDC_DURATION, va( "%f", g_Params.m_flWaitTime ) );
  117. SendMessage( GetDlgItem( hwndDlg, IDC_CB_AUTOACTION ), WM_SETTEXT , 0, (LPARAM)g_Params.m_szType );
  118. // add text to combo box
  119. SendMessage( GetDlgItem( hwndDlg, IDC_CB_AUTOACTION ), CB_ADDSTRING, 0, (LPARAM)"Cancel" );
  120. SendMessage( GetDlgItem( hwndDlg, IDC_CB_AUTOACTION ), CB_ADDSTRING, 0, (LPARAM)"Resume" );
  121. SetWindowText( hwndDlg, g_Params.m_szDialogTitle );
  122. SetFocus( GetDlgItem( hwndDlg, IDC_EVENTNAME ) );
  123. }
  124. return FALSE;
  125. case WM_COMMAND:
  126. switch (LOWORD(wParam))
  127. {
  128. case IDOK:
  129. {
  130. char szTime[ 32 ];
  131. SendMessage( GetDlgItem( hwndDlg, IDC_CB_AUTOACTION ), WM_GETTEXT, (WPARAM)sizeof( g_Params.m_szType ), (LPARAM)g_Params.m_szType );
  132. GetDlgItemText( hwndDlg, IDC_DURATION, szTime, sizeof( szTime ) );
  133. g_Params.m_flWaitTime = atof( szTime );
  134. g_Params.m_bAutomate = SendMessage( GetDlgItem( hwndDlg, IDC_CHECK_AUTOCHECK ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  135. CreateAutoStateFromControls( &g_Params );
  136. GetDlgItemText( hwndDlg, IDC_EVENTNAME, g_Params.m_szName, sizeof( g_Params.m_szName ) );
  137. GetDlgItemText( hwndDlg, IDC_STARTTIME, szTime, sizeof( szTime ) );
  138. g_Params.m_flStartTime = atof( szTime );
  139. char szLoop[ 32 ];
  140. GetDlgItemText( hwndDlg, IDC_LOOPCOUNT, szLoop, sizeof( szLoop ) );
  141. g_Params.m_nLoopCount = atoi( szLoop );
  142. GetDlgItemText( hwndDlg, IDC_LOOPTIME, szLoop, sizeof( szLoop ) );
  143. g_Params.m_flLoopTime = (float)atof( szLoop );
  144. EndDialog( hwndDlg, 1 );
  145. }
  146. break;
  147. case IDCANCEL:
  148. EndDialog( hwndDlg, 0 );
  149. break;
  150. }
  151. return TRUE;
  152. }
  153. return FALSE;
  154. }
  155. //-----------------------------------------------------------------------------
  156. // Purpose:
  157. // Input : *view -
  158. // *actor -
  159. // Output : int
  160. //-----------------------------------------------------------------------------
  161. int GlobalEventProperties( CGlobalEventParams *params )
  162. {
  163. g_Params = *params;
  164. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  165. MAKEINTRESOURCE( IDD_GLOBALEVENTPROPERTIES ),
  166. (HWND)g_MDLViewer->getHandle(),
  167. (DLGPROC)GlobalEventPropertiesDialogProc );
  168. *params = g_Params;
  169. return retval;
  170. }