Hud refactor (#7202)

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
Co-authored-by: Jezithyr <jmaster9999@gmail.com>
Co-authored-by: Jezithyr <Jezithyr@gmail.com>
Co-authored-by: Visne <39844191+Visne@users.noreply.github.com>
Co-authored-by: wrexbe <wrexbe@protonmail.com>
Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com>
This commit is contained in:
Jezithyr
2022-10-12 01:16:23 -07:00
committed by GitHub
parent d09fbc1849
commit 571dd4e6d5
168 changed files with 6940 additions and 7817 deletions

View File

@@ -0,0 +1,83 @@
using System.Linq;
using Content.Client.UserInterface.Systems.Inventory.Controls;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.UserInterface.Systems.Hands.Controls;
public sealed class HandsContainer : ItemSlotUIContainer<HandButton>
{
private readonly GridContainer _grid;
public int ColumnLimit { get => _grid.Columns; set => _grid.Columns = value; }
public int MaxButtonCount { get; set; } = 0;
public HandsContainer()
{
AddChild(_grid = new GridContainer());
_grid.ExpandBackwards = true;
}
public override HandButton? AddButton(HandButton newButton)
{
if (MaxButtonCount > 0)
{
if (ButtonCount >= MaxButtonCount)
return null;
_grid.AddChild(newButton);
}
else
{
_grid.AddChild(newButton);
}
return base.AddButton(newButton);
}
public override void RemoveButton(string handName)
{
var button = GetButton(handName);
if (button == null)
return;
base.RemoveButton(button);
_grid.RemoveChild(button);
}
public bool TryGetLastButton(out HandButton? control)
{
if (Buttons.Count == 0)
{
control = null;
return false;
}
control = Buttons.Values.Last();
return true;
}
public bool TryRemoveLastHand(out HandButton? control)
{
var success = TryGetLastButton(out control);
if (control != null)
RemoveButton(control);
return success;
}
public void Clear()
{
ClearButtons();
_grid.DisposeAllChildren();
}
public IEnumerable<HandButton> GetButtons()
{
foreach (var child in _grid.Children)
{
if (child is HandButton hand)
yield return hand;
}
}
public bool IsFull => (MaxButtonCount != 0 && ButtonCount >= MaxButtonCount);
public int ButtonCount => _grid.ChildCount;
}