Improve stripping UI (#9768)

This commit is contained in:
Leon Friedrich
2022-10-16 06:00:04 +13:00
committed by GitHub
parent be90d63d15
commit efac113469
32 changed files with 518 additions and 461 deletions

View File

@@ -0,0 +1,43 @@
using Content.Client.Inventory;
using Content.Shared.Cuffs.Components;
using Content.Shared.Ensnaring.Components;
using Content.Shared.Hands;
using Content.Shared.Inventory.Events;
using Robust.Client.GameObjects;
namespace Content.Client.Strip;
/// <summary>
/// This is the client-side stripping system, which just triggers UI updates on events.
/// </summary>
public sealed class StrippableSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StrippableComponent, CuffedStateChangeEvent>(OnCuffStateChange);
SubscribeLocalEvent<StrippableComponent, DidEquipEvent>(UpdateUi);
SubscribeLocalEvent<StrippableComponent, DidUnequipEvent>(UpdateUi);
SubscribeLocalEvent<StrippableComponent, DidEquipHandEvent>(UpdateUi);
SubscribeLocalEvent<StrippableComponent, DidUnequipHandEvent>(UpdateUi);
SubscribeLocalEvent<StrippableComponent, EnsnaredChangedEvent>(UpdateUi);
}
private void OnCuffStateChange(EntityUid uid, StrippableComponent component, ref CuffedStateChangeEvent args)
{
UpdateUi(uid, component);
}
public void UpdateUi(EntityUid uid, StrippableComponent? component = null, EntityEventArgs? args = null)
{
if (!TryComp(uid, out ClientUserInterfaceComponent? uiComp))
return;
foreach (var ui in uiComp.Interfaces)
{
if (ui is StrippableBoundUserInterface stripUi)
stripUi.DirtyMenu();
}
}
}

View File

@@ -1,64 +1,45 @@
using System;
using Content.Client.Stylesheets;
using Robust.Client.UserInterface;
using Content.Client.Inventory;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Timing;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.Strip
{
public sealed class StrippingMenu : DefaultWindow
{
private readonly BoxContainer _vboxContainer;
public LayoutContainer InventoryContainer = new();
public BoxContainer HandsContainer = new() { Orientation = LayoutOrientation.Horizontal };
public BoxContainer SnareContainer = new();
private StrippableBoundUserInterface _bui;
public bool Dirty = true;
public StrippingMenu(string title)
public StrippingMenu(string title, StrippableBoundUserInterface bui)
{
MinSize = SetSize = (400, 620);
Title = title;
_bui = bui;
_vboxContainer = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
VerticalExpand = true,
SeparationOverride = 5,
};
Contents.AddChild(_vboxContainer);
var box = new BoxContainer() { Orientation = LayoutOrientation.Vertical, Margin = new Thickness(0, 8) };
Contents.AddChild(box);
box.AddChild(SnareContainer);
box.AddChild(HandsContainer);
box.AddChild(InventoryContainer);
}
public void ClearButtons()
{
_vboxContainer.DisposeAllChildren();
InventoryContainer.DisposeAllChildren();
HandsContainer.DisposeAllChildren();
SnareContainer.DisposeAllChildren();
}
public void AddButton(string title, string name, Action<BaseButton.ButtonEventArgs> onPressed)
protected override void FrameUpdate(FrameEventArgs args)
{
var button = new Button()
{
Text = name,
StyleClasses = { StyleBase.ButtonOpenRight }
};
if (!Dirty)
return;
button.OnPressed += onPressed;
_vboxContainer.AddChild(new BoxContainer
{
Orientation = LayoutOrientation.Horizontal,
HorizontalExpand = true,
SeparationOverride = 5,
Children =
{
new Label()
{
Text = $"{title}:"
},
new Control()
{
HorizontalExpand = true
},
button,
}
});
Dirty = false;
_bui.UpdateMenu();
}
}
}