Files
wwdpublic/Content.Client/UserInterface/Systems/Hotbar/HotbarUIController.cs
sleepyyapril 1e423cabf9 v245.0.0 (and Storage UI V2) (#1799)
Contains:

- Storage UI v2, required for removing DeferredClose.
- Stock market refactor (mostly some basic changes to stock market,
didn't want to make a whole other PR for it)
- Make guidebook remember where you left off
- Any other PRs are purely for fixing issues related to the above PRs or
the engine update.

🆑
- add: Ported Storage UI v2.
- tweak: The guidebook will now remember where you left off.

---------

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Co-authored-by: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: 12rabbits <53499656+12rabbits@users.noreply.github.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
Co-authored-by: gluesniffler <159397573+gluesniffler@users.noreply.github.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
(cherry picked from commit 3c37ff1c48637d1cdf8bc3c6b1412dad338ea205)
2025-02-28 16:22:37 +03:00

94 lines
2.8 KiB
C#

using Content.Client.UserInterface.Systems.Gameplay;
using Content.Client.UserInterface.Systems.Hands;
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;
using Robust.Client.UserInterface.Controllers;
namespace Content.Client.UserInterface.Systems.Hotbar;
public sealed class HotbarUIController : UIController
{
private InventoryUIController? _inventory;
private HandsUIController? _hands;
private StorageUIController? _storage;
public override void Initialize()
{
base.Initialize();
var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
gameplayStateLoad.OnScreenLoad += OnScreenLoad;
}
private void OnScreenLoad()
{
ReloadHotbar();
}
public void Setup(HandsContainer handsContainer)
{
_inventory = UIManager.GetUIController<InventoryUIController>();
_hands = UIManager.GetUIController<HandsUIController>();
_storage = UIManager.GetUIController<StorageUIController>();
_hands.RegisterHandContainer(handsContainer);
}
public void ReloadHotbar()
{
if (UIManager.ActiveScreen == null)
{
return;
}
if (UIManager.ActiveScreen.GetWidget<HotbarGui>() is { } hotbar)
{
foreach (var container in GetAllItemSlotContainers(hotbar))
{
// Yes, this is dirty.
container.SlotGroup = container.SlotGroup;
}
}
_hands?.ReloadHands();
_inventory?.ReloadSlots();
//todo move this over to its own hellhole
var inventory = UIManager.ActiveScreen.GetWidget<InventoryGui>();
if (inventory == null)
{
return;
}
foreach (var container in GetAllItemSlotContainers(inventory))
{
// Yes, this is dirty.
container.SlotGroup = container.SlotGroup;
}
_inventory?.RegisterInventoryBarContainer(inventory.InventoryHotbar);
}
private static IEnumerable<ItemSlotButtonContainer> GetAllItemSlotContainers(Control gui)
{
var result = new List<ItemSlotButtonContainer>();
foreach (var child in gui.Children)
{
if (child is ItemSlotButtonContainer container)
{
result.Add(container);
}
result.AddRange(GetAllItemSlotContainers(child));
}
return result;
}
}