Controllers don't have to be wired directly to an item for camera focus to work (= railguns and cameras can be used over wifi). Closes #535

This commit is contained in:
Joonas Rikkonen
2018-07-31 15:03:20 +03:00
parent d81ee1a27e
commit 82103cf394
5 changed files with 42 additions and 21 deletions

View File

@@ -6,9 +6,7 @@ namespace Barotrauma.Items.Components
{
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{
var focusTarget = GetFocusTarget();
if (focusTarget == null) return;
if (character.ViewTarget == focusTarget)
if (focusTarget != null && character.ViewTarget == focusTarget)
{
foreach (ItemComponent ic in focusTarget.components)
{

View File

@@ -33,6 +33,9 @@ namespace Barotrauma.Items.Components
private Character character;
private Item focusTarget;
private float targetRotation;
public Vector2 UserPos
{
get { return userPos; }
@@ -174,7 +177,7 @@ namespace Barotrauma.Items.Components
return true;
}
public override bool SecondaryUse(float deltaTime, Character character = null)
{
if (this.character != character)
@@ -190,7 +193,7 @@ namespace Barotrauma.Items.Components
}
if (character == null) return false;
Entity focusTarget = GetFocusTarget();
focusTarget = GetFocusTarget();
if (focusTarget == null)
{
Vector2 centerPos = new Vector2(item.WorldRect.Center.X, item.WorldRect.Center.Y);
@@ -198,9 +201,7 @@ namespace Barotrauma.Items.Components
Vector2 offset = character.CursorWorldPosition - centerPos;
offset.Y = -offset.Y;
float targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
item.SendSignal(0, targetRotation.ToString(), "position_out", character);
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
return false;
}
@@ -211,7 +212,7 @@ namespace Barotrauma.Items.Components
Lights.LightManager.ViewTarget = focusTarget;
cam.TargetPos = focusTarget.WorldPosition;
cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, (focusTarget as Item).Prefab.OffsetOnSelected, deltaTime*10.0f);
cam.OffsetAmount = MathHelper.Lerp(cam.OffsetAmount, (focusTarget as Item).Prefab.OffsetOnSelected, deltaTime * 10.0f);
}
#endif
@@ -232,9 +233,7 @@ namespace Barotrauma.Items.Components
Vector2 offset = character.CursorWorldPosition - centerPos;
offset.Y = -offset.Y;
float targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
item.SendSignal(0, targetRotation.ToString(), "position_out", character);
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
}
return true;
@@ -242,17 +241,16 @@ namespace Barotrauma.Items.Components
private Item GetFocusTarget()
{
foreach (Connection c in item.Connections)
{
if (c.Name != "position_out") continue;
item.SendSignal(0, targetRotation.ToString(), "position_out", character);
foreach (Connection c2 in c.Recipients)
for (int i = item.LastSentSignalRecipients.Count - 1; i >= 0; i--)
{
if (item.LastSentSignalRecipients[i].Prefab.FocusOnSelected)
{
if (c2 == null || c2.Item == null || !c2.Item.Prefab.FocusOnSelected) continue;
return c2.Item;
return item.LastSentSignalRecipients[i];
}
}
return null;
}

View File

@@ -160,6 +160,11 @@ namespace Barotrauma.Items.Components
if (recipient == null) continue;
if (recipient.item == this.item || recipient.item == source) continue;
if (source != null && !source.LastSentSignalRecipients.Contains(recipient.item))
{
source.LastSentSignalRecipients.Add(recipient.item);
}
foreach (ItemComponent ic in recipient.item.components)
{
ic.ReceiveSignal(stepsTaken, signal, recipient, item, sender, power);

View File

@@ -95,6 +95,16 @@ namespace Barotrauma.Items.Components
foreach (WifiComponent wifiComp in receivers)
{
wifiComp.item.SendSignal(stepsTaken, signal, "signal_out", sender);
if (source != null)
{
foreach (Item receiverItem in wifiComp.item.LastSentSignalRecipients)
{
if (!source.LastSentSignalRecipients.Contains(receiverItem))
{
source.LastSentSignalRecipients.Add(receiverItem);
}
}
}
}
break;
}

View File

@@ -268,7 +268,16 @@ namespace Barotrauma
return IsInWater();
}
}
/// <summary>
/// A list of items the last signal sent by this item went through
/// </summary>
public List<Item> LastSentSignalRecipients
{
get;
private set;
} = new List<Item>();
public ItemPrefab Prefab
{
get { return prefab; }
@@ -1011,9 +1020,10 @@ namespace Barotrauma
}
}
}
public void SendSignal(int stepsTaken, string signal, string connectionName, Character sender, float power = 0.0f)
{
LastSentSignalRecipients.Clear();
if (connections == null) return;
stepsTaken++;