Railgun HUD (shows supercapacitor charge & how many shells there are left)
This commit is contained in:
@@ -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.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user