Railgun HUD (shows supercapacitor charge & how many shells there are left)

This commit is contained in:
Joonas Rikkonen
2017-11-27 19:34:57 +02:00
parent f4f58622e1
commit 51fe7df481
10 changed files with 189 additions and 32 deletions
@@ -460,9 +460,15 @@
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Tools\tools.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\crosshair.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\depthcharge.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\disabledCrosshair.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(MSBuildThisFileDirectory)Content\Items\Weapons\explosives.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</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"
>
<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"
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">
<sound file="Content/Items/Weapons/railgun.ogg" range="5000"/>
<Explosion range="1000.0" structuredamage="0" force="0.01" camerashake="10.0"/>
</StatusEffect>
<Crosshair texture="crosshair.png"/>
<DisabledCrosshair texture="disabledCrosshair.png"/>
</Turret>
<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
private List<LimbPos> limbPositions;
@@ -167,26 +167,9 @@ namespace Barotrauma.Items.Components
character = null;
return;
}
if (character == null) return;
Entity focusTarget = null;
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;
}
}
Entity focusTarget = GetFocusTarget();
if (focusTarget == null)
{
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)
{
item.SendSignal(0, "1", "signal_out", picker);
@@ -87,6 +87,25 @@ namespace Barotrauma.Items.Components
barrelSpritePath,
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)
@@ -296,6 +315,19 @@ namespace Barotrauma.Items.Components
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()
{
base.RemoveComponentSpecific();
@@ -303,7 +335,7 @@ namespace Barotrauma.Items.Components
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>();
@@ -312,16 +344,27 @@ namespace Barotrauma.Items.Components
var projectileContainer = e as Item;
if (projectileContainer == null) continue;
var containedItems = projectileContainer.ContainedItems;
if (containedItems == null) continue;
for (int i = 0; i < containedItems.Length; i++)
if (returnNull)
{
var projectileComponent = containedItems[i].GetComponent<Projectile>();
if (projectileComponent != null)
var itemContainer = projectileContainer.GetComponent<ItemContainer>();
for (int i = 0; i < itemContainer.Inventory.Items.Length; i++)
{
projectiles.Add(projectileComponent);
if (returnFirst) return projectiles;
projectiles.Add(itemContainer.Inventory.Items[i]?.GetComponent<Projectile>());
}
}
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;
}
}
}
}