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:
juanjp600
2018-03-07 22:53:28 -03:00
parent 3bfca8c67d
commit 82dcbc3ae8
4 changed files with 84 additions and 29 deletions

View File

@@ -37,6 +37,26 @@ namespace Barotrauma.Items.Components
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)
{
Vector2 drawPos = new Vector2(item.Rect.X, item.Rect.Y);

View File

@@ -185,7 +185,14 @@ namespace Barotrauma.Items.Components
Entity focusTarget = GetFocusTarget();
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;
}
@@ -202,7 +209,24 @@ namespace Barotrauma.Items.Components
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;

View File

@@ -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. "+
"Disabling shadows increases the performance of the game, and is recommended for lights with a short range."), Serialize(true, true)]
public bool CastShadows
@@ -155,6 +157,12 @@ namespace Barotrauma.Items.Components
return;
}
}
else
{
#if CLIENT
light.Rotation = -Rotation;
#endif
}
if (powerConsumption == 0.0f)
{

View File

@@ -16,6 +16,9 @@ namespace Barotrauma.Items.Components
Vector2 barrelPos;
bool? hasLight;
LightComponent lightComponent;
float rotation, targetRotation;
float reload, reloadTime;
@@ -62,8 +65,8 @@ namespace Barotrauma.Items.Components
}
set
{
minRotation = MathHelper.ToRadians(value.X);
maxRotation = MathHelper.ToRadians(value.Y);
minRotation = MathHelper.ToRadians(Math.Min(value.X, value.Y));
maxRotation = MathHelper.ToRadians(Math.Max(value.X, value.Y));
rotation = (minRotation + maxRotation) / 2;
}
@@ -88,28 +91,30 @@ namespace Barotrauma.Items.Components
element.GetAttributeVector2("origin", Vector2.Zero));
}
#if CLIENT
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;
}
}
hasLight = null;
int barWidth = 200;
powerIndicator = new GUIProgressBar(new Rectangle(GameMain.GraphicsWidth / 2 - barWidth / 2, 20, barWidth, 30 ), Color.White, 0.0f);
#endif
InitProjSpecific(element);
}
partial void InitProjSpecific(XElement element);
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;
if (reload > 0.0f) reload -= deltaTime;
@@ -142,6 +147,11 @@ namespace Barotrauma.Items.Components
{
rotation = maxRotation;
}
if ((bool)hasLight)
{
lightComponent.Rotation = rotation;
}
}
public override bool Use(float deltaTime, Character character = null)
@@ -396,14 +406,7 @@ namespace Barotrauma.Items.Components
switch (connection.Name)
{
case "position_in":
Vector2 receivedPos = XMLExtensions.ParseVector2(signal, false);
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));
float.TryParse(signal, out targetRotation);
IsActive = true;