diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index 483457cf21..935db4b5ad 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -247,7 +247,6 @@ namespace Content.Client IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); - IoCManager.Resolve().Initialize(); _baseClient.RunLevelChanged += (sender, args) => { diff --git a/Content.Client/UserInterface/CooldownGraphic.cs b/Content.Client/UserInterface/CooldownGraphic.cs new file mode 100644 index 0000000000..49977492d0 --- /dev/null +++ b/Content.Client/UserInterface/CooldownGraphic.cs @@ -0,0 +1,33 @@ +using Robust.Client.Graphics.Drawing; +using Robust.Client.Interfaces.GameObjects.Components; +using Robust.Client.Interfaces.Graphics; +using Robust.Shared.Maths; +using System; + +namespace Robust.Client.UserInterface.Controls +{ + public class CooldownGraphic : Control + { + public float Fraction { get; set; } + + protected override void Draw(DrawingHandleScreen handle) + { + const int maxSegments = 64; + const float segment = MathHelper.TwoPi / maxSegments; + + var segments = (int)Math.Max(2, Math.Ceiling(maxSegments * Fraction)); // ensure that we always have 3 vertices + var max = MathHelper.TwoPi * Fraction; + var radius = (Math.Min(SizeBox.Height, SizeBox.Width) / 2) * 0.875f; // 28/32 = 0.875 - 2 pixels inwards from the edge + + Span vertices = stackalloc Vector2[segments + 1]; + vertices[0] = PixelPosition + SizeBox.Center; + for (int i = 0; i < segments; i++) + { + var angle = MathHelper.Pi + Math.Min(max, segment * i); + vertices[i + 1] = vertices[0] + new Vector2((float) Math.Sin(angle) * radius, (float) Math.Cos(angle) * radius); + } + + handle.DrawPrimitives(DrawPrimitiveTopology.TriangleFan, vertices, new Color(0.3f, 0.3f, 0.4f, 0.5f)); + } + } +} diff --git a/Content.Client/UserInterface/IItemSlotManager.cs b/Content.Client/UserInterface/IItemSlotManager.cs index f8493d5c23..5e1d09365d 100644 --- a/Content.Client/UserInterface/IItemSlotManager.cs +++ b/Content.Client/UserInterface/IItemSlotManager.cs @@ -6,7 +6,6 @@ namespace Content.Client.UserInterface { public interface IItemSlotManager { - void Initialize(); bool OnButtonPressed(GUIBoundKeyEventArgs args, IEntity item); void UpdateCooldown(ItemSlotButton cooldownTexture, IEntity entity); bool SetItemSlot(ItemSlotButton button, IEntity entity); diff --git a/Content.Client/UserInterface/ItemSlotButton.cs b/Content.Client/UserInterface/ItemSlotButton.cs index 54bc4c027c..97f88efaae 100644 --- a/Content.Client/UserInterface/ItemSlotButton.cs +++ b/Content.Client/UserInterface/ItemSlotButton.cs @@ -1,4 +1,5 @@ using System; +using Content.Client.UserInterface; using Content.Shared.Input; using Robust.Client.Graphics; using Robust.Client.UserInterface; @@ -13,7 +14,7 @@ namespace Content.Client.GameObjects public TextureRect Button { get; } public SpriteView SpriteView { get; } public BaseButton StorageButton { get; } - public TextureRect CooldownCircle { get; } + public CooldownGraphic CooldownDisplay { get; } public Action OnPressed { get; set; } public Action OnStoragePressed { get; set; } @@ -56,12 +57,10 @@ namespace Content.Client.GameObjects StorageButton.OnPressed += OnStorageButtonPressed; - AddChild(CooldownCircle = new TextureRect + AddChild(CooldownDisplay = new CooldownGraphic { - SizeFlagsHorizontal = SizeFlags.ShrinkCenter, - SizeFlagsVertical = SizeFlags.ShrinkCenter, - Stretch = TextureRect.StretchMode.KeepCentered, - TextureScale = (2, 2), + SizeFlagsHorizontal = SizeFlags.Fill, + SizeFlagsVertical = SizeFlags.Fill, Visible = false, }); } diff --git a/Content.Client/UserInterface/ItemSlotManager.cs b/Content.Client/UserInterface/ItemSlotManager.cs index 5c07cd5f57..a1daa70ebe 100644 --- a/Content.Client/UserInterface/ItemSlotManager.cs +++ b/Content.Client/UserInterface/ItemSlotManager.cs @@ -30,22 +30,8 @@ namespace Content.Client.UserInterface [Dependency] private readonly IInputManager _inputManager; [Dependency] private readonly IEntitySystemManager _entitySystemManager; [Dependency] private readonly IEyeManager _eyeManager; - [Dependency] private readonly IResourceCache _resourceCache; #pragma warning restore 0649 - private const int CooldownLevels = 8; - - private readonly Texture[] _texturesCooldownOverlay = new Texture[CooldownLevels]; - - public void Initialize() - { - for (var i = 0; i < CooldownLevels; i++) - { - _texturesCooldownOverlay[i] = - _resourceCache.GetTexture($"/Textures/UserInterface/Inventory/cooldown-{i}.png"); - } - } - public bool SetItemSlot(ItemSlotButton button, IEntity entity) { if (entity == null) @@ -103,7 +89,7 @@ namespace Content.Client.UserInterface public void UpdateCooldown(ItemSlotButton button, IEntity entity) { - var cooldownTexture = button.CooldownCircle; + var cooldownDisplay = button.CooldownDisplay; if (entity != null && entity.TryGetComponent(out ItemCooldownComponent cooldown) @@ -115,30 +101,23 @@ namespace Content.Client.UserInterface var length = (end - start).TotalSeconds; var progress = (_gameTiming.CurTime - start).TotalSeconds; - var ratio = (float)(progress / length); + var ratio = 1 - (float)(progress / length).Clamp(0, 1); - var textureIndex = CalculateCooldownLevel(ratio); - if (textureIndex == CooldownLevels) + cooldownDisplay.Fraction = ratio; + + if (ratio > 0) { - cooldownTexture.Visible = false; + cooldownDisplay.Visible = true; } else { - cooldownTexture.Visible = true; - cooldownTexture.Texture = _texturesCooldownOverlay[textureIndex]; + cooldownDisplay.Visible = false; } } else { - cooldownTexture.Visible = false; + cooldownDisplay.Visible = false; } } - - internal static int CalculateCooldownLevel(float cooldownValue) - { - var val = cooldownValue.Clamp(0, 1); - val *= CooldownLevels; - return (int)Math.Floor(val); - } } } diff --git a/Content.Tests/Client/UserInterface/ItemSlotTest.cs b/Content.Tests/Client/UserInterface/ItemSlotTest.cs deleted file mode 100644 index 1c66549b82..0000000000 --- a/Content.Tests/Client/UserInterface/ItemSlotTest.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Content.Client.UserInterface; -using NUnit.Framework; - -namespace Content.Tests.Client.UserInterface -{ - [TestFixture] - public class ItemSlotTest - { - [Test] - public void TestCalculateCooldownLevel() - { - Assert.AreEqual(ItemSlotManager.CalculateCooldownLevel(0.5f), 4); - Assert.AreEqual(ItemSlotManager.CalculateCooldownLevel(1), 8); - Assert.AreEqual(ItemSlotManager.CalculateCooldownLevel(0), 0); - } - } -}