(79cd545fb) Switched send out a continuous 0/1 signal that can be flipped by interacting with the switch (as opposed to working like buttons which send out a pulse when interacted with). Closes #1657

This commit is contained in:
Joonas Rikkonen
2019-06-16 18:07:18 +03:00
parent e1e92c1c3b
commit c02da46ef5
2 changed files with 26 additions and 14 deletions
@@ -1900,15 +1900,6 @@ namespace Barotrauma.Networking
chatBox.AddMessage(message); chatBox.AddMessage(message);
} }
public override void AddChatMessage(ChatMessage message)
{
base.AddChatMessage(message);
if (string.IsNullOrEmpty(message.Text)) { return; }
GameMain.NetLobbyScreen.NewChatMessage(message);
chatBox.AddMessage(message);
}
public override void KickPlayer(string kickedName, string reason) public override void KickPlayer(string kickedName, string reason)
{ {
NetOutgoingMessage msg = client.CreateMessage(); NetOutgoingMessage msg = client.CreateMessage();
@@ -37,6 +37,8 @@ namespace Barotrauma.Items.Components
private Item focusTarget; private Item focusTarget;
private float targetRotation; private float targetRotation;
private bool state;
public Vector2 UserPos public Vector2 UserPos
{ {
get { return userPos; } get { return userPos; }
@@ -48,6 +50,13 @@ namespace Barotrauma.Items.Components
get { return user; } get { return user; }
} }
[Serialize(false, false), Editable(ToolTip = "When enabled, the item will continuously send out a 0/1 signal and interacting with it will flip the signal (making the item behave like a switch). When disabled, the item will simply send out 1 when interacted with.")]
public bool IsToggle
{
get;
set;
}
public Controller(Item item, XElement element) public Controller(Item item, XElement element)
: base(item, element) : base(item, element)
{ {
@@ -55,7 +64,7 @@ namespace Barotrauma.Items.Components
userPos = element.GetAttributeVector2("UserPos", Vector2.Zero); userPos = element.GetAttributeVector2("UserPos", Vector2.Zero);
Enum.TryParse<Direction>(element.GetAttributeString("direction", "None"), out dir); Enum.TryParse(element.GetAttributeString("direction", "None"), out dir);
foreach (XElement el in element.Elements()) foreach (XElement el in element.Elements())
{ {
@@ -83,7 +92,12 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam) public override void Update(float deltaTime, Camera cam)
{ {
this.cam = cam; this.cam = cam;
if (IsToggle)
{
item.SendSignal(0, state ? "1" : "0", "signal_out", sender: null);
}
if (user == null if (user == null
|| user.Removed || user.Removed
|| user.SelectedConstruction != item || user.SelectedConstruction != item
@@ -94,7 +108,7 @@ namespace Barotrauma.Items.Components
CancelUsing(user); CancelUsing(user);
user = null; user = null;
} }
IsActive = false; if (!IsToggle) { IsActive = false; }
return; return;
} }
@@ -169,7 +183,7 @@ namespace Barotrauma.Items.Components
} }
item.SendSignal(0, "1", "trigger_out", user); item.SendSignal(0, "1", "trigger_out", user);
ApplyStatusEffects(ActionType.OnUse, 1.0f, activator); ApplyStatusEffects(ActionType.OnUse, 1.0f, activator);
return true; return true;
@@ -254,7 +268,14 @@ namespace Barotrauma.Items.Components
public override bool Pick(Character picker) public override bool Pick(Character picker)
{ {
item.SendSignal(0, "1", "signal_out", picker); if (IsToggle)
{
state = !state;
}
else
{
item.SendSignal(0, "1", "signal_out", picker);
}
#if CLIENT #if CLIENT
PlaySound(ActionType.OnUse, item.WorldPosition, picker); PlaySound(ActionType.OnUse, item.WorldPosition, picker);