button_switcher.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "../idlib/precompiled.h"
  2. #pragma hdrstop
  3. #include "Game_local.h"
  4. const idEventDef EV_ButtonSwitcher_activate( "buttonswitcheractivate", "f" );
  5. CLASS_DECLARATION( idAnimated, idButtonSwitcher )
  6. EVENT( EV_ButtonSwitcher_activate, idButtonSwitcher::Event_buttonswitcheractivate)
  7. END_CLASS
  8. void idButtonSwitcher::Save( idSaveGame *savefile ) const
  9. {
  10. savefile->WriteInt(state);
  11. savefile->WriteBool(active);
  12. }
  13. void idButtonSwitcher::Restore( idRestoreGame *savefile )
  14. {
  15. savefile->ReadInt(state);
  16. savefile->ReadBool(active);
  17. }
  18. void idButtonSwitcher::Spawn( void )
  19. {
  20. GetPhysics()->SetContents( 0 );
  21. this->noGrab = true;
  22. this->isFrobbable = false;
  23. state = 0;
  24. active = false;
  25. }
  26. void idButtonSwitcher::Event_buttonswitcheractivate( int value )
  27. {
  28. Event_PlayAnim( "turn", 4);
  29. GetPhysics()->SetContents( CONTENTS_RENDERMODEL );
  30. GetPhysics()->SetClipMask( MASK_SOLID | CONTENTS_MOVEABLECLIP );
  31. this->isFrobbable = true;
  32. active = true;
  33. }
  34. void idButtonSwitcher::OnFrob( idEntity* activator )
  35. {
  36. if (!active)
  37. return;
  38. StartSound( "snd_press", SND_CHANNEL_BODY, 0, false, NULL );
  39. if (state == 0)
  40. {
  41. state = 1;
  42. Event_PlayAnim( "_0_to_1", 4);
  43. CallScript("script1");
  44. SetSkin(declManager->FindSkin( "skins/button_switcher/skin_1" ));
  45. }
  46. else if (state == 1)
  47. {
  48. state = 2;
  49. Event_PlayAnim( "_1_to_2", 4);
  50. CallScript("script2");
  51. SetSkin(declManager->FindSkin( "skins/button_switcher/skin_2" ));
  52. }
  53. else
  54. {
  55. state = 0;
  56. Event_PlayAnim( "_2_to_0", 4);
  57. CallScript("script0");
  58. SetSkin(declManager->FindSkin( "skins/button_switcher/skin" ));
  59. }
  60. }
  61. void idButtonSwitcher::CallScript(const char* name)
  62. {
  63. idStr scriptName = spawnArgs.GetString( name );
  64. if (scriptName.Length() <= 0)
  65. return;
  66. const function_t *scriptFunction;
  67. scriptFunction = gameLocal.program.FindFunction( scriptName );
  68. if ( !scriptFunction )
  69. return;
  70. idThread *thread;
  71. thread = new idThread( scriptFunction );
  72. thread->DelayedStart( 0 );
  73. }
  74. /*
  75. void idLever::Think( void )
  76. {
  77. UpdateStates();
  78. idAnimatedEntity::Think();
  79. idAnimatedEntity::Present();
  80. }*/