From 51fe7df4815c324c459f4ee5d5bfde14517e3b7f Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 27 Nov 2017 19:34:57 +0200 Subject: [PATCH] Railgun HUD (shows supercapacitor charge & how many shells there are left) --- .../BarotraumaClient/BarotraumaClient.csproj | 1 + .../Items/Components/Machines/Controller.cs | 19 ++++ .../Source/Items/Components/Turret.cs | 84 ++++++++++++++++++ .../Source/Items/Inventory.cs | 2 +- .../BarotraumaShared.projitems | 6 ++ .../Content/Items/Weapons/crosshair.png | Bin 0 -> 6863 bytes .../Items/Weapons/disabledCrosshair.png | Bin 0 -> 1082 bytes .../Content/Items/Weapons/railgun.xml | 9 +- .../Items/Components/Machines/Controller.cs | 39 ++++---- .../Source/Items/Components/Turret.cs | 61 +++++++++++-- 10 files changed, 189 insertions(+), 32 deletions(-) create mode 100644 Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Controller.cs create mode 100644 Barotrauma/BarotraumaShared/Content/Items/Weapons/crosshair.png create mode 100644 Barotrauma/BarotraumaShared/Content/Items/Weapons/disabledCrosshair.png diff --git a/Barotrauma/BarotraumaClient/BarotraumaClient.csproj b/Barotrauma/BarotraumaClient/BarotraumaClient.csproj index 16b41b3b4..3503eb0a8 100644 --- a/Barotrauma/BarotraumaClient/BarotraumaClient.csproj +++ b/Barotrauma/BarotraumaClient/BarotraumaClient.csproj @@ -70,6 +70,7 @@ + diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Controller.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Controller.cs new file mode 100644 index 000000000..486559bb5 --- /dev/null +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Machines/Controller.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); + } + } + } + } +} diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Turret.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Turret.cs index 6c5fdab91..3af4b474c 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Turret.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Turret.cs @@ -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 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(); diff --git a/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs b/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs index 78a5ee727..8130dea44 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs @@ -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; diff --git a/Barotrauma/BarotraumaShared/BarotraumaShared.projitems b/Barotrauma/BarotraumaShared/BarotraumaShared.projitems index d3b1f729b..49dc19662 100644 --- a/Barotrauma/BarotraumaShared/BarotraumaShared.projitems +++ b/Barotrauma/BarotraumaShared/BarotraumaShared.projitems @@ -460,9 +460,15 @@ PreserveNewest + + PreserveNewest + PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/Barotrauma/BarotraumaShared/Content/Items/Weapons/crosshair.png b/Barotrauma/BarotraumaShared/Content/Items/Weapons/crosshair.png new file mode 100644 index 0000000000000000000000000000000000000000..e6986481e1fd3ff6acce2cd8b6ed141c67d4d4e0 GIT binary patch literal 6863 zcmcIpX*`rs)PH8ijD24RF^EKntR?FdWl2KT?8}fbma=DtFxjqU_dZN`dv^xZsRs_*1eYuY$P#X5VxT?L0=4CCY3 zd43`jMHUPESUjB|DLZAq#1P%1N{R0H40N;D@qjF2C<7{`NM*hdx<|H-IROMfDy@0@f3qKA6oXTBCfMMtLzrs4`pK9&@ zf5;0Q^jOO>$;61?n zb2mMDr;Ig6EEu|e|6~3VF3w70(eB?lYE&09sI)*R8LFJ|Bg(t!Q|#Psi0fI|a_AZR znH*pu-@)SGQJ@H$LBx&Eug`W4*>bM~ z@0RRBTLNRpwT1)REtY49s>C4d%HmF2rN@qgx}24L>@GM8e9Is_x-tw}X*TSf?jc;) z_2Zig5$1NRPH4}@b`~Fb=EFX)J>y~ z&7O7LJb3mPhq>mPV&-c68b37Op!z#I2Vei{rINS7ga`FMe(( zutvyzwz%vC7W74&W)k6ejCYb>Joh$7nYh6g3u-*M9_i)~zgEw+*K%uUGc%OhGX;#e zftztph$o4C28BZOra{ zzAkw(agyXx&v0^ljs)=wp{>uzygEJhk2?XL)J2pw+lri9X>ITKI!k4i)C+sWT%yV< zH%uyiA+sK>p2&^WUxJOXQ_86#29jon*d;%jZm%UVF(;>B^%QYXVGpT+ zPMp6Ud@VL^dpY5HeWGc z+`8!bS!U(#8tTUk5zAfKHX!BV zmtgqfx(4>w-6JkS6ko6}@A*Ou6E%o9flF4ht>jSY;k>O(eLYpe1i>e;rZF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BsSJOkirv`&xvb zxbilK_^S6txN<>{sp3$+U5nw|>kovxBd*igru@|R>{gu4iG|xAUz^6#jV5niDbRQP zb@Ukj=do{l5rigcU#*Q+>%fKvi#1GNXrgN~MjdivG@r1EeFejuMhjm*Mir?m1DCji z>N*QbmU@eYZZgM+iFnT5k1Av4zhHckBDCn$9oF9D<$_Co`AKm0o*KxN6Y(Z6JOo~F z_;)h#qxK?-5@WXTAn|txr*jcE4HnTpqTCggFiy_T`3#;$Hmzu|w@eWk*_pY{JZuom zD!FiGBdHJ;r7TwxkZ{YmxZ&H8J*9LwdfGm~Ep1n}gh>b#U@gAavuL+jg%k72sj@EQJ_KOKm2{4M?=9tDdy_{e;0+qPq8e~Cah7d%wvTh$+F8raWxpr#S zGj?u)fU32O>^}Pg6F}An=r_9?r$_ch?(|3yW^-dP1EHCa-+^C`ZuVGYE7$K7_tc21 zSRg*btWwVn)ClD*2UD3Nhdw|vf#w>?7&eUB7nyl`o+2++x5it-H#B4>S!mF3N|%ZE z9@hcjg4-krMl!MwucMa#av9!Uf(4bl4bIHvA01;YB+e3Dy@5eb0rd6xB0^i~v!C_l zB@XzACfWaeocdG!^Wg8;bMWUdZKlTWKQIM% z96$GH%GGyvYu}IAx-rS*WBnIp_KJgIO3s;kial42$_vYJ_yGSNaQKZMyL2+95A{u? zYALj7ZuF2KvV2%$$IoK-{2g1Z_GV75XxXL(~B9m&WbdS-+_9Zpr)0Z z$L_YL*G)L+H;wOq9rNBd|9G>>{XzQqo0Qazk&?=OQOv8cYd0stJG+1nl#G?ldrrIM zl+14=;-p~~Wc?(mYyXD^BQwiLfD`G1doI5)0le>KBHCv(Tc|KA|sB@z$5 z0UH*eC!K4%E+Ez0kK$kpgBz$02Yys#y$lVDLcR4Jl6Yivmh%R%xOBl1S!?7L{~syqoYDXQ literal 0 HcmV?d00001 diff --git a/Barotrauma/BarotraumaShared/Content/Items/Weapons/disabledCrosshair.png b/Barotrauma/BarotraumaShared/Content/Items/Weapons/disabledCrosshair.png new file mode 100644 index 0000000000000000000000000000000000000000..43d8093635f00a28ef4bcda585895246d9762ec4 GIT binary patch literal 1082 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%U;1OBOz`!jG!i)^F=12eq z6_P!Id>I(3R2di=ni&{={s+=87#M;$7#Kw(7#OUkGcbtfUyqWXz`($Kz|+Msq~g|_ zTfVFPvSkiDoZst_{=~&gWNyzCzGZ2rj`TD#s?`YGKinaCbc$8FlB?#KJw7Rq)}}bH zOIN=)E_iPfe=zEL=<0c))nDSz|5{sp_x!yL+qQ*WT`Jw56t*qw`6}(J=8tDg_g>By zzV*qoc1gB`JDSnB0RR(&6g+YM90pusDFsNq|+(mRTQY~?7lr%fjfipRh$K4js zSnum*U|k<_eD&O`@mFuY%Ke)E^=ic$h8gQ*uO59BTe`L?Dt5hHsQ4=TUJr&D?BDrub;~Y}_1gNs$6DVX zxcKqrS^Lel49^}`mu|MYe187#c|EW9ul}|BR(Pzbnl{6-*UqI&WlVP#O91`G1B#23(8@b!Iv;91IE!4GauS4Af#!&m_2u l=w{@H=wI>-4FCT#Gdwj3Ix_d01}6g$c)I$ztaD0e0svOp6@35z literal 0 HcmV?d00001 diff --git a/Barotrauma/BarotraumaShared/Content/Items/Weapons/railgun.xml b/Barotrauma/BarotraumaShared/Content/Items/Weapons/railgun.xml index 27abb571a..4480fe655 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Weapons/railgun.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Weapons/railgun.xml @@ -7,15 +7,20 @@ linkable="true" > - + + powerconsumption="20000.0" + showchargeindicator="true" + showprojectileindicator="true" + hudtint="0.4,0.6,0.7,0.05"> + + diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs index a1e0a2542..b75f1eb4b 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Controller.cs @@ -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 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); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs index ae486ed82..2c24e4926 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Turret.cs @@ -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(); + + 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 GetLoadedProjectiles(bool returnFirst = false) + private List GetLoadedProjectiles(bool returnFirst = false, bool returnNull = false) { List projectiles = new List(); @@ -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(); - if (projectileComponent != null) + var itemContainer = projectileContainer.GetComponent(); + for (int i = 0; i < itemContainer.Inventory.Items.Length; i++) { - projectiles.Add(projectileComponent); - if (returnFirst) return projectiles; + projectiles.Add(itemContainer.Inventory.Items[i]?.GetComponent()); + } + } + else + { + var containedItems = projectileContainer.ContainedItems; + if (containedItems == null) continue; + + for (int i = 0; i < containedItems.Length; i++) + { + var projectileComponent = containedItems[i].GetComponent(); + if (projectileComponent != null) + { + projectiles.Add(projectileComponent); + if (returnFirst) return projectiles; + } } } }