Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/Items/Components/Machines/Controller.cs
2 using Microsoft.Xna.Framework.Graphics;
3 using System.ComponentModel;
4 
6 {
7  partial class Controller : ItemComponent
8  {
9  private bool chatBoxOriginalState;
10  private bool isHUDsHidden;
11 
12  public override void DrawHUD(SpriteBatch spriteBatch, Character character)
13  {
14  if (focusTarget != null && character.ViewTarget == focusTarget)
15  {
16  foreach (ItemComponent ic in focusTarget.Components)
17  {
18  if (ic.ShouldDrawHUD(character))
19  {
20  ic.DrawHUD(spriteBatch, character);
21  }
22  }
23  }
24  }
25 
26  partial void HideHUDs(bool value)
27  {
28  if (isHUDsHidden == value) { return; }
29  if (value == true)
30  {
32  ToggleChatBox(false, storeOriginalState: true);
33  }
34  else
35  {
37  ToggleChatBox(chatBoxOriginalState, storeOriginalState: false);
38  }
39  isHUDsHidden = value;
40  }
41 
42  private void ToggleChatBox(bool value, bool storeOriginalState)
43  {
44  var crewManager = GameMain.GameSession?.CrewManager;
45  if (crewManager == null) { return; }
46 
47  if (crewManager.IsSinglePlayer)
48  {
49  if (crewManager.ChatBox != null)
50  {
51  if (storeOriginalState)
52  {
53  chatBoxOriginalState = crewManager.ChatBox.ToggleOpen;
54  }
55  crewManager.ChatBox.ToggleOpen = value;
56  }
57  }
58  else if (GameMain.Client != null)
59  {
60  if (storeOriginalState)
61  {
62  chatBoxOriginalState = GameMain.Client.ChatBox.ToggleOpen;
63  }
64  GameMain.Client.ChatBox.ToggleOpen = value;
65  }
66  }
67 
68 #if DEBUG
69  public override void CreateEditingHUD(SerializableEntityEditor editor)
70  {
71  base.CreateEditingHUD(editor);
72 
73  foreach (LimbPos limbPos in limbPositions)
74  {
75  PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(limbPos);
76 
77  PropertyDescriptor limbPosProperty = properties.Find("Position", false);
78  editor.CreateVector2Field(limbPos, new SerializableProperty(limbPosProperty), limbPos.Position, limbPos.LimbType.ToString(), "");
79  }
80  }
81 #endif
82 
83  public void ClientEventRead(IReadMessage msg, float sendingTime)
84  {
85  State = msg.ReadBoolean();
86  ushort userID = msg.ReadUInt16();
87  if (userID == 0)
88  {
89  if (user != null)
90  {
91  IsActive = false;
92  CancelUsing(user);
93  user = null;
94  }
95  }
96  else
97  {
98  Character newUser = Entity.FindEntityByID(userID) as Character;
99  if (newUser != user)
100  {
101  CancelUsing(user);
102  }
103  user = newUser;
104  IsActive = true;
105  }
106  }
107  }
108 }
static Entity FindEntityByID(ushort ID)
Find an entity based on the ID
Definition: Entity.cs:204
static GameSession?? GameSession
Definition: GameMain.cs:88
override void DrawHUD(SpriteBatch spriteBatch, Character character)
The base class for components holding the different functionalities of the item
virtual void DrawHUD(SpriteBatch spriteBatch, Character character)