Railgun HUD (shows supercapacitor charge & how many shells there are left)
This commit is contained in:
@@ -70,6 +70,7 @@
|
|||||||
<Compile Include="Source\Characters\AI\HumanAIController.cs" />
|
<Compile Include="Source\Characters\AI\HumanAIController.cs" />
|
||||||
<Compile Include="Source\Characters\Animation\Ragdoll.cs" />
|
<Compile Include="Source\Characters\Animation\Ragdoll.cs" />
|
||||||
<Compile Include="Source\Characters\Attack.cs" />
|
<Compile Include="Source\Characters\Attack.cs" />
|
||||||
|
<Compile Include="Source\Items\Components\Machines\Controller.cs" />
|
||||||
<Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreature.cs" />
|
<Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreature.cs" />
|
||||||
<Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreatureManager.cs" />
|
<Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreatureManager.cs" />
|
||||||
<Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreaturePrefab.cs" />
|
<Compile Include="Source\Map\Levels\BackgroundSprite\BackgroundCreaturePrefab.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
|
namespace Barotrauma.Items.Components
|
||||||
|
{
|
||||||
|
partial class Controller : ItemComponent
|
||||||
|
{
|
||||||
|
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||||
|
{
|
||||||
|
var focusTarget = GetFocusTarget();
|
||||||
|
if (character.ViewTarget == focusTarget)
|
||||||
|
{
|
||||||
|
foreach (ItemComponent ic in focusTarget.components)
|
||||||
|
{
|
||||||
|
ic.DrawHUD(spriteBatch, character);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,40 @@ using Lidgren.Network;
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace Barotrauma.Items.Components
|
namespace Barotrauma.Items.Components
|
||||||
{
|
{
|
||||||
partial class Turret : Powered, IDrawableComponent, IServerSerializable
|
partial class Turret : Powered, IDrawableComponent, IServerSerializable
|
||||||
{
|
{
|
||||||
|
private Sprite crosshairSprite, disabledCrossHairSprite;
|
||||||
|
|
||||||
|
private GUIProgressBar powerIndicator;
|
||||||
|
|
||||||
|
[Editable, Serialize("0.0,0.0,0.0,0.0", true)]
|
||||||
|
public Color HudTint
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serialize(false, false)]
|
||||||
|
public bool ShowChargeIndicator
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serialize(false, false)]
|
||||||
|
public bool ShowProjectileIndicator
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -41,6 +70,61 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||||
|
{
|
||||||
|
if (HudTint.A > 0)
|
||||||
|
{
|
||||||
|
GUI.DrawRectangle(spriteBatch, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
|
||||||
|
new Color(HudTint.R, HudTint.G, HudTint.B) * (HudTint.A/255.0f), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
float batteryCharge;
|
||||||
|
float batteryCapacity;
|
||||||
|
GetAvailablePower(out batteryCharge, out batteryCapacity);
|
||||||
|
|
||||||
|
List<Projectile> projectiles = GetLoadedProjectiles(false, true);
|
||||||
|
|
||||||
|
float chargeRate = powerConsumption <= 0.0f ? 1.0f : batteryCharge / batteryCapacity;
|
||||||
|
bool charged = batteryCharge * 3600.0f > powerConsumption;
|
||||||
|
bool readyToFire = reload <= 0.0f && charged && projectiles.Any(p => p != null);
|
||||||
|
|
||||||
|
if (ShowChargeIndicator && PowerConsumption > 0.0f)
|
||||||
|
{
|
||||||
|
powerIndicator.BarSize = chargeRate;
|
||||||
|
powerIndicator.Color = charged ? Color.Green : Color.Red;
|
||||||
|
powerIndicator.Draw(spriteBatch);
|
||||||
|
|
||||||
|
int requiredChargeIndicatorPos = (int)((powerConsumption / (batteryCapacity * 3600.0f)) * powerIndicator.Rect.Width);
|
||||||
|
GUI.DrawRectangle(spriteBatch,
|
||||||
|
new Rectangle(powerIndicator.Rect.X + requiredChargeIndicatorPos, powerIndicator.Rect.Y, 3, powerIndicator.Rect.Height),
|
||||||
|
Color.White * 0.5f, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ShowProjectileIndicator)
|
||||||
|
{
|
||||||
|
Point slotSize = new Point(60, 30);
|
||||||
|
int spacing = 5;
|
||||||
|
int slotsPerRow = Math.Min(projectiles.Count, 6);
|
||||||
|
int totalWidth = slotSize.X * slotsPerRow + spacing * (slotsPerRow - 1);
|
||||||
|
Point invSlotPos = new Point(GameMain.GraphicsWidth / 2 - totalWidth / 2, 60);
|
||||||
|
for (int i = 0; i < projectiles.Count; i++)
|
||||||
|
{
|
||||||
|
Inventory.DrawSlot(spriteBatch,
|
||||||
|
new InventorySlot(new Rectangle(invSlotPos + new Point((i % slotsPerRow) * (slotSize.X + spacing), (int)Math.Floor(i / (float)slotsPerRow) * (slotSize.Y + spacing)), slotSize)),
|
||||||
|
projectiles[i] == null ? null : projectiles[i].Item, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (readyToFire)
|
||||||
|
{
|
||||||
|
if (crosshairSprite != null) crosshairSprite.Draw(spriteBatch, PlayerInput.MousePosition);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (disabledCrossHairSprite != null) disabledCrossHairSprite.Draw(spriteBatch, PlayerInput.MousePosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
|
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
|
||||||
{
|
{
|
||||||
UInt16 projectileID = msg.ReadUInt16();
|
UInt16 projectileID = msg.ReadUInt16();
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DrawSlot(SpriteBatch spriteBatch, InventorySlot slot, Item item, bool drawItem = true)
|
public static void DrawSlot(SpriteBatch spriteBatch, InventorySlot slot, Item item, bool drawItem = true)
|
||||||
{
|
{
|
||||||
Rectangle rect = slot.Rect;
|
Rectangle rect = slot.Rect;
|
||||||
|
|
||||||
|
|||||||
@@ -460,9 +460,15 @@
|
|||||||
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Tools\tools.xml">
|
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Tools\tools.xml">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\crosshair.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\depthcharge.xml">
|
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\depthcharge.xml">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\disabledCrosshair.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\explosives.xml">
|
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\explosives.xml">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -7,15 +7,20 @@
|
|||||||
linkable="true"
|
linkable="true"
|
||||||
>
|
>
|
||||||
|
|
||||||
<Sprite texture ="railgunbase.png" depth = "0.01"/>
|
<Sprite texture="railgunbase.png" depth = "0.01"/>
|
||||||
|
|
||||||
<Turret barrelsprite="railgunbarrel.png" canbeselected = "true" linkable="true" origin="0.5, 0.85" barrelpos="128, 128"
|
<Turret barrelsprite="railgunbarrel.png" canbeselected = "true" linkable="true" origin="0.5, 0.85" barrelpos="128, 128"
|
||||||
rotationlimits="180,360"
|
rotationlimits="180,360"
|
||||||
powerconsumption="20000.0">
|
powerconsumption="20000.0"
|
||||||
|
showchargeindicator="true"
|
||||||
|
showprojectileindicator="true"
|
||||||
|
hudtint="0.4,0.6,0.7,0.05">
|
||||||
<StatusEffect type="OnUse" target="This">
|
<StatusEffect type="OnUse" target="This">
|
||||||
<sound file="Content/Items/Weapons/railgun.ogg" range="5000"/>
|
<sound file="Content/Items/Weapons/railgun.ogg" range="5000"/>
|
||||||
<Explosion range="1000.0" structuredamage="0" force="0.01" camerashake="10.0"/>
|
<Explosion range="1000.0" structuredamage="0" force="0.01" camerashake="10.0"/>
|
||||||
</StatusEffect>
|
</StatusEffect>
|
||||||
|
<Crosshair texture="crosshair.png"/>
|
||||||
|
<DisabledCrosshair texture="disabledCrosshair.png"/>
|
||||||
</Turret>
|
</Turret>
|
||||||
|
|
||||||
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
|
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Controller : ItemComponent
|
partial class Controller : ItemComponent
|
||||||
{
|
{
|
||||||
//where the limbs of the user should be positioned when using the controller
|
//where the limbs of the user should be positioned when using the controller
|
||||||
private List<LimbPos> limbPositions;
|
private List<LimbPos> limbPositions;
|
||||||
@@ -167,26 +167,9 @@ namespace Barotrauma.Items.Components
|
|||||||
character = null;
|
character = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (character == null) return;
|
||||||
|
|
||||||
Entity focusTarget = null;
|
Entity focusTarget = GetFocusTarget();
|
||||||
|
|
||||||
if (character == null) return;
|
|
||||||
|
|
||||||
|
|
||||||
foreach (Connection c in item.Connections)
|
|
||||||
{
|
|
||||||
if (c.Name != "position_out") continue;
|
|
||||||
|
|
||||||
foreach (Connection c2 in c.Recipients)
|
|
||||||
{
|
|
||||||
if (c2 == null || c2.Item == null || !c2.Item.Prefab.FocusOnSelected) continue;
|
|
||||||
|
|
||||||
focusTarget = c2.Item;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (focusTarget == null)
|
if (focusTarget == null)
|
||||||
{
|
{
|
||||||
item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character);
|
item.SendSignal(0, XMLExtensions.Vector2ToString(character.CursorWorldPosition), "position_out", character);
|
||||||
@@ -210,6 +193,22 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Item GetFocusTarget()
|
||||||
|
{
|
||||||
|
foreach (Connection c in item.Connections)
|
||||||
|
{
|
||||||
|
if (c.Name != "position_out") continue;
|
||||||
|
|
||||||
|
foreach (Connection c2 in c.Recipients)
|
||||||
|
{
|
||||||
|
if (c2 == null || c2.Item == null || !c2.Item.Prefab.FocusOnSelected) continue;
|
||||||
|
return c2.Item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Pick(Character picker)
|
public override bool Pick(Character picker)
|
||||||
{
|
{
|
||||||
item.SendSignal(0, "1", "signal_out", picker);
|
item.SendSignal(0, "1", "signal_out", picker);
|
||||||
|
|||||||
@@ -87,6 +87,25 @@ namespace Barotrauma.Items.Components
|
|||||||
barrelSpritePath,
|
barrelSpritePath,
|
||||||
element.GetAttributeVector2("origin", Vector2.Zero));
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int barWidth = 200;
|
||||||
|
powerIndicator = new GUIProgressBar(new Rectangle(GameMain.GraphicsWidth / 2 - barWidth / 2, 20, barWidth, 30 ), Color.White, 0.0f);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float deltaTime, Camera cam)
|
public override void Update(float deltaTime, Camera cam)
|
||||||
@@ -296,6 +315,19 @@ namespace Barotrauma.Items.Components
|
|||||||
return availablePower;
|
return availablePower;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GetAvailablePower(out float availableCharge, out float availableCapacity)
|
||||||
|
{
|
||||||
|
var batteries = item.GetConnectedComponents<PowerContainer>();
|
||||||
|
|
||||||
|
availableCharge = 0.0f;
|
||||||
|
availableCapacity = 0.0f;
|
||||||
|
foreach (PowerContainer battery in batteries)
|
||||||
|
{
|
||||||
|
availableCharge += battery.Charge;
|
||||||
|
availableCapacity += battery.Capacity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void RemoveComponentSpecific()
|
protected override void RemoveComponentSpecific()
|
||||||
{
|
{
|
||||||
base.RemoveComponentSpecific();
|
base.RemoveComponentSpecific();
|
||||||
@@ -303,7 +335,7 @@ namespace Barotrauma.Items.Components
|
|||||||
if (barrelSprite != null) barrelSprite.Remove();
|
if (barrelSprite != null) barrelSprite.Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Projectile> GetLoadedProjectiles(bool returnFirst = false)
|
private List<Projectile> GetLoadedProjectiles(bool returnFirst = false, bool returnNull = false)
|
||||||
{
|
{
|
||||||
List<Projectile> projectiles = new List<Projectile>();
|
List<Projectile> projectiles = new List<Projectile>();
|
||||||
|
|
||||||
@@ -312,16 +344,27 @@ namespace Barotrauma.Items.Components
|
|||||||
var projectileContainer = e as Item;
|
var projectileContainer = e as Item;
|
||||||
if (projectileContainer == null) continue;
|
if (projectileContainer == null) continue;
|
||||||
|
|
||||||
var containedItems = projectileContainer.ContainedItems;
|
if (returnNull)
|
||||||
if (containedItems == null) continue;
|
|
||||||
|
|
||||||
for (int i = 0; i < containedItems.Length; i++)
|
|
||||||
{
|
{
|
||||||
var projectileComponent = containedItems[i].GetComponent<Projectile>();
|
var itemContainer = projectileContainer.GetComponent<ItemContainer>();
|
||||||
if (projectileComponent != null)
|
for (int i = 0; i < itemContainer.Inventory.Items.Length; i++)
|
||||||
{
|
{
|
||||||
projectiles.Add(projectileComponent);
|
projectiles.Add(itemContainer.Inventory.Items[i]?.GetComponent<Projectile>());
|
||||||
if (returnFirst) return projectiles;
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var containedItems = projectileContainer.ContainedItems;
|
||||||
|
if (containedItems == null) continue;
|
||||||
|
|
||||||
|
for (int i = 0; i < containedItems.Length; i++)
|
||||||
|
{
|
||||||
|
var projectileComponent = containedItems[i].GetComponent<Projectile>();
|
||||||
|
if (projectileComponent != null)
|
||||||
|
{
|
||||||
|
projectiles.Add(projectileComponent);
|
||||||
|
if (returnFirst) return projectiles;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user