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.

1441 lines
40 KiB

  1. //========= Copyright 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. int fadein = f->fadeFlags & FFADE_IN;
  362. int fadeout = f->fadeFlags & FFADE_OUT;
  363. int fademodulate = f->fadeFlags & FFADE_MODULATE;
  364. int fadestayout = f->fadeFlags & FFADE_STAYOUT;
  365. int fadepurge = f->fadeFlags & FFADE_PURGE;
  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 != 0 );
  374. m_pFFADE_OUT->SetSelected( fadeout != 0 );
  375. m_pFFADE_MODULATE->SetSelected( fademodulate != 0 );
  376. m_pFFADE_STAYOUT->SetSelected( fadestayout != 0 );
  377. m_pFFADE_PURGE->SetSelected( fadepurge != 0 );
  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;
  391. bool fadeout = ( f->fadeFlags & FFADE_OUT ) != 0;
  392. bool fademodulate = ( f->fadeFlags & FFADE_MODULATE ) != 0;
  393. bool fadestayout = ( f->fadeFlags & FFADE_STAYOUT ) != 0;
  394. bool fadepurge = ( f->fadeFlags & FFADE_PURGE ) != 0;
  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 ( !Q_strnicmp( relativepath, "sound\\", strlen( "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. }
  881. if ( m_hFileOpenDialog )
  882. {
  883. char startPath[ MAX_PATH ];
  884. Q_strncpy( startPath, com_gamedir, sizeof( startPath ) );
  885. Q_FixSlashes( startPath );
  886. m_hFileOpenDialog->SetStartDirectory( va( "%s/sound", startPath ) );
  887. m_hFileOpenDialog->DoModal( false );
  888. }
  889. return;
  890. }
  891. BaseClass::OnCommand( command );
  892. }
  893. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_PLAYSOUND_START, CBaseActionPlaySoundStartDialog );
  894. class CBaseActionWithStopTimeDialog : public CBaseActionEditDialog
  895. {
  896. typedef CBaseActionEditDialog BaseClass;
  897. public:
  898. CBaseActionWithStopTimeDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  899. virtual void Init( void );
  900. // Returns true if changes were effected
  901. virtual bool OnSaveChanges( void );
  902. private:
  903. CBaseDemoActionWithStopTime *GetAction( void ) { return static_cast< CBaseDemoActionWithStopTime * >( m_pAction ); }
  904. vgui::ComboBox *m_pStopType;
  905. vgui::TextEntry *m_pStop;
  906. };
  907. CBaseActionWithStopTimeDialog::CBaseActionWithStopTimeDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  908. : CBaseActionEditDialog( parent, action, newaction )
  909. {
  910. m_pStop = new vgui::TextEntry( this, "ActionStop" );
  911. m_pStopType = new vgui::ComboBox( this, "ActionStopType", (int)2, false );
  912. for ( int i = 1; i < (int)NUM_TIMING_TYPES; i++ )
  913. {
  914. m_pStopType->AddItem( CBaseDemoAction::NameForTimingType( (DEMOACTIONTIMINGTYPE)i ), NULL );
  915. }
  916. }
  917. //-----------------------------------------------------------------------------
  918. // Purpose:
  919. //-----------------------------------------------------------------------------
  920. void CBaseActionWithStopTimeDialog::Init( void )
  921. {
  922. BaseClass::Init();
  923. if ( GetAction()->m_bUsingStopTick )
  924. {
  925. m_pStopType->SetText( "TimeUseTick" );
  926. m_pStop->SetText( va( "%i", GetAction()->m_nStopTick ) );
  927. }
  928. else
  929. {
  930. m_pStopType->SetText( "TimeUseClock" );
  931. m_pStop->SetText( va( "%.3f", GetAction()->m_flStopTime ) );
  932. }
  933. }
  934. //-----------------------------------------------------------------------------
  935. // Purpose:
  936. // Output : Returns true if changes were effected
  937. //-----------------------------------------------------------------------------
  938. bool CBaseActionWithStopTimeDialog::OnSaveChanges( void )
  939. {
  940. bool bret = BaseClass::OnSaveChanges();
  941. char stoptype[ 512 ];
  942. m_pStopType->GetText( stoptype, sizeof( stoptype ) );
  943. char stop[ 512 ];
  944. m_pStop->GetText( stop, sizeof( stop ) );
  945. float fstop = (float)atof( stop );
  946. int istop = (int)atoi( stop );
  947. if ( !Q_strcasecmp( stoptype, "TimeUseTick" ) )
  948. {
  949. if ( GetAction()->m_nStopTick != istop )
  950. {
  951. bret = true;
  952. GetAction()->SetStopTick( istop );
  953. GetAction()->SetStopTime( -1.0f );
  954. }
  955. }
  956. else
  957. {
  958. if ( GetAction()->m_flStopTime != fstop )
  959. {
  960. bret = true;
  961. GetAction()->SetStopTime( fstop );
  962. GetAction()->SetStopTick( -1 );
  963. }
  964. }
  965. return bret;
  966. }
  967. //-----------------------------------------------------------------------------
  968. // Purpose:
  969. //-----------------------------------------------------------------------------
  970. class CBaseActionChangePlaybackRateDialog : public CBaseActionWithStopTimeDialog
  971. {
  972. typedef CBaseActionWithStopTimeDialog BaseClass;
  973. public:
  974. CBaseActionChangePlaybackRateDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  975. virtual void Init( void );
  976. // Returns true if changes were effected
  977. virtual bool OnSaveChanges( void );
  978. private:
  979. CDemoActionChangePlaybackRate *GetAction( void ) { return static_cast< CDemoActionChangePlaybackRate * >( m_pAction ); }
  980. vgui::TextEntry *m_pRate;
  981. };
  982. CBaseActionChangePlaybackRateDialog::CBaseActionChangePlaybackRateDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  983. : BaseClass( parent, action, newaction )
  984. {
  985. m_pRate = new vgui::TextEntry( this, "PlaybackRate" );
  986. }
  987. //-----------------------------------------------------------------------------
  988. // Purpose:
  989. //-----------------------------------------------------------------------------
  990. void CBaseActionChangePlaybackRateDialog::Init( void )
  991. {
  992. LoadControlSettings( "resource\\BaseActionPlaybackRateDialog.res" );
  993. BaseClass::Init();
  994. m_pRate->SetText( va( "%f", GetAction()->GetPlaybackRate() ) );
  995. }
  996. //-----------------------------------------------------------------------------
  997. // Purpose:
  998. // Output : Returns true if changes were effected
  999. //-----------------------------------------------------------------------------
  1000. bool CBaseActionChangePlaybackRateDialog::OnSaveChanges( void )
  1001. {
  1002. bool bret = BaseClass::OnSaveChanges();
  1003. char rate[ 512 ];
  1004. m_pRate->GetText( rate, sizeof( rate ) );
  1005. float frate = (float)atof( rate );
  1006. if ( GetAction()->GetPlaybackRate() != frate )
  1007. {
  1008. bret = true;
  1009. GetAction()->SetPlaybackRate( frate );
  1010. }
  1011. return bret;
  1012. }
  1013. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_CHANGEPLAYBACKRATE, CBaseActionChangePlaybackRateDialog );
  1014. //-----------------------------------------------------------------------------
  1015. // Purpose:
  1016. //-----------------------------------------------------------------------------
  1017. class CBaseActionPauseDialog : public CBaseActionEditDialog
  1018. {
  1019. typedef CBaseActionEditDialog BaseClass;
  1020. public:
  1021. CBaseActionPauseDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  1022. virtual void Init( void );
  1023. // Returns true if changes were effected
  1024. virtual bool OnSaveChanges( void );
  1025. private:
  1026. CDemoActionPausePlayback *GetAction( void ) { return static_cast< CDemoActionPausePlayback * >( m_pAction ); }
  1027. vgui::TextEntry *m_pPauseTime;
  1028. };
  1029. CBaseActionPauseDialog::CBaseActionPauseDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  1030. : BaseClass( parent, action, newaction )
  1031. {
  1032. m_pPauseTime = new vgui::TextEntry( this, "PauseTime" );
  1033. }
  1034. //-----------------------------------------------------------------------------
  1035. // Purpose:
  1036. //-----------------------------------------------------------------------------
  1037. void CBaseActionPauseDialog::Init( void )
  1038. {
  1039. LoadControlSettings( "resource\\BaseActionPauseDialog.res" );
  1040. BaseClass::Init();
  1041. m_pPauseTime->SetText( va( "%f", GetAction()->GetPauseTime() ) );
  1042. }
  1043. //-----------------------------------------------------------------------------
  1044. // Purpose:
  1045. // Output : Returns true if changes were effected
  1046. //-----------------------------------------------------------------------------
  1047. bool CBaseActionPauseDialog::OnSaveChanges( void )
  1048. {
  1049. bool bret = BaseClass::OnSaveChanges();
  1050. char pausetime[ 512 ];
  1051. m_pPauseTime->GetText( pausetime, sizeof( pausetime ) );
  1052. float ftime = (float)atof( pausetime );
  1053. if ( GetAction()->GetPauseTime() != ftime )
  1054. {
  1055. bret = true;
  1056. GetAction()->SetPauseTime( ftime );
  1057. }
  1058. return bret;
  1059. }
  1060. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_PAUSE, CBaseActionPauseDialog );
  1061. // Fonts
  1062. /*
  1063. // if a font fails to load then the subsequent fonts will replace
  1064. "Default"
  1065. "DefaultUnderline"
  1066. "DefaultSmall"
  1067. "DefaultVerySmall"
  1068. "DefaultLarge"
  1069. "Marlett"
  1070. "Trebuchet24"
  1071. "Trebuchet20"
  1072. "Trebuchet18"
  1073. "DefaultFixed"
  1074. */
  1075. //-----------------------------------------------------------------------------
  1076. // Purpose:
  1077. //-----------------------------------------------------------------------------
  1078. class CBaseActionZoomDialog : public CBaseActionEditDialog
  1079. {
  1080. typedef CBaseActionEditDialog BaseClass;
  1081. public:
  1082. CBaseActionZoomDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction );
  1083. virtual void Init( void );
  1084. // Returns true if changes were effected
  1085. virtual bool OnSaveChanges( void );
  1086. private:
  1087. CDemoActionZoom *GetAction( void ) { return static_cast< CDemoActionZoom * >( m_pAction ); }
  1088. vgui::CheckButton *m_pSpline;
  1089. vgui::CheckButton *m_pStayout;
  1090. vgui::TextEntry *m_pFinalFOV;
  1091. vgui::TextEntry *m_pOutRate;
  1092. vgui::TextEntry *m_pInRate;
  1093. vgui::TextEntry *m_pHoldTime;
  1094. };
  1095. CBaseActionZoomDialog::CBaseActionZoomDialog( CDemoEditorPanel *parent, CBaseDemoAction *action, bool newaction )
  1096. : BaseClass( parent, action, newaction )
  1097. {
  1098. m_pFinalFOV = new vgui::TextEntry( this, "ZoomFOV" );
  1099. m_pOutRate = new vgui::TextEntry( this, "ZoomOut" );
  1100. m_pInRate = new vgui::TextEntry( this, "ZoomIn" );
  1101. m_pHoldTime = new vgui::TextEntry( this, "ZoomHold" );
  1102. m_pSpline = new vgui::CheckButton( this, "ZoomSpline", "Spline" );
  1103. m_pStayout = new vgui::CheckButton( this, "ZoomStayout", "Stay Out" );
  1104. }
  1105. //-----------------------------------------------------------------------------
  1106. // Purpose:
  1107. //-----------------------------------------------------------------------------
  1108. void CBaseActionZoomDialog::Init( void )
  1109. {
  1110. LoadControlSettings( "resource\\BaseActionZoomDialog.res" );
  1111. BaseClass::Init();
  1112. m_pFinalFOV->SetText( va( "%f", GetAction()->m_flFinalFOV ) );
  1113. m_pOutRate->SetText( va( "%f", GetAction()->m_flFOVRateOut ) );
  1114. m_pInRate->SetText( va( "%f", GetAction()->m_flFOVRateIn ) );
  1115. m_pHoldTime->SetText( va( "%f", GetAction()->m_flHoldTime ) );
  1116. m_pSpline->SetSelected( GetAction()->m_bSpline );
  1117. m_pStayout->SetSelected( GetAction()->m_bStayout );
  1118. }
  1119. //-----------------------------------------------------------------------------
  1120. // Purpose:
  1121. // Output : Returns true if changes were effected
  1122. //-----------------------------------------------------------------------------
  1123. bool CBaseActionZoomDialog::OnSaveChanges( void )
  1124. {
  1125. bool bret = BaseClass::OnSaveChanges();
  1126. char sz[ 512 ];
  1127. m_pFinalFOV->GetText( sz, sizeof( sz ) );
  1128. float f = (float)atof( sz );
  1129. if ( GetAction()->m_flFinalFOV != f )
  1130. {
  1131. bret = true;
  1132. GetAction()->m_flFinalFOV = f;
  1133. }
  1134. m_pOutRate->GetText( sz, sizeof( sz ) );
  1135. f = (float)atof( sz );
  1136. if ( GetAction()->m_flFOVRateOut != f )
  1137. {
  1138. bret = true;
  1139. GetAction()->m_flFOVRateOut = f;
  1140. }
  1141. m_pInRate->GetText( sz, sizeof( sz ) );
  1142. f = (float)atof( sz );
  1143. if ( GetAction()->m_flFOVRateIn != f )
  1144. {
  1145. bret = true;
  1146. GetAction()->m_flFOVRateIn = f;
  1147. }
  1148. m_pHoldTime->GetText( sz, sizeof( sz ) );
  1149. f = (float)atof( sz );
  1150. if ( GetAction()->m_flHoldTime != f )
  1151. {
  1152. bret = true;
  1153. GetAction()->m_flHoldTime = f;
  1154. }
  1155. if ( m_pSpline->IsSelected() != GetAction()->m_bSpline )
  1156. {
  1157. bret = true;
  1158. GetAction()->m_bSpline = m_pSpline->IsSelected();
  1159. }
  1160. if ( m_pStayout->IsSelected() != GetAction()->m_bStayout )
  1161. {
  1162. bret = true;
  1163. GetAction()->m_bStayout = m_pStayout->IsSelected();
  1164. }
  1165. return bret;
  1166. }
  1167. DECLARE_DEMOACTIONEDIT( DEMO_ACTION_ZOOM, CBaseActionZoomDialog );