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.

270 lines
7.1 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 "EdgeProperties.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 CEdgePropertiesParams g_Params;
  21. void CEdgePropertiesParams::SetFromFlexTrack( CFlexAnimationTrack *track )
  22. {
  23. for ( int i = 0 ; i < 2; ++i )
  24. {
  25. m_bActive[ i ] = track->IsEdgeActive( i == 0 ? true : false );
  26. int curveType = 0;
  27. track->GetEdgeInfo( i == 0 ? true : false, curveType, m_flValue[ i ] );
  28. if ( i == 0 )
  29. {
  30. m_InterpolatorType[ i ] = GET_RIGHT_CURVE( curveType );
  31. }
  32. else
  33. {
  34. m_InterpolatorType[ i ] = GET_LEFT_CURVE( curveType );
  35. }
  36. }
  37. }
  38. void CEdgePropertiesParams::ApplyToTrack( CFlexAnimationTrack *track )
  39. {
  40. for ( int i = 0 ; i < 2; ++i )
  41. {
  42. track->SetEdgeActive( i == 0 ? true : false, m_bActive[ i ] );
  43. int curveType = 0;
  44. if ( i == 0 )
  45. {
  46. curveType = MAKE_CURVE_TYPE( 0, m_InterpolatorType[ i ] );
  47. }
  48. else
  49. {
  50. curveType = MAKE_CURVE_TYPE( m_InterpolatorType[ i ], 0 );
  51. }
  52. track->SetEdgeInfo( i == 0 ? true : false, curveType, m_flValue[ i ] );
  53. }
  54. }
  55. void CEdgePropertiesParams::SetFromCurve( CCurveData *ramp )
  56. {
  57. for ( int i = 0 ; i < 2; ++i )
  58. {
  59. m_bActive[ i ] = ramp->IsEdgeActive( i == 0 ? true : false );
  60. int curveType = 0;
  61. ramp->GetEdgeInfo( i == 0 ? true : false, curveType, m_flValue[ i ] );
  62. if ( i == 0 )
  63. {
  64. m_InterpolatorType[ i ] = GET_RIGHT_CURVE( curveType );
  65. }
  66. else
  67. {
  68. m_InterpolatorType[ i ] = GET_LEFT_CURVE( curveType );
  69. }
  70. }
  71. }
  72. void CEdgePropertiesParams::ApplyToCurve( CCurveData *ramp )
  73. {
  74. for ( int i = 0 ; i < 2; ++i )
  75. {
  76. ramp->SetEdgeActive( i == 0 ? true : false, m_bActive[ i ] );
  77. int curveType = 0;
  78. if ( i == 0 )
  79. {
  80. curveType = MAKE_CURVE_TYPE( 0, m_InterpolatorType[ i ] );
  81. }
  82. else
  83. {
  84. curveType = MAKE_CURVE_TYPE( m_InterpolatorType[ i ], 0 );
  85. }
  86. ramp->SetEdgeInfo( i == 0 ? true : false, curveType, m_flValue[ i ] );
  87. }
  88. }
  89. static void PopulateCurveType( HWND control, CEdgePropertiesParams *params, bool isLeftEdge )
  90. {
  91. SendMessage( control, CB_RESETCONTENT, 0, 0 );
  92. for ( int i = 0; i < NUM_INTERPOLATE_TYPES; ++i )
  93. {
  94. SendMessage( control, CB_ADDSTRING, 0, (LPARAM)Interpolator_NameForInterpolator( i, true ) );
  95. }
  96. SendMessage( control, CB_SETCURSEL , params->m_InterpolatorType[ isLeftEdge ? 0 : 1 ], 0 );
  97. }
  98. static void Reset( HWND hwndDlg, bool left )
  99. {
  100. SendMessage( GetDlgItem( hwndDlg, left ? IDC_LEFT_ACTIVE : IDC_RIGHT_ACTIVE ), BM_SETCHECK,
  101. ( WPARAM )BST_UNCHECKED,
  102. ( LPARAM )0 );
  103. SendMessage( GetDlgItem( hwndDlg, left ? IDC_LEFT_CURVETYPE : IDC_RIGHT_CURVETYPE ), CB_SETCURSEL, 0, 0 );
  104. SetDlgItemText( hwndDlg, left ? IDC_LEFT_ZEROVALUE : IDC_RIGHT_ZEROVALUE, "0.0" );
  105. SendMessage( GetDlgItem( hwndDlg, IDC_HOLD_OUT ), BM_SETCHECK,
  106. ( WPARAM )BST_UNCHECKED,
  107. ( LPARAM )0 );
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose:
  111. // Input : hwndDlg -
  112. // uMsg -
  113. // wParam -
  114. // lParam -
  115. // Output : static BOOL CALLBACK
  116. //-----------------------------------------------------------------------------
  117. static BOOL CALLBACK EdgePropertiesDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  118. {
  119. switch(uMsg)
  120. {
  121. case WM_INITDIALOG:
  122. {
  123. g_Params.PositionSelf( hwndDlg );
  124. PopulateCurveType( GetDlgItem( hwndDlg, IDC_LEFT_CURVETYPE ), &g_Params, true );
  125. PopulateCurveType( GetDlgItem( hwndDlg, IDC_RIGHT_CURVETYPE ), &g_Params, false );
  126. SetDlgItemText( hwndDlg, IDC_LEFT_ZEROVALUE, va( "%f", g_Params.m_flValue[ 0 ] ) );
  127. SetDlgItemText( hwndDlg, IDC_RIGHT_ZEROVALUE, va( "%f", g_Params.m_flValue[ 1 ] ) );
  128. SendMessage( GetDlgItem( hwndDlg, IDC_LEFT_ACTIVE ), BM_SETCHECK,
  129. ( WPARAM ) g_Params.m_bActive[ 0 ] ? BST_CHECKED : BST_UNCHECKED,
  130. ( LPARAM )0 );
  131. SendMessage( GetDlgItem( hwndDlg, IDC_RIGHT_ACTIVE ), BM_SETCHECK,
  132. ( WPARAM ) g_Params.m_bActive[ 1 ] ? BST_CHECKED : BST_UNCHECKED,
  133. ( LPARAM )0 );
  134. SetWindowText( hwndDlg, g_Params.m_szDialogTitle );
  135. SetFocus( GetDlgItem( hwndDlg, IDC_LEFT_ZEROVALUE ) );
  136. }
  137. return FALSE;
  138. case WM_COMMAND:
  139. switch (LOWORD(wParam))
  140. {
  141. case IDC_LEFT_RESET:
  142. {
  143. Reset( hwndDlg, true );
  144. }
  145. break;
  146. case IDC_RIGHT_RESET:
  147. {
  148. Reset( hwndDlg, false );
  149. }
  150. break;
  151. case IDC_LEFT_CURVETYPE:
  152. {
  153. if ( HIWORD( wParam ) == CBN_SELCHANGE )
  154. {
  155. SendMessage( GetDlgItem( hwndDlg, IDC_LEFT_ACTIVE ), BM_SETCHECK,
  156. ( WPARAM ) BST_CHECKED,
  157. ( LPARAM )0 );
  158. }
  159. }
  160. break;
  161. case IDC_RIGHT_CURVETYPE:
  162. {
  163. if ( HIWORD( wParam ) == CBN_SELCHANGE )
  164. {
  165. SendMessage( GetDlgItem( hwndDlg, IDC_RIGHT_ACTIVE ), BM_SETCHECK,
  166. ( WPARAM ) BST_CHECKED,
  167. ( LPARAM )0 );
  168. }
  169. }
  170. break;
  171. case IDC_LEFT_ZEROVALUE:
  172. {
  173. if ( HIWORD( wParam ) == EN_CHANGE )
  174. {
  175. SendMessage( GetDlgItem( hwndDlg, IDC_LEFT_ACTIVE ), BM_SETCHECK,
  176. ( WPARAM ) BST_CHECKED,
  177. ( LPARAM )0 );
  178. }
  179. }
  180. break;
  181. case IDC_RIGHT_ZEROVALUE:
  182. {
  183. if ( HIWORD( wParam ) == EN_CHANGE )
  184. {
  185. SendMessage( GetDlgItem( hwndDlg, IDC_RIGHT_ACTIVE ), BM_SETCHECK,
  186. ( WPARAM ) BST_CHECKED,
  187. ( LPARAM )0 );
  188. }
  189. }
  190. break;
  191. case IDOK:
  192. {
  193. char sz[ 64 ];
  194. GetDlgItemText( hwndDlg, IDC_LEFT_ZEROVALUE, sz, sizeof( sz ) );
  195. g_Params.m_flValue[ 0 ] = clamp( Q_atof( sz ), 0.0f, 1.0f );
  196. GetDlgItemText( hwndDlg, IDC_RIGHT_ZEROVALUE, sz, sizeof( sz ) );
  197. g_Params.m_flValue[ 1 ] = clamp( Q_atof( sz ), 0.0f, 1.0f );
  198. g_Params.m_bActive[ 0 ] = SendMessage( GetDlgItem( hwndDlg, IDC_LEFT_ACTIVE ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  199. g_Params.m_bActive[ 1 ] = SendMessage( GetDlgItem( hwndDlg, IDC_RIGHT_ACTIVE ), BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
  200. int interpolatorType;
  201. interpolatorType = SendMessage( GetDlgItem( hwndDlg, IDC_LEFT_CURVETYPE ), CB_GETCURSEL, 0, 0 );
  202. if ( interpolatorType != CB_ERR )
  203. {
  204. g_Params.m_InterpolatorType[ 0 ] = interpolatorType;
  205. }
  206. interpolatorType = SendMessage( GetDlgItem( hwndDlg, IDC_RIGHT_CURVETYPE ), CB_GETCURSEL, 0, 0 );
  207. if ( interpolatorType != CB_ERR )
  208. {
  209. g_Params.m_InterpolatorType[ 1 ] = interpolatorType;
  210. }
  211. EndDialog( hwndDlg, 1 );
  212. }
  213. break;
  214. case IDCANCEL:
  215. EndDialog( hwndDlg, 0 );
  216. break;
  217. }
  218. return TRUE;
  219. }
  220. return FALSE;
  221. }
  222. //-----------------------------------------------------------------------------
  223. // Purpose:
  224. // Input : *view -
  225. // *actor -
  226. // Output : int
  227. //-----------------------------------------------------------------------------
  228. int EdgeProperties( CEdgePropertiesParams *params )
  229. {
  230. g_Params = *params;
  231. int retval = DialogBox( (HINSTANCE)GetModuleHandle( 0 ),
  232. MAKEINTRESOURCE( IDD_EDGEPROPERTIES ),
  233. (HWND)g_MDLViewer->getHandle(),
  234. (DLGPROC)EdgePropertiesDialogProc );
  235. *params = g_Params;
  236. return retval;
  237. }