diff --git a/Content.Client/UserInterface/Screens/DefaultGameScreen.xaml b/Content.Client/UserInterface/Screens/DefaultGameScreen.xaml index 5c09574005..54aeffe72c 100644 --- a/Content.Client/UserInterface/Screens/DefaultGameScreen.xaml +++ b/Content.Client/UserInterface/Screens/DefaultGameScreen.xaml @@ -8,6 +8,7 @@ xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Ghost.Widgets" xmlns:hotbar="clr-namespace:Content.Client.UserInterface.Systems.Hotbar.Widgets" xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" + xmlns:inventory="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Widgets" Name="DefaultHud" VerticalExpand="False" VerticalAlignment="Bottom" @@ -25,6 +26,7 @@ + diff --git a/Content.Client/UserInterface/Screens/DefaultGameScreen.xaml.cs b/Content.Client/UserInterface/Screens/DefaultGameScreen.xaml.cs index a8a53e83c7..0fb1b7d507 100644 --- a/Content.Client/UserInterface/Screens/DefaultGameScreen.xaml.cs +++ b/Content.Client/UserInterface/Screens/DefaultGameScreen.xaml.cs @@ -18,6 +18,7 @@ public sealed partial class DefaultGameScreen : InGameScreen SetAnchorPreset(ViewportContainer, LayoutPreset.Wide); SetAnchorAndMarginPreset(TopLeft, LayoutPreset.TopLeft, margin: 10); SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80); + SetAnchorAndMarginPreset(Inventory, LayoutPreset.BottomLeft, margin: 5); SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5); SetAnchorAndMarginPreset(Chat, LayoutPreset.TopRight, margin: 10); SetAnchorAndMarginPreset(Alerts, LayoutPreset.TopRight, margin: 10); diff --git a/Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml b/Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml index d62ad33dfc..7f1d1bcd5b 100644 --- a/Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml +++ b/Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml @@ -9,6 +9,7 @@ xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Ghost.Widgets" xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client" + xmlns:inventory="clr-namespace:Content.Client.UserInterface.Systems.Inventory.Widgets" Name="SeparatedChatHud" VerticalExpand="False" VerticalAlignment="Bottom" @@ -17,7 +18,8 @@ - + + diff --git a/Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml.cs b/Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml.cs index 7816cf1be1..45a29e03f1 100644 --- a/Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml.cs +++ b/Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml.cs @@ -18,6 +18,7 @@ public sealed partial class SeparatedChatGameScreen : InGameScreen SetAnchorPreset(ScreenContainer, LayoutPreset.Wide); SetAnchorPreset(ViewportContainer, LayoutPreset.Wide); SetAnchorPreset(MainViewport, LayoutPreset.Wide); + SetAnchorAndMarginPreset(Inventory, LayoutPreset.BottomLeft, margin: 5); SetAnchorAndMarginPreset(TopLeftContainer, LayoutPreset.TopLeft, margin: 10); SetAnchorAndMarginPreset(Ghost, LayoutPreset.BottomWide, margin: 80); SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5); diff --git a/Content.Client/UserInterface/Systems/Hotbar/HotbarUIController.cs b/Content.Client/UserInterface/Systems/Hotbar/HotbarUIController.cs index 397da978d8..daececcd35 100644 --- a/Content.Client/UserInterface/Systems/Hotbar/HotbarUIController.cs +++ b/Content.Client/UserInterface/Systems/Hotbar/HotbarUIController.cs @@ -4,6 +4,7 @@ using Content.Client.UserInterface.Systems.Hands.Controls; using Content.Client.UserInterface.Systems.Hotbar.Widgets; using Content.Client.UserInterface.Systems.Inventory; using Content.Client.UserInterface.Systems.Inventory.Controls; +using Content.Client.UserInterface.Systems.Inventory.Widgets; using Content.Client.UserInterface.Systems.Storage; using Content.Client.UserInterface.Systems.Storage.Controls; using Robust.Client.UserInterface; @@ -30,13 +31,12 @@ public sealed class HotbarUIController : UIController ReloadHotbar(); } - public void Setup(HandsContainer handsContainer, ItemSlotButtonContainer inventoryBar, ItemStatusPanel handStatus, StorageContainer storageContainer) + public void Setup(HandsContainer handsContainer, ItemStatusPanel handStatus, StorageContainer storageContainer) { _inventory = UIManager.GetUIController(); _hands = UIManager.GetUIController(); _storage = UIManager.GetUIController(); _hands.RegisterHandContainer(handsContainer); - _inventory.RegisterInventoryBarContainer(inventoryBar); _storage.RegisterStorageContainer(storageContainer); } @@ -47,25 +47,35 @@ public sealed class HotbarUIController : UIController return; } - var hotbar = UIManager.ActiveScreen.GetWidget(); + if (UIManager.ActiveScreen.GetWidget() is { } hotbar) + { + foreach (var container in GetAllItemSlotContainers(hotbar)) + { + // Yes, this is dirty. + container.SlotGroup = container.SlotGroup; + } + } - if (hotbar == null) + _hands?.ReloadHands(); + _inventory?.ReloadSlots(); + + //todo move this over to its own hellhole + var inventory = UIManager.ActiveScreen.GetWidget(); + if (inventory == null) { return; } - foreach (var container in GetAllItemSlotContainers(hotbar)) + foreach (var container in GetAllItemSlotContainers(inventory)) { // Yes, this is dirty. container.SlotGroup = container.SlotGroup; } - _hands?.ReloadHands(); - _inventory?.ReloadSlots(); - _inventory?.RegisterInventoryBarContainer(hotbar.InventoryHotbar); + _inventory?.RegisterInventoryBarContainer(inventory.InventoryHotbar); } - private IEnumerable GetAllItemSlotContainers(Control gui) + private static IEnumerable GetAllItemSlotContainers(Control gui) { var result = new List(); diff --git a/Content.Client/UserInterface/Systems/Hotbar/Widgets/HotbarGui.xaml b/Content.Client/UserInterface/Systems/Hotbar/Widgets/HotbarGui.xaml index 04b606de08..0e9f0c77f9 100644 --- a/Content.Client/UserInterface/Systems/Hotbar/Widgets/HotbarGui.xaml +++ b/Content.Client/UserInterface/Systems/Hotbar/Widgets/HotbarGui.xaml @@ -5,38 +5,26 @@ xmlns:hands="clr-namespace:Content.Client.UserInterface.Systems.Hands.Controls" xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Hotbar.Widgets" Name="HotbarInterface" - VerticalExpand="False" + VerticalExpand="True" VerticalAlignment="Bottom" Orientation="Vertical" HorizontalAlignment="Center"> - - - - - - - + + + + + + (); - hotbarController.Setup(HandContainer, InventoryHotbar, StatusPanel, StoragePanel); + hotbarController.Setup(HandContainer, StatusPanel, StoragePanel); LayoutContainer.SetGrowVertical(this, LayoutContainer.GrowDirection.Begin); } diff --git a/Content.Client/UserInterface/Systems/Inventory/Controls/ItemSlotUIContainer.cs b/Content.Client/UserInterface/Systems/Inventory/Controls/ItemSlotUIContainer.cs index d44a4a2d76..df45ceabf6 100644 --- a/Content.Client/UserInterface/Systems/Inventory/Controls/ItemSlotUIContainer.cs +++ b/Content.Client/UserInterface/Systems/Inventory/Controls/ItemSlotUIContainer.cs @@ -16,6 +16,14 @@ public abstract class ItemSlotUIContainer : GridContainer, IItemslotUIContain { protected readonly Dictionary 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 : GridContainer, IItemslotUIContain { if (!Children.Contains(newButton) && newButton.Parent == null && newButton.SlotName != "") AddChild(newButton); - Columns = ChildCount; + Columns = _maxColumns ?? ChildCount; return AddButtonToDict(newButton); } diff --git a/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs b/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs index 59beaa5a02..8af68282f3 100644 --- a/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs +++ b/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs @@ -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 UIManager.ActiveScreen?.GetWidget()?.InventoryButton; + private SlotButton? _inventoryButton; - private SlotControl? _lastHovered = null; + private SlotControl? _lastHovered; + + public override void Initialize() + { + base.Initialize(); + + var gameplayStateLoad = UIManager.GetUIController(); + gameplayStateLoad.OnScreenLoad += OnScreenLoad; + } + + private void OnScreenLoad() + { + if (UIManager.ActiveScreen == null) + return; + + var inventoryGui = UIManager.GetActiveUIWidget(); + RegisterInventoryButton(inventoryGui.InventoryButton); + } public void OnStateEntered(GameplayState state) { @@ -67,26 +87,6 @@ public sealed class InventoryUIController : UIController, IOnStateEntered(); } - 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 !p.Value.HasSlotGroup).ToList(); + + if (_inventoryButton != null) + _inventoryButton.Visible = clothing.Count != 0; + if (clothing.Count == 0) + return; + + foreach (var child in new List(_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 + + + + + diff --git a/Content.Client/UserInterface/Systems/Inventory/Widgets/InventoryGui.xaml.cs b/Content.Client/UserInterface/Systems/Inventory/Widgets/InventoryGui.xaml.cs new file mode 100644 index 0000000000..90154c5a9f --- /dev/null +++ b/Content.Client/UserInterface/Systems/Inventory/Widgets/InventoryGui.xaml.cs @@ -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.RegisterInventoryBarContainer(InventoryHotbar); + + LayoutContainer.SetGrowVertical(this, LayoutContainer.GrowDirection.Begin); + } +} diff --git a/Content.Client/UserInterface/Systems/MenuBar/GameTopMenuBarUIController.cs b/Content.Client/UserInterface/Systems/MenuBar/GameTopMenuBarUIController.cs index b399e83fc6..1505db48a7 100644 --- a/Content.Client/UserInterface/Systems/MenuBar/GameTopMenuBarUIController.cs +++ b/Content.Client/UserInterface/Systems/MenuBar/GameTopMenuBarUIController.cs @@ -6,7 +6,6 @@ using Content.Client.UserInterface.Systems.Crafting; using Content.Client.UserInterface.Systems.EscapeMenu; using Content.Client.UserInterface.Systems.Gameplay; using Content.Client.UserInterface.Systems.Guidebook; -using Content.Client.UserInterface.Systems.Inventory; using Content.Client.UserInterface.Systems.MenuBar.Widgets; using Content.Client.UserInterface.Systems.Sandbox; using Robust.Client.UserInterface.Controllers; @@ -16,7 +15,6 @@ namespace Content.Client.UserInterface.Systems.MenuBar; public sealed class GameTopMenuBarUIController : UIController { [Dependency] private readonly EscapeUIController _escape = default!; - [Dependency] private readonly InventoryUIController _inventory = default!; [Dependency] private readonly AdminUIController _admin = default!; [Dependency] private readonly CharacterUIController _character = default!; [Dependency] private readonly CraftingUIController _crafting = default!; @@ -40,7 +38,6 @@ public sealed class GameTopMenuBarUIController : UIController { _escape.UnloadButton(); _guidebook.UnloadButton(); - _inventory.UnloadButton(); _admin.UnloadButton(); _character.UnloadButton(); _crafting.UnloadButton(); @@ -53,7 +50,6 @@ public sealed class GameTopMenuBarUIController : UIController { _escape.LoadButton(); _guidebook.LoadButton(); - _inventory.LoadButton(); _admin.LoadButton(); _character.LoadButton(); _crafting.LoadButton(); diff --git a/Content.Client/UserInterface/Systems/MenuBar/Widgets/GameTopMenuBar.xaml b/Content.Client/UserInterface/Systems/MenuBar/Widgets/GameTopMenuBar.xaml index 6765699531..3c8cd1d164 100644 --- a/Content.Client/UserInterface/Systems/MenuBar/Widgets/GameTopMenuBar.xaml +++ b/Content.Client/UserInterface/Systems/MenuBar/Widgets/GameTopMenuBar.xaml @@ -43,16 +43,6 @@ HorizontalExpand="True" AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}" /> -