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.

1442 lines
40 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "client_pch.h"
  8. #include "shake.h"
  9. #include "tmessage.h"
  10. #include "cl_demoaction.h"
  11. #include "cl_demoactionmanager.h"
  12. #include "cl_demoactioneditors.h"
  13. #include "cl_demoaction_types.h"
  14. #include "cl_demoeditorpanel.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. //-----------------------------------------------------------------------------
  18. // Purpose:
  19. // Input : *parent -
  20. // *action -
  21. // newaction -
  22. //-----------------------------------------------------------------------------
  23. CBaseActionEditDialog::CBaseActionEditDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  24. : vgui::Frame( parent, CBaseDemoAction::NameForType( action->GetType() ) ),
  25. m_pEditor( parent ),
  26. m_pAction( action ),
  27. m_bNewAction( newaction )
  28. {
  29. if ( m_bNewAction )
  30. {
  31. SetTitle( va( "New %s Action", CBaseDemoAction::NameForType( action->GetType() ) ), true );
  32. }
  33. else
  34. {
  35. SetTitle( va( "Edit %s Action", CBaseDemoAction::NameForType( action->GetType() ) ), true );
  36. }
  37. m_pOK = new vgui::Button( this, "OK", "OK" );
  38. m_pCancel = new vgui::Button( this, "Cancel", "Cancel" );
  39. m_pActionName = new vgui::TextEntry( this, "ActionName" );
  40. m_pStart = new vgui::TextEntry( this, "ActionStart" );
  41. m_pStartType = new vgui::ComboBox( this, "ActionStartType", (int)NUM_TIMING_TYPES, false );
  42. for ( int i = 0; i < (int)NUM_TIMING_TYPES; i++ )
  43. {
  44. m_pStartType->AddItem( CBaseDemoAction::NameForTimingType( (DEMOACTIONTIMINGTYPE)i ), NULL );
  45. }
  46. SetSizeable( false );
  47. SetMoveable( true );
  48. }
  49. static bool g_BaseActionEditSaveChained = false;
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. //-----------------------------------------------------------------------------
  53. void CBaseActionEditDialog::Init( void )
  54. {
  55. // Fill in data from passed in action
  56. m_pActionName->SetText( m_pAction->GetActionName() );
  57. m_pStartType->ActivateItem( (int)m_pAction->GetTimingType() );
  58. switch ( m_pAction->GetTimingType() )
  59. {
  60. default:
  61. case ACTION_USES_NEITHER:
  62. {
  63. m_pStart->SetText( "" );
  64. }
  65. break;
  66. case ACTION_USES_TICK:
  67. {
  68. m_pStart->SetText( va( "%i", m_pAction->GetStartTick() ) );
  69. }
  70. break;
  71. case ACTION_USES_TIME:
  72. {
  73. m_pStart->SetText( va( "%.3f", m_pAction->GetStartTime() ) );
  74. }
  75. break;
  76. }
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose:
  80. // Output : Returns true on success, false on failure.
  81. //-----------------------------------------------------------------------------
  82. bool CBaseActionEditDialog::OnSaveChanges( void )
  83. {
  84. bool bret = false;
  85. // No baseclass chain
  86. g_BaseActionEditSaveChained = true;
  87. char actionname[ 512 ];
  88. m_pActionName->GetText( actionname, sizeof( actionname ) );
  89. if ( Q_strcmp( m_pAction->GetActionName(), actionname ) )
  90. {
  91. bret = true;
  92. m_pAction->SetActionName( actionname );
  93. }
  94. char starttext[ 512 ];
  95. m_pStart->GetText( starttext, sizeof( starttext ) );
  96. char starttype[ 512 ];
  97. m_pStartType->GetText( starttype, sizeof( starttype ) );
  98. DEMOACTIONTIMINGTYPE timingType = CBaseDemoAction::TimingTypeForName( starttype );
  99. if ( timingType != m_pAction->GetTimingType() )
  100. {
  101. bret = true;
  102. m_pAction->SetTimingType( timingType );
  103. }
  104. switch ( timingType )
  105. {
  106. default:
  107. case ACTION_USES_NEITHER:
  108. {
  109. }
  110. break;
  111. case ACTION_USES_TICK:
  112. {
  113. int tick = atoi( starttext );
  114. if ( tick != m_pAction->GetStartTick() )
  115. {
  116. m_pAction->SetStartTick( tick );
  117. bret = true;
  118. }
  119. }
  120. break;
  121. case ACTION_USES_TIME:
  122. {
  123. float t = (float)atof( starttext );
  124. if ( t != m_pAction->GetStartTime() )
  125. {
  126. m_pAction->SetStartTime( t );
  127. bret = true;
  128. }
  129. }
  130. break;
  131. }
  132. return bret;
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Purpose:
  136. //-----------------------------------------------------------------------------
  137. void CBaseActionEditDialog::OnClose()
  138. {
  139. if ( m_bNewAction )
  140. {
  141. demoaction->AddAction( m_pAction );
  142. }
  143. g_BaseActionEditSaveChained = false;
  144. if ( OnSaveChanges() || m_bNewAction )
  145. {
  146. demoaction->SetDirty( true );
  147. m_pEditor->OnRefresh();
  148. }
  149. Assert( g_BaseActionEditSaveChained );
  150. MarkForDeletion();
  151. BaseClass::OnClose();
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Purpose:
  155. //-----------------------------------------------------------------------------
  156. void CBaseActionEditDialog::OnCancel()
  157. {
  158. if ( m_bNewAction )
  159. {
  160. delete m_pAction;
  161. }
  162. // Nothing, just delete
  163. MarkForDeletion();
  164. BaseClass::OnClose();
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Purpose:
  168. // Input : *commands -
  169. //-----------------------------------------------------------------------------
  170. void CBaseActionEditDialog::OnCommand( char const *commands )
  171. {
  172. if ( !Q_strcasecmp( commands, "OK" ) )
  173. {
  174. OnClose();
  175. }
  176. else if ( !Q_strcasecmp( commands, "Cancel" ) )
  177. {
  178. OnCancel();
  179. }
  180. else
  181. {
  182. BaseClass::OnCommand( commands );
  183. }
  184. }
  185. //-----------------------------------------------------------------------------
  186. // Purpose:
  187. // Input : *parent -
  188. // *action -
  189. // newaction -
  190. //-----------------------------------------------------------------------------
  191. CBaseActionWithTargetDialog::CBaseActionWithTargetDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  192. : CBaseActionEditDialog( parent, action, newaction )
  193. {
  194. m_pActionTarget = new vgui::TextEntry( this, "ActionTarget" );
  195. }
  196. //-----------------------------------------------------------------------------
  197. // Purpose: Slam text with text from action
  198. //-----------------------------------------------------------------------------
  199. void CBaseActionWithTargetDialog::Init( void )
  200. {
  201. BaseClass::Init();
  202. m_pActionTarget->SetText( m_pAction->GetActionTarget() );
  203. }
  204. //-----------------------------------------------------------------------------
  205. // Purpose:
  206. // Output : Returns true on success, false on failure.
  207. //-----------------------------------------------------------------------------
  208. bool CBaseActionWithTargetDialog::OnSaveChanges( void )
  209. {
  210. bool bret = BaseClass::OnSaveChanges();
  211. char actiontarget[ 512 ];
  212. m_pActionTarget->GetText( actiontarget, sizeof( actiontarget ) );
  213. if ( Q_strcmp( m_pAction->GetActionTarget(), actiontarget ) )
  214. {
  215. bret = true;
  216. m_pAction->SetActionTarget( actiontarget );
  217. }
  218. return bret;
  219. }
  220. //-----------------------------------------------------------------------------
  221. // Purpose:
  222. //-----------------------------------------------------------------------------
  223. class CBaseActionSkipAheadDialog : public CBaseActionEditDialog
  224. {
  225. typedef CBaseActionEditDialog BaseClass;
  226. public:
  227. CBaseActionSkipAheadDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  228. virtual void Init( void );
  229. // Returns true if changes were effected
  230. virtual bool OnSaveChanges( void );
  231. private:
  232. CDemoActionSkipAhead *GetAction( void ) { return static_cast< CDemoActionSkipAhead * >( m_pAction ); }
  233. vgui::ComboBox *m_pSkipType;
  234. vgui::TextEntry *m_pSkip;
  235. };
  236. CBaseActionSkipAheadDialog::CBaseActionSkipAheadDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  237. : CBaseActionEditDialog( parent, action, newaction )
  238. {
  239. m_pSkip = new vgui::TextEntry( this, "ActionSkip" );
  240. m_pSkipType = new vgui::ComboBox( this, "ActionSkipType", (int)2, false );
  241. for ( int i = 1; i < (int)NUM_TIMING_TYPES; i++ )
  242. {
  243. m_pSkipType->AddItem( CBaseDemoAction::NameForTimingType( (DEMOACTIONTIMINGTYPE)i ), NULL );
  244. }
  245. }
  246. //-----------------------------------------------------------------------------
  247. // Purpose:
  248. //-----------------------------------------------------------------------------
  249. void CBaseActionSkipAheadDialog::Init( void )
  250. {
  251. LoadControlSettings( "resource\\BaseActionSkipAheadDialog.res" );
  252. BaseClass::Init();
  253. if ( GetAction()->m_bUsingSkipTick )
  254. {
  255. m_pSkipType->SetText( "TimeUseTick" );
  256. m_pSkip->SetText( va( "%i", GetAction()->m_nSkipToTick ) );
  257. }
  258. else
  259. {
  260. m_pSkipType->SetText( "TimeUseClock" );
  261. m_pSkip->SetText( va( "%.3f", GetAction()->m_flSkipToTime ) );
  262. }
  263. }
  264. //-----------------------------------------------------------------------------
  265. // Purpose:
  266. // Output : Returns true if changes were effected
  267. //-----------------------------------------------------------------------------
  268. bool CBaseActionSkipAheadDialog::OnSaveChanges( void )
  269. {
  270. bool bret = BaseClass::OnSaveChanges();
  271. char skiptype[ 512 ];
  272. m_pSkipType->GetText( skiptype, sizeof( skiptype ) );
  273. char skipto[ 512 ];
  274. m_pSkip->GetText( skipto, sizeof( skipto ) );
  275. float fskip = (float)atof( skipto );
  276. int iskip = (int)atoi( skipto );
  277. if ( !Q_strcasecmp( skiptype, "TimeUseTick" ) )
  278. {
  279. if ( GetAction()->m_nSkipToTick != iskip )
  280. {
  281. bret = true;
  282. GetAction()->SetSkipToTick( iskip );
  283. GetAction()->SetSkipToTime( -1.0f );
  284. }
  285. }
  286. else
  287. {
  288. if ( GetAction()->m_flSkipToTime != fskip )
  289. {
  290. bret = true;
  291. GetAction()->SetSkipToTime( fskip );
  292. GetAction()->SetSkipToTick( -1 );
  293. }
  294. }
  295. return bret;
  296. }
  297. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_SKIPAHEAD, CBaseActionSkipAheadDialog );
  298. //-----------------------------------------------------------------------------
  299. // Purpose:
  300. //-----------------------------------------------------------------------------
  301. class CBaseActionStopPlaybackDialog : public CBaseActionEditDialog
  302. {
  303. typedef CBaseActionEditDialog BaseClass;
  304. public:
  305. CBaseActionStopPlaybackDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  306. : BaseClass( parent, action, newaction )
  307. {
  308. }
  309. virtual void Init( void )
  310. {
  311. LoadControlSettings( "resource\\BaseActionStopPlaybackDialog.res" );
  312. BaseClass::Init();
  313. }
  314. private:
  315. CDemoActionStopPlayback *GetAction( void ) { return static_cast< CDemoActionStopPlayback * >( m_pAction ); }
  316. };
  317. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_STOPPLAYBACK, CBaseActionStopPlaybackDialog );
  318. //-----------------------------------------------------------------------------
  319. // Purpose: Screen Fade
  320. //-----------------------------------------------------------------------------
  321. class CBaseActionScreenFadeStartDialog : public CBaseActionEditDialog
  322. {
  323. typedef CBaseActionEditDialog BaseClass;
  324. public:
  325. CBaseActionScreenFadeStartDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  326. : BaseClass( parent, action, newaction )
  327. {
  328. m_pDuration = new vgui::TextEntry( this, "ScreenFadeDuration" );
  329. m_pHoldTime = new vgui::TextEntry( this, "ScreenFadeHoldTime" );
  330. m_pFFADE_IN = new vgui::CheckButton( this, "ScreenFadeFFADE_IN", "Fade in" );
  331. m_pFFADE_OUT = new vgui::CheckButton( this, "ScreenFadeFFADE_OUT", "Fade out" );
  332. m_pFFADE_MODULATE = new vgui::CheckButton( this, "ScreenFadeFFADE_MODULATE", "Modulate" );
  333. m_pFFADE_STAYOUT = new vgui::CheckButton( this, "ScreenFadeFFADE_STAYOUT", "Stay out" );
  334. m_pFFADE_PURGE = new vgui::CheckButton( this, "ScreenFadeFFADE_Purge", "Purge" );
  335. m_pColor = new vgui::TextEntry( this, "ScreenFadeColor" );
  336. }
  337. virtual void Init( void );
  338. virtual bool OnSaveChanges( void );
  339. private:
  340. CDemoActionScreenFadeStart *GetAction( void ) { return static_cast< CDemoActionScreenFadeStart * >( m_pAction ); }
  341. bool CheckFlagDifference( vgui::CheckButton *check, bool oldval, int flag );
  342. vgui::TextEntry *m_pDuration;
  343. vgui::TextEntry *m_pHoldTime;
  344. vgui::CheckButton *m_pFFADE_IN;
  345. vgui::CheckButton *m_pFFADE_OUT;
  346. vgui::CheckButton *m_pFFADE_MODULATE;
  347. vgui::CheckButton *m_pFFADE_STAYOUT;
  348. vgui::CheckButton *m_pFFADE_PURGE;
  349. vgui::TextEntry *m_pColor;
  350. };
  351. //-----------------------------------------------------------------------------
  352. // Purpose:
  353. //-----------------------------------------------------------------------------
  354. void CBaseActionScreenFadeStartDialog::Init( void )
  355. {
  356. LoadControlSettings( "resource\\BaseActionScreenFadeStartDialog.res" );
  357. BaseClass::Init();
  358. ScreenFade_t const *f = GetAction()->GetScreenFade();
  359. float duration = f->duration * (1.0f/(float)(1<<SCREENFADE_FRACBITS));
  360. float holdTime = f->holdTime * (1.0f/(float)(1<<SCREENFADE_FRACBITS));
  361. bool fadein = ( f->fadeFlags & FFADE_IN ) ? true : false;
  362. bool fadeout = ( f->fadeFlags & FFADE_OUT ) ? true : false;
  363. bool fademodulate = ( f->fadeFlags & FFADE_MODULATE ) ? true : false;
  364. bool fadestayout = ( f->fadeFlags & FFADE_STAYOUT ) ? true : false;
  365. bool fadepurge = ( f->fadeFlags & FFADE_PURGE ) ? true : false;
  366. int r = f->r;
  367. int g = f->g;
  368. int b = f->b;
  369. int a = f->a;
  370. m_pDuration->SetText( va( "%.3f", duration ) );
  371. m_pHoldTime->SetText( va( "%.3f", holdTime ) );
  372. m_pColor->SetText( va( "%i %i %i %i", r, g, b, a ) );
  373. m_pFFADE_IN->SetSelected( fadein );
  374. m_pFFADE_OUT->SetSelected( fadeout );
  375. m_pFFADE_MODULATE->SetSelected( fademodulate );
  376. m_pFFADE_STAYOUT->SetSelected( fadestayout );
  377. m_pFFADE_PURGE->SetSelected( fadepurge );
  378. }
  379. //-----------------------------------------------------------------------------
  380. // Purpose:
  381. // Output : Returns true on success, false on failure.
  382. //-----------------------------------------------------------------------------
  383. bool CBaseActionScreenFadeStartDialog::OnSaveChanges( void )
  384. {
  385. bool bret = BaseClass::OnSaveChanges();
  386. // Grab current settings
  387. ScreenFade_t *f = GetAction()->GetScreenFade();
  388. float duration = f->duration * (1.0f/(float)(1<<SCREENFADE_FRACBITS));
  389. float holdTime = f->holdTime * (1.0f/(float)(1<<SCREENFADE_FRACBITS));
  390. bool fadein = ( f->fadeFlags & FFADE_IN ) ? true : false;
  391. bool fadeout = ( f->fadeFlags & FFADE_OUT ) ? true : false;
  392. bool fademodulate = ( f->fadeFlags & FFADE_MODULATE ) ? true : false;
  393. bool fadestayout = ( f->fadeFlags & FFADE_STAYOUT ) ? true : false;
  394. bool fadepurge = ( f->fadeFlags & FFADE_PURGE ) ? true : false;
  395. int r = f->r;
  396. int g = f->g;
  397. int b = f->b;
  398. int a = f->a;
  399. char sz[ 512 ];
  400. m_pDuration->GetText( sz, sizeof( sz ) );
  401. if ( (float)atof( sz ) != duration )
  402. {
  403. bret = true;
  404. f->duration = (unsigned short)((float)(1<<SCREENFADE_FRACBITS) * (float)atof( sz ) );
  405. }
  406. m_pHoldTime->GetText( sz, sizeof( sz ) );
  407. if ( (float)atof( sz ) != holdTime )
  408. {
  409. bret = true;
  410. f->holdTime = (unsigned short)((float)(1<<SCREENFADE_FRACBITS) * (float)atof( sz ) );
  411. }
  412. int rr, gg, bb, aa;
  413. m_pColor->GetText( sz, sizeof( sz ) );
  414. if ( 4 == sscanf( sz, "%i %i %i %i", &rr, &gg, &bb, &aa ) )
  415. {
  416. rr = clamp( rr, 0, 255 );
  417. gg = clamp( gg, 0, 255 );
  418. bb = clamp( bb, 0, 255 );
  419. aa = clamp( aa, 0, 255 );
  420. if ( rr != r || gg != g || bb != b || aa != a )
  421. {
  422. bret = true;
  423. f->r = rr;
  424. f->g = gg;
  425. f->b = bb;
  426. f->a = aa;
  427. }
  428. }
  429. if ( CheckFlagDifference( m_pFFADE_IN, fadein, FFADE_IN ) )
  430. {
  431. bret = true;
  432. }
  433. if ( CheckFlagDifference( m_pFFADE_OUT, fadeout, FFADE_OUT ) )
  434. {
  435. bret = true;
  436. }
  437. if ( CheckFlagDifference( m_pFFADE_MODULATE, fademodulate, FFADE_MODULATE ) )
  438. {
  439. bret = true;
  440. }
  441. if ( CheckFlagDifference( m_pFFADE_STAYOUT, fadestayout, FFADE_STAYOUT ) )
  442. {
  443. bret = true;
  444. }
  445. if ( CheckFlagDifference( m_pFFADE_PURGE, fadepurge, FFADE_PURGE ) )
  446. {
  447. bret = true;
  448. }
  449. return bret;
  450. }
  451. //-----------------------------------------------------------------------------
  452. // Purpose:
  453. // Input : *check -
  454. // oldval -
  455. // flag -
  456. // Output : Returns true on success, false on failure.
  457. //-----------------------------------------------------------------------------
  458. bool CBaseActionScreenFadeStartDialog::CheckFlagDifference( vgui::CheckButton *check, bool oldval, int flag )
  459. {
  460. bool bret = false;
  461. if ( check->IsSelected() != oldval )
  462. {
  463. ScreenFade_t *f = GetAction()->GetScreenFade();
  464. bret = true;
  465. if ( check->IsSelected() )
  466. {
  467. f->fadeFlags |= flag;
  468. }
  469. else
  470. {
  471. f->fadeFlags &= ~flag;
  472. }
  473. }
  474. return bret;
  475. }
  476. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_SCREENFADE_START, CBaseActionScreenFadeStartDialog );
  477. //-----------------------------------------------------------------------------
  478. // Purpose: Screen Fade
  479. //-----------------------------------------------------------------------------
  480. class CBaseActionTextMessageStartDialog : public CBaseActionEditDialog
  481. {
  482. typedef CBaseActionEditDialog BaseClass;
  483. public:
  484. CBaseActionTextMessageStartDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  485. : BaseClass( parent, action, newaction )
  486. {
  487. m_pFadeInTime = new vgui::TextEntry( this, "TextMessageFadeInTime" );
  488. m_pFadeOutTime = new vgui::TextEntry( this, "TextMessageFadeOutTime" );
  489. m_pHoldTime = new vgui::TextEntry( this, "TextMessageHoldTime" );
  490. m_pFXTime = new vgui::TextEntry( this, "TextMessageFXTime" );
  491. m_pMessageText = new vgui::TextEntry( this, "TextMessageText" );
  492. m_pFontName = new vgui::ComboBox( this, "TextMessageFont", 6, false );
  493. m_pX = new vgui::TextEntry( this, "TextMessageX" );
  494. m_pY = new vgui::TextEntry( this, "TextMessageY" );
  495. m_pColor1 = new vgui::TextEntry( this, "TextMessageColor1" );
  496. m_pColor2 = new vgui::TextEntry( this, "TextMessageColor2" );
  497. m_pEffectType = new vgui::ComboBox( this, "TextMessageEffect", 3, false );
  498. }
  499. virtual void Init( void );
  500. virtual bool OnSaveChanges( void );
  501. private:
  502. CDemoActionTextMessageStart *GetAction( void ) { return static_cast< CDemoActionTextMessageStart * >( m_pAction ); }
  503. void FillInFonts();
  504. bool SaveDifferingFloat( vgui::TextEntry *control, float *curval );
  505. bool SaveDifferingInt( vgui::TextEntry *control, int *curval );
  506. bool SaveDifferingColor( vgui::TextEntry *control, byte *r, byte *g, byte *b, byte *a );
  507. enum
  508. {
  509. FADEINOUT = 0,
  510. FLICKER,
  511. WRITEOUT,
  512. NUM_EFFECT_TYPES
  513. };
  514. struct EffectType
  515. {
  516. char const *name;
  517. };
  518. static EffectType s_EffectTypes[];
  519. static int EffectTypeForName( char const *name );
  520. static char const *NameForEffectType( int type );
  521. vgui::TextEntry *m_pFadeInTime;
  522. vgui::TextEntry *m_pFadeOutTime;
  523. vgui::TextEntry *m_pHoldTime;
  524. vgui::TextEntry *m_pFXTime;
  525. vgui::TextEntry *m_pMessageText;
  526. vgui::ComboBox *m_pFontName;
  527. vgui::ComboBox *m_pEffectType;
  528. vgui::TextEntry *m_pColor1;
  529. vgui::TextEntry *m_pColor2;
  530. vgui::TextEntry *m_pX;
  531. vgui::TextEntry *m_pY;
  532. };
  533. CBaseActionTextMessageStartDialog::EffectType CBaseActionTextMessageStartDialog::s_EffectTypes[] =
  534. {
  535. { "FADEINOUT" },
  536. { "FLICKER" },
  537. { "WRITEOUT " }
  538. };
  539. int CBaseActionTextMessageStartDialog::EffectTypeForName( char const *name )
  540. {
  541. int c = NUM_EFFECT_TYPES;
  542. int i;
  543. for ( i = 0; i < c; i++ )
  544. {
  545. if ( !Q_strcasecmp( s_EffectTypes[ i ].name, name ) )
  546. return i;
  547. }
  548. Assert( 0 );
  549. return 0;
  550. }
  551. char const *CBaseActionTextMessageStartDialog::NameForEffectType( int type )
  552. {
  553. Assert( type >= 0 && type < NUM_EFFECT_TYPES );
  554. return s_EffectTypes[ type ].name;
  555. }
  556. //-----------------------------------------------------------------------------
  557. // Purpose:
  558. //-----------------------------------------------------------------------------
  559. void CBaseActionTextMessageStartDialog::Init( void )
  560. {
  561. LoadControlSettings( "resource\\BaseActionTextMessageStartDialog.res" );
  562. BaseClass::Init();
  563. client_textmessage_t *tm = GetAction()->GetTextMessage();
  564. m_pX->SetText( va( "%f", tm->x ) );
  565. m_pY->SetText( va( "%f", tm->y ) );
  566. m_pFadeInTime->SetText( va( "%.3f", tm->fadein ) );
  567. m_pFadeOutTime->SetText( va( "%.3f", tm->fadeout ) );
  568. m_pHoldTime->SetText( va( "%.3f", tm->holdtime ) );
  569. m_pFXTime->SetText( va( "%.3f", tm->fxtime ) );
  570. m_pColor1->SetText( va( "%i %i %i %i", tm->r1, tm->g1, tm->b1, tm->a1 ) );
  571. m_pColor2->SetText( va( "%i %i %i %i", tm->r2, tm->g2, tm->b2, tm->a2 ) );
  572. m_pMessageText->SetText( GetAction()->GetMessageText() );
  573. FillInFonts();
  574. m_pFontName->SetText( GetAction()->GetFontName() );
  575. int c = NUM_EFFECT_TYPES;
  576. int i;
  577. for ( i = 0; i < c ; i++ )
  578. {
  579. m_pEffectType->AddItem( NameForEffectType( i ), NULL );
  580. }
  581. m_pEffectType->SetText( NameForEffectType( tm->effect ) );
  582. }
  583. void CBaseActionTextMessageStartDialog::FillInFonts()
  584. {
  585. m_pFontName->AddItem( "TextMessageDefault", NULL );
  586. KeyValues *schemeFile = new KeyValues( "Fonts" );
  587. if ( !schemeFile )
  588. return;
  589. if ( schemeFile->LoadFromFile( g_pFileSystem, "resource/SourceScheme.res" ) )
  590. {
  591. // Iterate fonts
  592. for ( KeyValues *kv = schemeFile->FindKey("Fonts", true)->GetFirstSubKey();
  593. kv != NULL;
  594. kv = kv->GetNextKey() )
  595. {
  596. m_pFontName->AddItem( kv->GetName(), NULL );
  597. }
  598. }
  599. schemeFile->deleteThis();
  600. }
  601. //-----------------------------------------------------------------------------
  602. // Purpose:
  603. // Input : *control -
  604. // *curval -
  605. // Output : Returns true on success, false on failure.
  606. //-----------------------------------------------------------------------------
  607. bool CBaseActionTextMessageStartDialog::SaveDifferingFloat( vgui::TextEntry *control, float *curval )
  608. {
  609. bool bret = false;
  610. Assert( curval && control );
  611. char sz[ 512 ];
  612. control->GetText( sz, sizeof( sz ) );
  613. float fcontrol = (float)atof( sz );
  614. if ( fcontrol != *curval )
  615. {
  616. *curval = fcontrol;
  617. bret = true;
  618. }
  619. return bret;
  620. }
  621. //-----------------------------------------------------------------------------
  622. // Purpose:
  623. // Input : *control -
  624. // *curval -
  625. // Output : Returns true on success, false on failure.
  626. //-----------------------------------------------------------------------------
  627. bool CBaseActionTextMessageStartDialog::SaveDifferingInt( vgui::TextEntry *control, int *curval )
  628. {
  629. bool bret = false;
  630. Assert( curval && control );
  631. char sz[ 512 ];
  632. control->GetText( sz, sizeof( sz ) );
  633. int icontrol = atoi( sz );
  634. if ( icontrol != *curval )
  635. {
  636. *curval = icontrol;
  637. bret = true;
  638. }
  639. return bret;
  640. }
  641. bool CBaseActionTextMessageStartDialog::SaveDifferingColor( vgui::TextEntry *control, byte *r, byte *g, byte *b, byte *a )
  642. {
  643. bool bret = false;
  644. Assert( r && g && b && a && control );
  645. char sz[ 512 ];
  646. control->GetText( sz, sizeof( sz ) );
  647. int rr, gg, bb, aa;
  648. if ( sscanf( sz, "%i %i %i %i", &rr, &gg, &bb, &aa ) == 4 )
  649. {
  650. if ( *r != rr )
  651. {
  652. bret = true;
  653. *r = rr;
  654. }
  655. if ( *g != gg )
  656. {
  657. bret = true;
  658. *g = gg;
  659. }
  660. if ( *b != bb )
  661. {
  662. bret = true;
  663. *b = bb;
  664. }
  665. if ( *a != aa )
  666. {
  667. bret = true;
  668. *a = aa;
  669. }
  670. }
  671. return bret;
  672. }
  673. //-----------------------------------------------------------------------------
  674. // Purpose:
  675. // Output : Returns true on success, false on failure.
  676. //-----------------------------------------------------------------------------
  677. bool CBaseActionTextMessageStartDialog::OnSaveChanges( void )
  678. {
  679. bool bret = BaseClass::OnSaveChanges();
  680. client_textmessage_t *tm = GetAction()->GetTextMessage();
  681. bret |= SaveDifferingFloat( m_pFadeInTime, &tm->fadein );
  682. bret |= SaveDifferingFloat( m_pFadeOutTime, &tm->fadeout );
  683. bret |= SaveDifferingFloat( m_pHoldTime, &tm->holdtime );
  684. bret |= SaveDifferingFloat( m_pFXTime, &tm->fxtime );
  685. bret |= SaveDifferingFloat( m_pX, &tm->x );
  686. bret |= SaveDifferingFloat( m_pY, &tm->y );
  687. bret |= SaveDifferingColor( m_pColor1, &tm->r1, &tm->g1, &tm->b1, &tm->a1 );
  688. bret |= SaveDifferingColor( m_pColor2, &tm->r2, &tm->g2, &tm->b2, &tm->a2 );
  689. char sz[ 1024 ];
  690. m_pEffectType->GetText( sz, sizeof( sz ) );
  691. int iEffect = EffectTypeForName( sz );
  692. if ( iEffect != tm->effect )
  693. {
  694. tm->effect = iEffect;
  695. bret = true;
  696. }
  697. m_pMessageText->GetText( sz, sizeof( sz ) );
  698. if ( Q_strcasecmp( sz, GetAction()->GetMessageText() ) )
  699. {
  700. GetAction()->SetMessageText( sz );
  701. bret = true;
  702. }
  703. m_pFontName->GetText( sz, sizeof( sz ) );
  704. if ( Q_strcasecmp( sz, GetAction()->GetFontName() ) )
  705. {
  706. GetAction()->SetFontName( sz );
  707. bret = true;
  708. }
  709. return bret;
  710. }
  711. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_TEXTMESSAGE_START, CBaseActionTextMessageStartDialog );
  712. //-----------------------------------------------------------------------------
  713. // Purpose:
  714. //-----------------------------------------------------------------------------
  715. class CBaseActionPlayCommandsDialog : public CBaseActionEditDialog
  716. {
  717. typedef CBaseActionEditDialog BaseClass;
  718. public:
  719. CBaseActionPlayCommandsDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  720. virtual void Init( void );
  721. // Returns true if changes were effected
  722. virtual bool OnSaveChanges( void );
  723. private:
  724. CDemoActionPlayCommands *GetAction( void ) { return static_cast< CDemoActionPlayCommands * >( m_pAction ); }
  725. vgui::TextEntry *m_pCommands;
  726. };
  727. CBaseActionPlayCommandsDialog::CBaseActionPlayCommandsDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  728. : CBaseActionEditDialog( parent, action, newaction )
  729. {
  730. m_pCommands = new vgui::TextEntry( this, "Commands" );
  731. }
  732. //-----------------------------------------------------------------------------
  733. // Purpose:
  734. //-----------------------------------------------------------------------------
  735. void CBaseActionPlayCommandsDialog::Init( void )
  736. {
  737. LoadControlSettings( "resource\\BaseActionPlayCommandsDialog.res" );
  738. BaseClass::Init();
  739. m_pCommands->SetText( GetAction()->GetCommandStream() );
  740. }
  741. //-----------------------------------------------------------------------------
  742. // Purpose:
  743. // Output : Returns true if changes were effected
  744. //-----------------------------------------------------------------------------
  745. bool CBaseActionPlayCommandsDialog::OnSaveChanges( void )
  746. {
  747. bool bret = BaseClass::OnSaveChanges();
  748. char commands[ 512 ];
  749. m_pCommands->GetText( commands, sizeof( commands ) );
  750. if ( Q_strcasecmp( commands, GetAction()->GetCommandStream() ) )
  751. {
  752. bret = true;
  753. GetAction()->SetCommandStream( commands );
  754. }
  755. return bret;
  756. }
  757. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_PLAYCOMMANDS, CBaseActionPlayCommandsDialog );
  758. //-----------------------------------------------------------------------------
  759. // Purpose:
  760. //-----------------------------------------------------------------------------
  761. class CBaseActionCDTrackStartDialog : public CBaseActionEditDialog
  762. {
  763. typedef CBaseActionEditDialog BaseClass;
  764. public:
  765. CBaseActionCDTrackStartDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  766. virtual void Init( void );
  767. // Returns true if changes were effected
  768. virtual bool OnSaveChanges( void );
  769. private:
  770. CDemoActionCDTrackStart *GetAction( void ) { return static_cast< CDemoActionCDTrackStart * >( m_pAction ); }
  771. vgui::TextEntry *m_pTrackNumber;
  772. };
  773. CBaseActionCDTrackStartDialog::CBaseActionCDTrackStartDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  774. : CBaseActionEditDialog( parent, action, newaction )
  775. {
  776. m_pTrackNumber = new vgui::TextEntry( this, "TrackNumber" );
  777. }
  778. //-----------------------------------------------------------------------------
  779. // Purpose:
  780. //-----------------------------------------------------------------------------
  781. void CBaseActionCDTrackStartDialog::Init( void )
  782. {
  783. LoadControlSettings( "resource\\BaseActionCDTrackStartDialog.res" );
  784. BaseClass::Init();
  785. m_pTrackNumber->SetText( va( "%i", GetAction()->GetTrack() ) );
  786. }
  787. //-----------------------------------------------------------------------------
  788. // Purpose:
  789. // Output : Returns true if changes were effected
  790. //-----------------------------------------------------------------------------
  791. bool CBaseActionCDTrackStartDialog::OnSaveChanges( void )
  792. {
  793. bool bret = BaseClass::OnSaveChanges();
  794. char track[ 512 ];
  795. m_pTrackNumber->GetText( track, sizeof( track ) );
  796. int itrack = atoi( track );
  797. if ( itrack != GetAction()->GetTrack() )
  798. {
  799. bret = true;
  800. GetAction()->SetTrack( itrack );
  801. }
  802. return bret;
  803. }
  804. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_PLAYCDTRACK_START, CBaseActionCDTrackStartDialog );
  805. //-----------------------------------------------------------------------------
  806. // Purpose:
  807. //-----------------------------------------------------------------------------
  808. class CBaseActionPlaySoundStartDialog : public CBaseActionEditDialog
  809. {
  810. DECLARE_CLASS_SIMPLE( CBaseActionPlaySoundStartDialog, CBaseActionEditDialog );
  811. public:
  812. CBaseActionPlaySoundStartDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  813. virtual void Init( void );
  814. // Returns true if changes were effected
  815. virtual bool OnSaveChanges( void );
  816. virtual void OnCommand( char const *command );
  817. private:
  818. CDemoActionPlaySoundStart *GetAction( void ) { return static_cast< CDemoActionPlaySoundStart * >( m_pAction ); }
  819. MESSAGE_FUNC_CHARPTR( OnFileSelected, "FileSelected", fullpath );
  820. vgui::TextEntry *m_pSoundName;
  821. vgui::Button *m_pChooseSound;
  822. vgui::DHANDLE< vgui::FileOpenDialog > m_hFileOpenDialog;
  823. };
  824. CBaseActionPlaySoundStartDialog::CBaseActionPlaySoundStartDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  825. : CBaseActionEditDialog( parent, action, newaction )
  826. {
  827. m_pSoundName = new vgui::TextEntry( this, "SoundName" );
  828. m_pChooseSound = new vgui::Button( this, "ChooseSound", "Choose..." );
  829. }
  830. //-----------------------------------------------------------------------------
  831. // Purpose:
  832. //-----------------------------------------------------------------------------
  833. void CBaseActionPlaySoundStartDialog::Init( void )
  834. {
  835. LoadControlSettings( "resource\\BaseActionPlaySoundStartDialog.res" );
  836. BaseClass::Init();
  837. m_pSoundName->SetText( GetAction()->GetSoundName() );
  838. }
  839. //-----------------------------------------------------------------------------
  840. // Purpose:
  841. // Output : Returns true if changes were effected
  842. //-----------------------------------------------------------------------------
  843. bool CBaseActionPlaySoundStartDialog::OnSaveChanges( void )
  844. {
  845. bool bret = BaseClass::OnSaveChanges();
  846. char soundname[ 512 ];
  847. m_pSoundName->GetText( soundname, sizeof( soundname ) );
  848. if ( Q_strcasecmp( soundname, GetAction()->GetSoundName() ) )
  849. {
  850. bret = true;
  851. GetAction()->SetSoundName( soundname );
  852. }
  853. return bret;
  854. }
  855. void CBaseActionPlaySoundStartDialog::OnFileSelected( char const *fullpath )
  856. {
  857. if ( !fullpath || !fullpath[ 0 ] )
  858. return;
  859. char relativepath[ 512 ];
  860. g_pFileSystem->FullPathToRelativePath( fullpath, relativepath, sizeof( relativepath ) );
  861. Q_FixSlashes( relativepath );
  862. char *soundname = relativepath;
  863. if ( StringHasPrefix( relativepath, "sound\\" ) )
  864. {
  865. soundname += strlen( "sound\\" );
  866. }
  867. m_pSoundName->SetText( soundname );
  868. if ( m_hFileOpenDialog )
  869. {
  870. m_hFileOpenDialog->MarkForDeletion();
  871. }
  872. }
  873. void CBaseActionPlaySoundStartDialog::OnCommand( char const *command )
  874. {
  875. if ( !Q_strcasecmp( command, "choosesound" ) )
  876. {
  877. if ( !m_hFileOpenDialog.Get() )
  878. {
  879. m_hFileOpenDialog = new vgui::FileOpenDialog( this, "Choose .wav file", true );
  880. m_hFileOpenDialog->SetDeleteSelfOnClose( false );
  881. }
  882. if ( m_hFileOpenDialog )
  883. {
  884. char startPath[ MAX_PATH ];
  885. Q_strncpy( startPath, com_gamedir, sizeof( startPath ) );
  886. Q_FixSlashes( startPath );
  887. m_hFileOpenDialog->SetStartDirectory( va( "%s/sound", startPath ) );
  888. m_hFileOpenDialog->DoModal( false );
  889. }
  890. return;
  891. }
  892. BaseClass::OnCommand( command );
  893. }
  894. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_PLAYSOUND_START, CBaseActionPlaySoundStartDialog );
  895. class CBaseActionWithStopTimeDialog : public CBaseActionEditDialog
  896. {
  897. typedef CBaseActionEditDialog BaseClass;
  898. public:
  899. CBaseActionWithStopTimeDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  900. virtual void Init( void );
  901. // Returns true if changes were effected
  902. virtual bool OnSaveChanges( void );
  903. private:
  904. CBaseDemoActionWithStopTime *GetAction( void ) { return static_cast< CBaseDemoActionWithStopTime * >( m_pAction ); }
  905. vgui::ComboBox *m_pStopType;
  906. vgui::TextEntry *m_pStop;
  907. };
  908. CBaseActionWithStopTimeDialog::CBaseActionWithStopTimeDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  909. : CBaseActionEditDialog( parent, action, newaction )
  910. {
  911. m_pStop = new vgui::TextEntry( this, "ActionStop" );
  912. m_pStopType = new vgui::ComboBox( this, "ActionStopType", (int)2, false );
  913. for ( int i = 1; i < (int)NUM_TIMING_TYPES; i++ )
  914. {
  915. m_pStopType->AddItem( CBaseDemoAction::NameForTimingType( (DEMOACTIONTIMINGTYPE)i ), NULL );
  916. }
  917. }
  918. //-----------------------------------------------------------------------------
  919. // Purpose:
  920. //-----------------------------------------------------------------------------
  921. void CBaseActionWithStopTimeDialog::Init( void )
  922. {
  923. BaseClass::Init();
  924. if ( GetAction()->m_bUsingStopTick )
  925. {
  926. m_pStopType->SetText( "TimeUseTick" );
  927. m_pStop->SetText( va( "%i", GetAction()->m_nStopTick ) );
  928. }
  929. else
  930. {
  931. m_pStopType->SetText( "TimeUseClock" );
  932. m_pStop->SetText( va( "%.3f", GetAction()->m_flStopTime ) );
  933. }
  934. }
  935. //-----------------------------------------------------------------------------
  936. // Purpose:
  937. // Output : Returns true if changes were effected
  938. //-----------------------------------------------------------------------------
  939. bool CBaseActionWithStopTimeDialog::OnSaveChanges( void )
  940. {
  941. bool bret = BaseClass::OnSaveChanges();
  942. char stoptype[ 512 ];
  943. m_pStopType->GetText( stoptype, sizeof( stoptype ) );
  944. char stop[ 512 ];
  945. m_pStop->GetText( stop, sizeof( stop ) );
  946. float fstop = (float)atof( stop );
  947. int istop = (int)atoi( stop );
  948. if ( !Q_strcasecmp( stoptype, "TimeUseTick" ) )
  949. {
  950. if ( GetAction()->m_nStopTick != istop )
  951. {
  952. bret = true;
  953. GetAction()->SetStopTick( istop );
  954. GetAction()->SetStopTime( -1.0f );
  955. }
  956. }
  957. else
  958. {
  959. if ( GetAction()->m_flStopTime != fstop )
  960. {
  961. bret = true;
  962. GetAction()->SetStopTime( fstop );
  963. GetAction()->SetStopTick( -1 );
  964. }
  965. }
  966. return bret;
  967. }
  968. //-----------------------------------------------------------------------------
  969. // Purpose:
  970. //-----------------------------------------------------------------------------
  971. class CBaseActionChangePlaybackRateDialog : public CBaseActionWithStopTimeDialog
  972. {
  973. typedef CBaseActionWithStopTimeDialog BaseClass;
  974. public:
  975. CBaseActionChangePlaybackRateDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  976. virtual void Init( void );
  977. // Returns true if changes were effected
  978. virtual bool OnSaveChanges( void );
  979. private:
  980. CDemoActionChangePlaybackRate *GetAction( void ) { return static_cast< CDemoActionChangePlaybackRate * >( m_pAction ); }
  981. vgui::TextEntry *m_pRate;
  982. };
  983. CBaseActionChangePlaybackRateDialog::CBaseActionChangePlaybackRateDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  984. : BaseClass( parent, action, newaction )
  985. {
  986. m_pRate = new vgui::TextEntry( this, "PlaybackRate" );
  987. }
  988. //-----------------------------------------------------------------------------
  989. // Purpose:
  990. //-----------------------------------------------------------------------------
  991. void CBaseActionChangePlaybackRateDialog::Init( void )
  992. {
  993. LoadControlSettings( "resource\\BaseActionPlaybackRateDialog.res" );
  994. BaseClass::Init();
  995. m_pRate->SetText( va( "%f", GetAction()->GetPlaybackRate() ) );
  996. }
  997. //-----------------------------------------------------------------------------
  998. // Purpose:
  999. // Output : Returns true if changes were effected
  1000. //-----------------------------------------------------------------------------
  1001. bool CBaseActionChangePlaybackRateDialog::OnSaveChanges( void )
  1002. {
  1003. bool bret = BaseClass::OnSaveChanges();
  1004. char rate[ 512 ];
  1005. m_pRate->GetText( rate, sizeof( rate ) );
  1006. float frate = (float)atof( rate );
  1007. if ( GetAction()->GetPlaybackRate() != frate )
  1008. {
  1009. bret = true;
  1010. GetAction()->SetPlaybackRate( frate );
  1011. }
  1012. return bret;
  1013. }
  1014. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_CHANGEPLAYBACKRATE, CBaseActionChangePlaybackRateDialog );
  1015. //-----------------------------------------------------------------------------
  1016. // Purpose:
  1017. //-----------------------------------------------------------------------------
  1018. class CBaseActionPauseDialog : public CBaseActionEditDialog
  1019. {
  1020. typedef CBaseActionEditDialog BaseClass;
  1021. public:
  1022. CBaseActionPauseDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  1023. virtual void Init( void );
  1024. // Returns true if changes were effected
  1025. virtual bool OnSaveChanges( void );
  1026. private:
  1027. CDemoActionPausePlayback *GetAction( void ) { return static_cast< CDemoActionPausePlayback * >( m_pAction ); }
  1028. vgui::TextEntry *m_pPauseTime;
  1029. };
  1030. CBaseActionPauseDialog::CBaseActionPauseDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  1031. : BaseClass( parent, action, newaction )
  1032. {
  1033. m_pPauseTime = new vgui::TextEntry( this, "PauseTime" );
  1034. }
  1035. //-----------------------------------------------------------------------------
  1036. // Purpose:
  1037. //-----------------------------------------------------------------------------
  1038. void CBaseActionPauseDialog::Init( void )
  1039. {
  1040. LoadControlSettings( "resource\\BaseActionPauseDialog.res" );
  1041. BaseClass::Init();
  1042. m_pPauseTime->SetText( va( "%f", GetAction()->GetPauseTime() ) );
  1043. }
  1044. //-----------------------------------------------------------------------------
  1045. // Purpose:
  1046. // Output : Returns true if changes were effected
  1047. //-----------------------------------------------------------------------------
  1048. bool CBaseActionPauseDialog::OnSaveChanges( void )
  1049. {
  1050. bool bret = BaseClass::OnSaveChanges();
  1051. char pausetime[ 512 ];
  1052. m_pPauseTime->GetText( pausetime, sizeof( pausetime ) );
  1053. float ftime = (float)atof( pausetime );
  1054. if ( GetAction()->GetPauseTime() != ftime )
  1055. {
  1056. bret = true;
  1057. GetAction()->SetPauseTime( ftime );
  1058. }
  1059. return bret;
  1060. }
  1061. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_PAUSE, CBaseActionPauseDialog );
  1062. // Fonts
  1063. /*
  1064. // if a font fails to load then the subsequent fonts will replace
  1065. "Default"
  1066. "DefaultUnderline"
  1067. "DefaultSmall"
  1068. "DefaultVerySmall"
  1069. "DefaultLarge"
  1070. "Marlett"
  1071. "Trebuchet24"
  1072. "Trebuchet20"
  1073. "Trebuchet18"
  1074. "DefaultFixed"
  1075. */
  1076. //-----------------------------------------------------------------------------
  1077. // Purpose:
  1078. //-----------------------------------------------------------------------------
  1079. class CBaseActionZoomDialog : public CBaseActionEditDialog
  1080. {
  1081. typedef CBaseActionEditDialog BaseClass;
  1082. public:
  1083. CBaseActionZoomDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  1084. virtual void Init( void );
  1085. // Returns true if changes were effected
  1086. virtual bool OnSaveChanges( void );
  1087. private:
  1088. CDemoActionZoom *GetAction( void ) { return static_cast< CDemoActionZoom * >( m_pAction ); }
  1089. vgui::CheckButton *m_pSpline;
  1090. vgui::CheckButton *m_pStayout;
  1091. vgui::TextEntry *m_pFinalFOV;
  1092. vgui::TextEntry *m_pOutRate;
  1093. vgui::TextEntry *m_pInRate;
  1094. vgui::TextEntry *m_pHoldTime;
  1095. };
  1096. CBaseActionZoomDialog::CBaseActionZoomDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  1097. : BaseClass( parent, action, newaction )
  1098. {
  1099. m_pFinalFOV = new vgui::TextEntry( this, "ZoomFOV" );
  1100. m_pOutRate = new vgui::TextEntry( this, "ZoomOut" );
  1101. m_pInRate = new vgui::TextEntry( this, "ZoomIn" );
  1102. m_pHoldTime = new vgui::TextEntry( this, "ZoomHold" );
  1103. m_pSpline = new vgui::CheckButton( this, "ZoomSpline", "Spline" );
  1104. m_pStayout = new vgui::CheckButton( this, "ZoomStayout", "Stay Out" );
  1105. }
  1106. //-----------------------------------------------------------------------------
  1107. // Purpose:
  1108. //-----------------------------------------------------------------------------
  1109. void CBaseActionZoomDialog::Init( void )
  1110. {
  1111. LoadControlSettings( "resource\\BaseActionZoomDialog.res" );
  1112. BaseClass::Init();
  1113. m_pFinalFOV->SetText( va( "%f", GetAction()->m_flFinalFOV ) );
  1114. m_pOutRate->SetText( va( "%f", GetAction()->m_flFOVRateOut ) );
  1115. m_pInRate->SetText( va( "%f", GetAction()->m_flFOVRateIn ) );
  1116. m_pHoldTime->SetText( va( "%f", GetAction()->m_flHoldTime ) );
  1117. m_pSpline->SetSelected( GetAction()->m_bSpline );
  1118. m_pStayout->SetSelected( GetAction()->m_bStayout );
  1119. }
  1120. //-----------------------------------------------------------------------------
  1121. // Purpose:
  1122. // Output : Returns true if changes were effected
  1123. //-----------------------------------------------------------------------------
  1124. bool CBaseActionZoomDialog::OnSaveChanges( void )
  1125. {
  1126. bool bret = BaseClass::OnSaveChanges();
  1127. char sz[ 512 ];
  1128. m_pFinalFOV->GetText( sz, sizeof( sz ) );
  1129. float f = (float)atof( sz );
  1130. if ( GetAction()->m_flFinalFOV != f )
  1131. {
  1132. bret = true;
  1133. GetAction()->m_flFinalFOV = f;
  1134. }
  1135. m_pOutRate->GetText( sz, sizeof( sz ) );
  1136. f = (float)atof( sz );
  1137. if ( GetAction()->m_flFOVRateOut != f )
  1138. {
  1139. bret = true;
  1140. GetAction()->m_flFOVRateOut = f;
  1141. }
  1142. m_pInRate->GetText( sz, sizeof( sz ) );
  1143. f = (float)atof( sz );
  1144. if ( GetAction()->m_flFOVRateIn != f )
  1145. {
  1146. bret = true;
  1147. GetAction()->m_flFOVRateIn = f;
  1148. }
  1149. m_pHoldTime->GetText( sz, sizeof( sz ) );
  1150. f = (float)atof( sz );
  1151. if ( GetAction()->m_flHoldTime != f )
  1152. {
  1153. bret = true;
  1154. GetAction()->m_flHoldTime = f;
  1155. }
  1156. if ( m_pSpline->IsSelected() != GetAction()->m_bSpline )
  1157. {
  1158. bret = true;
  1159. GetAction()->m_bSpline = m_pSpline->IsSelected();
  1160. }
  1161. if ( m_pStayout->IsSelected() != GetAction()->m_bStayout )
  1162. {
  1163. bret = true;
  1164. GetAction()->m_bStayout = m_pStayout->IsSelected();
  1165. }
  1166. return bret;
  1167. }
  1168. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_ZOOM, CBaseActionZoomDialog );