Corner Clothing UI (#22883)
* Corner clothing (save point) * IT WORKS. YIPPEE * the last of it * template rejigs
This commit is contained in:
@@ -16,6 +16,14 @@ public abstract class ItemSlotUIContainer<T> : GridContainer, IItemslotUIContain
|
||||
{
|
||||
protected readonly Dictionary<string, T> Buttons = new();
|
||||
|
||||
private int? _maxColumns;
|
||||
|
||||
public int? MaxColumns
|
||||
{
|
||||
get => _maxColumns;
|
||||
set => _maxColumns = value;
|
||||
}
|
||||
|
||||
public virtual bool TryAddButton(T newButton, out T button)
|
||||
{
|
||||
var tempButton = AddButton(newButton);
|
||||
@@ -68,7 +76,7 @@ public abstract class ItemSlotUIContainer<T> : GridContainer, IItemslotUIContain
|
||||
{
|
||||
if (!Children.Contains(newButton) && newButton.Parent == null && newButton.SlotName != "")
|
||||
AddChild(newButton);
|
||||
Columns = ChildCount;
|
||||
Columns = _maxColumns ?? ChildCount;
|
||||
return AddButtonToDict(newButton);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Client.Hands.Systems;
|
||||
using Content.Client.Inventory;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Client.UserInterface.Systems.Gameplay;
|
||||
using Content.Client.UserInterface.Systems.Inventory.Controls;
|
||||
using Content.Client.UserInterface.Systems.Inventory.Widgets;
|
||||
using Content.Client.UserInterface.Systems.Inventory.Windows;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Input;
|
||||
@@ -16,7 +20,6 @@ using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Utility;
|
||||
using static Content.Client.Inventory.ClientInventorySystem;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Inventory;
|
||||
|
||||
@@ -35,9 +38,26 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
||||
|
||||
private StrippingWindow? _strippingWindow;
|
||||
private ItemSlotButtonContainer? _inventoryHotbar;
|
||||
private MenuButton? InventoryButton => UIManager.ActiveScreen?.GetWidget<MenuBar.Widgets.GameTopMenuBar>()?.InventoryButton;
|
||||
private SlotButton? _inventoryButton;
|
||||
|
||||
private SlotControl? _lastHovered = null;
|
||||
private SlotControl? _lastHovered;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
|
||||
gameplayStateLoad.OnScreenLoad += OnScreenLoad;
|
||||
}
|
||||
|
||||
private void OnScreenLoad()
|
||||
{
|
||||
if (UIManager.ActiveScreen == null)
|
||||
return;
|
||||
|
||||
var inventoryGui = UIManager.GetActiveUIWidget<InventoryGui>();
|
||||
RegisterInventoryButton(inventoryGui.InventoryButton);
|
||||
}
|
||||
|
||||
public void OnStateEntered(GameplayState state)
|
||||
{
|
||||
@@ -67,26 +87,6 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
||||
CommandBinds.Unregister<ClientInventorySystem>();
|
||||
}
|
||||
|
||||
public void UnloadButton()
|
||||
{
|
||||
if (InventoryButton == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
InventoryButton.OnPressed -= InventoryButtonPressed;
|
||||
}
|
||||
|
||||
public void LoadButton()
|
||||
{
|
||||
if (InventoryButton == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
InventoryButton.OnPressed += InventoryButtonPressed;
|
||||
}
|
||||
|
||||
private SlotButton CreateSlotButton(SlotData data)
|
||||
{
|
||||
var button = new SlotButton(data);
|
||||
@@ -102,8 +102,25 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
||||
_inventoryHotbar = inventoryHotbar;
|
||||
}
|
||||
|
||||
private void InventoryButtonPressed(ButtonEventArgs args)
|
||||
public void RegisterInventoryButton(SlotButton? button)
|
||||
{
|
||||
if (_inventoryButton != null)
|
||||
{
|
||||
_inventoryButton.Pressed -= InventoryButtonPressed;
|
||||
}
|
||||
|
||||
if (button != null)
|
||||
{
|
||||
_inventoryButton = button;
|
||||
_inventoryButton.Pressed += InventoryButtonPressed;
|
||||
}
|
||||
}
|
||||
|
||||
private void InventoryButtonPressed(GUIBoundKeyEventArgs args, SlotControl control)
|
||||
{
|
||||
if (args.Function != EngineKeyFunctions.UIClick)
|
||||
return;
|
||||
|
||||
ToggleInventoryBar();
|
||||
}
|
||||
|
||||
@@ -130,6 +147,52 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
||||
var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage);
|
||||
SpriteUpdated(update);
|
||||
}
|
||||
|
||||
if (_inventoryHotbar == null)
|
||||
return;
|
||||
|
||||
var clothing = clientInv.SlotData.Where(p => !p.Value.HasSlotGroup).ToList();
|
||||
|
||||
if (_inventoryButton != null)
|
||||
_inventoryButton.Visible = clothing.Count != 0;
|
||||
if (clothing.Count == 0)
|
||||
return;
|
||||
|
||||
foreach (var child in new List<Control>(_inventoryHotbar.Children))
|
||||
{
|
||||
if (child is not SlotControl)
|
||||
_inventoryHotbar.RemoveChild(child);
|
||||
}
|
||||
|
||||
var maxWidth = clothing.Max(p => p.Value.ButtonOffset.X) + 1;
|
||||
var maxIndex = clothing.Select(p => GetIndex(p.Value.ButtonOffset)).Max();
|
||||
|
||||
_inventoryHotbar.MaxColumns = maxWidth;
|
||||
_inventoryHotbar.Columns = maxWidth;
|
||||
|
||||
for (var i = 0; i <= maxIndex; i++)
|
||||
{
|
||||
var index = i;
|
||||
if (clothing.FirstOrNull(p => GetIndex(p.Value.ButtonOffset) == index) is { } pair)
|
||||
{
|
||||
if (_inventoryHotbar.TryGetButton(pair.Key, out var slot))
|
||||
slot.SetPositionLast();
|
||||
}
|
||||
else
|
||||
{
|
||||
_inventoryHotbar.AddChild(new Control
|
||||
{
|
||||
MinSize = new Vector2(64, 64)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
int GetIndex(Vector2i position)
|
||||
{
|
||||
return position.Y * maxWidth + position.X;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStrippingWindow(InventorySlotsComponent? clientInv)
|
||||
@@ -178,18 +241,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
||||
}
|
||||
|
||||
UpdateInventoryHotbar(_playerInventory);
|
||||
if (_inventoryHotbar.Visible)
|
||||
{
|
||||
_inventoryHotbar.Visible = false;
|
||||
if (InventoryButton != null)
|
||||
InventoryButton.Pressed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_inventoryHotbar.Visible = true;
|
||||
if (InventoryButton != null)
|
||||
InventoryButton.Pressed = true;
|
||||
}
|
||||
_inventoryHotbar.Visible = !_inventoryHotbar.Visible;
|
||||
}
|
||||
|
||||
// Neuron Activation
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<widgets:InventoryGui
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:inventory="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Controls"
|
||||
xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Widgets"
|
||||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
|
||||
Name="InventoryInterface"
|
||||
VerticalExpand="True"
|
||||
VerticalAlignment="Bottom"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center">
|
||||
<Control HorizontalAlignment="Center">
|
||||
<controls:SlotButton
|
||||
Name="InventoryButton"
|
||||
Access="Public"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalExpand="False"
|
||||
VerticalExpand="False"
|
||||
ButtonTexturePath="Slots/toggle"/>
|
||||
<inventory:ItemSlotButtonContainer
|
||||
Name="InventoryHotbar"
|
||||
Access="Public"
|
||||
Visible="False"
|
||||
MaxColumns="3"
|
||||
SlotGroup="Default"
|
||||
ExpandBackwards="True"
|
||||
VerticalExpand="True"
|
||||
HorizontalAlignment="Center"
|
||||
/>
|
||||
</Control>
|
||||
</widgets:InventoryGui>
|
||||
@@ -0,0 +1,19 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Inventory.Widgets;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class InventoryGui : UIWidget
|
||||
{
|
||||
public InventoryGui()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
var inventoryUIController = UserInterfaceManager.GetUIController<InventoryUIController>();
|
||||
inventoryUIController.RegisterInventoryBarContainer(InventoryHotbar);
|
||||
|
||||
LayoutContainer.SetGrowVertical(this, LayoutContainer.GrowDirection.Begin);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user