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
@@ -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;
}