ctactor.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. class CTActor extends CTObjectFollower
  2. {
  3. protected int m_Index;
  4. protected Widget m_Root;
  5. protected TextWidget m_IndexWidget;
  6. protected string m_HandsItem;
  7. protected ref array<string> m_Items;
  8. protected EntityAI m_HandsItemObj;
  9. void CTActor( int index, vector pos, vector orient, string type, array<string> items, string hands_item, CameraToolsMenu parent )
  10. {
  11. m_FollowerRoot = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/camera_tools/event_tracker.layout", null );
  12. m_FollowerButton = m_FollowerRoot.FindAnyWidget( "IconPanel" );
  13. m_IndexWidget = TextWidget.Cast( m_FollowerRoot.FindAnyWidget( "Text" ) );
  14. m_Index = index;
  15. m_Position = pos;
  16. m_Orientation = orient;
  17. m_Menu = parent;
  18. m_IndexWidget.SetText( m_Index.ToString() );
  19. m_FollowerRoot.SetHandler( this );
  20. CreateFollowedObject( type );
  21. SetHandsItem( hands_item );
  22. SetItems( items );
  23. }
  24. void ~CTActor()
  25. {
  26. delete m_FollowerRoot;
  27. }
  28. string GetActorType()
  29. {
  30. if( m_FollowedObject )
  31. return m_FollowedObject.GetType();
  32. return "";
  33. }
  34. void AddItem( string item )
  35. {
  36. PlayerBase p = PlayerBase.Cast( m_FollowedObject );
  37. if( p.GetInventory().CreateAttachment( item ) )
  38. m_Items.Insert( item );
  39. }
  40. void SetItems( array<string> items )
  41. {
  42. m_Items = items;
  43. PlayerBase p = PlayerBase.Cast( m_FollowedObject );
  44. if( p )
  45. {
  46. foreach( string item : items )
  47. {
  48. p.GetInventory().CreateAttachment( item );
  49. }
  50. }
  51. }
  52. array<string> GetItems()
  53. {
  54. return m_Items;
  55. }
  56. void SetHandsItem( string item )
  57. {
  58. m_HandsItem = item;
  59. if ( m_HandsItemObj && m_FollowedObject)
  60. {
  61. HumanInventory.Cast( m_FollowedObject.GetInventory() ).LocalDestroyEntity( m_HandsItemObj );
  62. GetGame().ObjectDelete( m_HandsItemObj );
  63. }
  64. if (item)
  65. {
  66. HumanInventory.Cast( m_FollowedObject.GetInventory() ).CreateInHands( item );
  67. }
  68. }
  69. string GetHandsItem()
  70. {
  71. return m_HandsItem;
  72. }
  73. void Reset()
  74. {
  75. string type = m_FollowedObject.GetType();
  76. DestroyFollowedObject();
  77. CreateFollowedObject( type );
  78. SetHandsItem( m_HandsItem );
  79. SetItems( GetItems() );
  80. }
  81. }