Light sources now follow the direction of parent Turrets + changed Controller's output signal and Turret's input signal to an angle
This commit is contained in:
@@ -37,6 +37,26 @@ namespace Barotrauma.Items.Components
|
|||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void InitProjSpecific(XElement element)
|
||||||
|
{
|
||||||
|
foreach (XElement subElement in element.Elements())
|
||||||
|
{
|
||||||
|
string texturePath = subElement.GetAttributeString("texture", "");
|
||||||
|
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||||
|
{
|
||||||
|
case "crosshair":
|
||||||
|
crosshairSprite = new Sprite(subElement, texturePath.Contains("/") ? "" : Path.GetDirectoryName(item.Prefab.ConfigFile));
|
||||||
|
break;
|
||||||
|
case "disabledcrosshair":
|
||||||
|
disabledCrossHairSprite = new Sprite(subElement, texturePath.Contains("/") ? "" : Path.GetDirectoryName(item.Prefab.ConfigFile));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int barWidth = 200;
|
||||||
|
powerIndicator = new GUIProgressBar(new Rectangle(GameMain.GraphicsWidth / 2 - barWidth / 2, 20, barWidth, 30), Color.White, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch, bool editing = false)
|
public void Draw(SpriteBatch spriteBatch, bool editing = false)
|
||||||
{
|
{
|
||||||
Vector2 drawPos = new Vector2(item.Rect.X, item.Rect.Y);
|
Vector2 drawPos = new Vector2(item.Rect.X, item.Rect.Y);
|
||||||
|
|||||||
@@ -185,7 +185,14 @@ namespace Barotrauma.Items.Components
|
|||||||
Entity focusTarget = GetFocusTarget();
|
Entity focusTarget = GetFocusTarget();
|
||||||
if (focusTarget == null)
|
if (focusTarget == null)
|
||||||
{
|
{
|
||||||
item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character);
|
Vector2 centerPos = new Vector2(item.WorldRect.Center.X, item.WorldRect.Center.Y);
|
||||||
|
|
||||||
|
Vector2 offset = character.CursorWorldPosition - centerPos;
|
||||||
|
offset.Y = -offset.Y;
|
||||||
|
|
||||||
|
float targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
|
||||||
|
|
||||||
|
item.SendSignal(0, targetRotation.ToString(), "position_out", character);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +209,24 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
if (!character.IsRemotePlayer || character.ViewTarget == focusTarget)
|
if (!character.IsRemotePlayer || character.ViewTarget == focusTarget)
|
||||||
{
|
{
|
||||||
item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character);
|
Vector2 centerPos = new Vector2(item.WorldRect.Center.X, item.WorldRect.Center.Y);
|
||||||
|
|
||||||
|
Item targetItem = focusTarget as Item;
|
||||||
|
if (targetItem != null)
|
||||||
|
{
|
||||||
|
Turret turret = targetItem.GetComponent<Turret>();
|
||||||
|
if (turret != null)
|
||||||
|
{
|
||||||
|
centerPos = new Vector2(targetItem.WorldRect.X + turret.BarrelPos.X, targetItem.WorldRect.Y - turret.BarrelPos.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 offset = character.CursorWorldPosition - centerPos;
|
||||||
|
offset.Y = -offset.Y;
|
||||||
|
|
||||||
|
float targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
|
||||||
|
|
||||||
|
item.SendSignal(0, targetRotation.ToString(), "position_out", character);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float Rotation;
|
||||||
|
|
||||||
[Editable(ToolTip = "Should structures cast shadows when light from this light source hits them. "+
|
[Editable(ToolTip = "Should structures cast shadows when light from this light source hits them. "+
|
||||||
"Disabling shadows increases the performance of the game, and is recommended for lights with a short range."), Serialize(true, true)]
|
"Disabling shadows increases the performance of the game, and is recommended for lights with a short range."), Serialize(true, true)]
|
||||||
public bool CastShadows
|
public bool CastShadows
|
||||||
@@ -155,6 +157,12 @@ namespace Barotrauma.Items.Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if CLIENT
|
||||||
|
light.Rotation = -Rotation;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (powerConsumption == 0.0f)
|
if (powerConsumption == 0.0f)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
Vector2 barrelPos;
|
Vector2 barrelPos;
|
||||||
|
|
||||||
|
bool? hasLight;
|
||||||
|
LightComponent lightComponent;
|
||||||
|
|
||||||
float rotation, targetRotation;
|
float rotation, targetRotation;
|
||||||
|
|
||||||
float reload, reloadTime;
|
float reload, reloadTime;
|
||||||
@@ -62,8 +65,8 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
minRotation = MathHelper.ToRadians(value.X);
|
minRotation = MathHelper.ToRadians(Math.Min(value.X, value.Y));
|
||||||
maxRotation = MathHelper.ToRadians(value.Y);
|
maxRotation = MathHelper.ToRadians(Math.Max(value.X, value.Y));
|
||||||
|
|
||||||
rotation = (minRotation + maxRotation) / 2;
|
rotation = (minRotation + maxRotation) / 2;
|
||||||
}
|
}
|
||||||
@@ -88,28 +91,30 @@ namespace Barotrauma.Items.Components
|
|||||||
element.GetAttributeVector2("origin", Vector2.Zero));
|
element.GetAttributeVector2("origin", Vector2.Zero));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CLIENT
|
hasLight = null;
|
||||||
foreach (XElement subElement in element.Elements())
|
|
||||||
{
|
|
||||||
string texturePath = subElement.GetAttributeString("texture", "");
|
|
||||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
|
||||||
{
|
|
||||||
case "crosshair":
|
|
||||||
crosshairSprite = new Sprite(subElement, texturePath.Contains("/") ? "" : Path.GetDirectoryName(item.Prefab.ConfigFile));
|
|
||||||
break;
|
|
||||||
case "disabledcrosshair":
|
|
||||||
disabledCrossHairSprite = new Sprite(subElement, texturePath.Contains("/") ? "" : Path.GetDirectoryName(item.Prefab.ConfigFile));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int barWidth = 200;
|
InitProjSpecific(element);
|
||||||
powerIndicator = new GUIProgressBar(new Rectangle(GameMain.GraphicsWidth / 2 - barWidth / 2, 20, barWidth, 30 ), Color.White, 0.0f);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void InitProjSpecific(XElement element);
|
||||||
|
|
||||||
public override void Update(float deltaTime, Camera cam)
|
public override void Update(float deltaTime, Camera cam)
|
||||||
{
|
{
|
||||||
|
if (hasLight == null)
|
||||||
|
{
|
||||||
|
List<LightComponent> lightComponents = item.GetComponents<LightComponent>();
|
||||||
|
|
||||||
|
if (lightComponents != null && lightComponents.Count>0)
|
||||||
|
{
|
||||||
|
lightComponent = lightComponents.Find(lc => lc.Parent == this);
|
||||||
|
hasLight = (lightComponent != null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hasLight = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.cam = cam;
|
this.cam = cam;
|
||||||
|
|
||||||
if (reload > 0.0f) reload -= deltaTime;
|
if (reload > 0.0f) reload -= deltaTime;
|
||||||
@@ -142,6 +147,11 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
rotation = maxRotation;
|
rotation = maxRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((bool)hasLight)
|
||||||
|
{
|
||||||
|
lightComponent.Rotation = rotation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Use(float deltaTime, Character character = null)
|
public override bool Use(float deltaTime, Character character = null)
|
||||||
@@ -396,14 +406,7 @@ namespace Barotrauma.Items.Components
|
|||||||
switch (connection.Name)
|
switch (connection.Name)
|
||||||
{
|
{
|
||||||
case "position_in":
|
case "position_in":
|
||||||
Vector2 receivedPos = XMLExtensions.ParseVector2(signal, false);
|
float.TryParse(signal, out targetRotation);
|
||||||
|
|
||||||
Vector2 centerPos = new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y);
|
|
||||||
|
|
||||||
Vector2 offset = receivedPos - centerPos;
|
|
||||||
offset.Y = -offset.Y;
|
|
||||||
|
|
||||||
targetRotation = MathUtils.WrapAngleTwoPi(MathUtils.VectorToAngle(offset));
|
|
||||||
|
|
||||||
IsActive = true;
|
IsActive = true;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user