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

@@ -52,6 +52,9 @@ namespace Content.Client.Cuffs.Components
}
}
}
var ev = new CuffedStateChangeEvent();
_entityManager.EventBus.RaiseLocalEvent(Owner, ref ev);
}
protected override void OnRemove()

View File

@@ -0,0 +1,46 @@
using Content.Client.Ensnaring.Components;
using Content.Shared.Ensnaring;
using Robust.Client.GameObjects;
namespace Content.Client.Ensnaring.Visualizers;
public sealed class EnsnareableSystem : SharedEnsnareableSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EnsnareableComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<EnsnareableComponent, AppearanceChangeEvent>(OnAppearanceChange);
}
private void OnComponentInit(EntityUid uid, EnsnareableComponent component, ComponentInit args)
{
if(!TryComp<SpriteComponent>(uid, out var sprite))
return;
// TODO remove this, this should just be in yaml.
sprite.LayerMapReserveBlank(EnsnaredVisualLayers.Ensnared);
}
private void OnAppearanceChange(EntityUid uid, EnsnareableComponent component, ref AppearanceChangeEvent args)
{
if (args.Sprite == null || !args.Sprite.LayerMapTryGet(EnsnaredVisualLayers.Ensnared, out var layer))
return;
if (args.Component.TryGetData(EnsnareableVisuals.IsEnsnared, out bool isEnsnared))
{
if (component.Sprite != null)
{
args.Sprite.LayerSetRSI(layer, component.Sprite);
args.Sprite.LayerSetState(layer, component.State);
args.Sprite.LayerSetVisible(layer, isEnsnared);
}
}
}
}
public enum EnsnaredVisualLayers : byte
{
Ensnared,
}

View File

@@ -1,9 +0,0 @@
using Robust.Shared.Utility;
namespace Content.Client.Ensnaring.Visualizers;
[RegisterComponent]
[Access(typeof(EnsnareableVisualizerSystem))]
public sealed class EnsnareableVisualizerComponent : Component
{
}

View File

@@ -1,42 +0,0 @@
using Content.Client.Ensnaring.Components;
using Content.Shared.Ensnaring;
using Robust.Client.GameObjects;
using Robust.Shared.Utility;
namespace Content.Client.Ensnaring.Visualizers;
public sealed class EnsnareableVisualizerSystem : VisualizerSystem<EnsnareableComponent>
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EnsnareableVisualizerComponent, ComponentInit>(OnComponentInit);
}
private void OnComponentInit(EntityUid uid, EnsnareableVisualizerComponent component, ComponentInit args)
{
if(!TryComp<SpriteComponent>(uid, out var sprite))
return;
sprite.LayerMapReserveBlank(EnsnaredVisualLayers.Ensnared);
}
protected override void OnAppearanceChange(EntityUid uid, EnsnareableComponent component, ref AppearanceChangeEvent args)
{
if (args.Component.TryGetData(EnsnareableVisuals.IsEnsnared, out bool isEnsnared))
{
if (args.Sprite != null && component.Sprite != null)
{
args.Sprite.LayerSetRSI(EnsnaredVisualLayers.Ensnared, component.Sprite);
args.Sprite.LayerSetState(EnsnaredVisualLayers.Ensnared, component.State);
args.Sprite.LayerSetVisible(EnsnaredVisualLayers.Ensnared, isEnsnared);
}
}
}
}
public enum EnsnaredVisualLayers : byte
{
Ensnared,
}

View File

@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using Content.Client.Animations;
using Content.Client.Examine;
using Content.Client.Strip;
using Content.Client.Verbs;
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
@@ -13,6 +13,7 @@ using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Timing;
using System.Diagnostics.CodeAnalysis;
namespace Content.Client.Hands.Systems
{
@@ -23,6 +24,7 @@ namespace Content.Client.Hands.Systems
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly StrippableSystem _stripSys = default!;
[Dependency] private readonly ExamineSystem _examine = default!;
[Dependency] private readonly VerbSystem _verbs = default!;
@@ -92,6 +94,8 @@ namespace Content.Client.Hands.Systems
component.SortedHands = new(state.HandNames);
}
_stripSys.UpdateUi(uid);
if (component.ActiveHand == null && state.ActiveHand == null)
return; //edge case
@@ -236,6 +240,7 @@ namespace Content.Client.Hands.Systems
if (!handComp.Hands.TryGetValue(args.Container.ID, out var hand))
return;
UpdateHandVisuals(uid, args.Entity, hand);
_stripSys.UpdateUi(uid);
if (uid != _playerManager.LocalPlayer?.ControlledEntity)
return;
@@ -251,6 +256,7 @@ namespace Content.Client.Hands.Systems
if (!handComp.Hands.TryGetValue(args.Container.ID, out var hand))
return;
UpdateHandVisuals(uid, args.Entity, hand);
_stripSys.UpdateUi(uid);
if (uid != _playerManager.LocalPlayer?.ControlledEntity)
return;

View File

@@ -1,110 +1,226 @@
using Content.Client.Cuffs.Components;
using Content.Client.Examine;
using Content.Client.Hands;
using Content.Client.Strip;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.Hands.Controls;
using Content.Shared.Ensnaring.Components;
using Content.Shared.Hands.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Input;
using Content.Shared.Inventory;
using Content.Shared.Strip.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using static Content.Client.Inventory.ClientInventorySystem;
using static Robust.Client.UserInterface.Control;
namespace Content.Client.Inventory
{
[UsedImplicitly]
public sealed class StrippableBoundUserInterface : BoundUserInterface
{
public Dictionary<(string ID, string Name), string>? Inventory { get; private set; }
public Dictionary<string, string>? Hands { get; private set; }
public Dictionary<EntityUid, string>? Handcuffs { get; private set; }
public Dictionary<EntityUid, string>? Ensnare { get; private set; }
private const int ButtonSeparation = 4;
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly IEntityManager _entMan = default!;
private ExamineSystem _examine = default!;
private InventorySystem _inv = default!;
[ViewVariables]
private StrippingMenu? _strippingMenu;
public const string HiddenPocketEntityId = "StrippingHiddenEntity";
private EntityUid _virtualHiddenEntity;
public StrippableBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{
IoCManager.InjectDependencies(this);
_examine = _entMan.EntitySysManager.GetEntitySystem<ExamineSystem>();
_inv = _entMan.EntitySysManager.GetEntitySystem<InventorySystem>();
var title = Loc.GetString("strippable-bound-user-interface-stripping-menu-title", ("ownerName", Identity.Name(Owner.Owner, _entMan)));
_strippingMenu = new StrippingMenu(title, this);
_strippingMenu.OnClose += Close;
_virtualHiddenEntity = _entMan.SpawnEntity(HiddenPocketEntityId, MapCoordinates.Nullspace);
}
protected override void Open()
{
base.Open();
var entMan = IoCManager.Resolve<IEntityManager>();
_strippingMenu = new StrippingMenu($"{Loc.GetString("strippable-bound-user-interface-stripping-menu-title", ("ownerName", Identity.Name(Owner.Owner, entMan)))}");
_strippingMenu.OnClose += Close;
_strippingMenu.OpenCenteredLeft();
UpdateMenu();
_strippingMenu?.OpenCenteredLeft();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_entMan.DeleteEntity(_virtualHiddenEntity);
if (!disposing)
return;
_strippingMenu?.Dispose();
}
private void UpdateMenu()
public void DirtyMenu()
{
if (_strippingMenu == null) return;
if (_strippingMenu != null)
_strippingMenu.Dirty = true;
}
public void UpdateMenu()
{
if (_strippingMenu == null)
return;
_strippingMenu.ClearButtons();
if (Inventory != null)
if (_entMan.TryGetComponent(Owner.Owner, out InventoryComponent? inv) && _protoMan.TryIndex<InventoryTemplatePrototype>(inv.TemplateId, out var template))
{
foreach (var (slot, name) in Inventory)
foreach (var slot in template.Slots)
{
_strippingMenu.AddButton(slot.Name, name, (ev) =>
{
SendMessage(new StrippingInventoryButtonPressed(slot.ID));
});
AddInventoryButton(slot.Name, template, inv);
}
}
if (Hands != null)
if (_entMan.TryGetComponent(Owner.Owner, out HandsComponent? handsComp))
{
foreach (var (hand, name) in Hands)
// good ol hands shit code. there is a GuiHands comparer that does the same thing... but these are hands
// and not gui hands... which are different...
foreach (var hand in handsComp.Hands.Values)
{
_strippingMenu.AddButton(hand, name, (ev) =>
{
SendMessage(new StrippingHandButtonPressed(hand));
});
if (hand.Location != HandLocation.Right)
continue;
AddHandButton(hand);
}
foreach (var hand in handsComp.Hands.Values)
{
if (hand.Location != HandLocation.Middle)
continue;
AddHandButton(hand);
}
foreach (var hand in handsComp.Hands.Values)
{
if (hand.Location != HandLocation.Left)
continue;
AddHandButton(hand);
}
}
if (Handcuffs != null)
// snare-removal button. This is just the old button before the change to item slots. It is pretty out of place.
if (_entMan.TryGetComponent(Owner.Owner, out SharedEnsnareableComponent? snare) && snare.IsEnsnared)
{
foreach (var (id, name) in Handcuffs)
var button = new Button()
{
_strippingMenu.AddButton(Loc.GetString("strippable-bound-user-interface-stripping-menu-handcuffs-button"), name, (ev) =>
{
SendMessage(new StrippingHandcuffButtonPressed(id));
});
}
Text = Loc.GetString("strippable-bound-user-interface-stripping-menu-ensnare-button"),
StyleClasses = { StyleBase.ButtonOpenRight }
};
button.OnPressed += (_) => SendMessage(new StrippingEnsnareButtonPressed());
_strippingMenu.SnareContainer.AddChild(button);
}
if (Ensnare != null)
{
foreach (var (id, name) in Ensnare)
{
_strippingMenu.AddButton(Loc.GetString("strippable-bound-user-interface-stripping-menu-ensnare-button"), name, (ev) =>
{
SendMessage(new StrippingEnsnareButtonPressed(id));
});
}
}
// TODO fix layout container measuring (its broken atm).
// _strippingMenu.InvalidateMeasure();
// _strippingMenu.Contents.Measure(Vector2.Infinity);
// TODO allow windows to resize based on content's desired size
// for now: shit-code
// this breaks for drones (too many hands, lots of empty vertical space), and looks shit for monkeys and the like.
// but the window is realizable, so eh.
_strippingMenu.SetSize = (220, snare?.IsEnsnared == true ? 550 : 530);
}
protected override void UpdateState(BoundUserInterfaceState state)
private void AddHandButton(Hand hand)
{
base.UpdateState(state);
var button = new HandButton(hand.Name, hand.Location);
if (state is not StrippingBoundUserInterfaceState stripState) return;
button.Pressed += SlotPressed;
Inventory = stripState.Inventory;
Hands = stripState.Hands;
Handcuffs = stripState.Handcuffs;
Ensnare = stripState.Ensnare;
if (_entMan.TryGetComponent(hand.HeldEntity, out HandVirtualItemComponent? virt))
{
button.Blocked = true;
if (_entMan.TryGetComponent(Owner.Owner, out CuffableComponent? cuff) && cuff.Container.Contains(virt.BlockingEntity))
button.BlockedRect.MouseFilter = MouseFilterMode.Ignore;
}
UpdateEntityIcon(button, hand.HeldEntity);
_strippingMenu!.HandsContainer.AddChild(button);
}
UpdateMenu();
private void SlotPressed(GUIBoundKeyEventArgs ev, SlotControl slot)
{
// TODO: allow other interactions? Verbs? But they should then generate a pop-up and/or have a delay so the
// user that is being stripped can prevent the verbs from being exectuted.
// So for now: only stripping & examining
if (ev.Function == EngineKeyFunctions.Use)
{
SendMessage(new StrippingSlotButtonPressed(slot.SlotName, slot is HandButton));
}
else if (ev.Function == ContentKeyFunctions.ExamineEntity && slot.Entity != null)
{
_examine.DoExamine(slot.Entity.Value);
return;
}
if (ev.Function != EngineKeyFunctions.Use)
return;
}
private void AddInventoryButton(string slotId, InventoryTemplatePrototype template, InventoryComponent inv)
{
if (!_inv.TryGetSlotContainer(inv.Owner, slotId, out var container, out var slotDef, inv))
return;
var entity = container.ContainedEntity;
// If this is a full pocket, obscure the real entity
if (entity != null && slotDef.StripHidden)
entity = _virtualHiddenEntity;
var button = new SlotButton(new SlotData(slotDef, container));
button.Pressed += SlotPressed;
_strippingMenu!.InventoryContainer.AddChild(button);
UpdateEntityIcon(button, entity);
LayoutContainer.SetPosition(button, slotDef.StrippingWindowPos * (SlotControl.DefaultButtonSize + ButtonSeparation));
}
private void UpdateEntityIcon(SlotControl button, EntityUid? entity)
{
// Hovering, highlighting & storage are features of general hands & inv GUIs. This UI just re-uses these because I'm lazy.
button.ClearHover();
button.StorageButton.Visible = false;
if (entity == null)
{
button.SpriteView.Sprite = null;
return;
}
SpriteComponent? sprite;
if (_entMan.TryGetComponent(entity, out HandVirtualItemComponent? virt))
_entMan.TryGetComponent(virt.BlockingEntity, out sprite);
else if (!_entMan.TryGetComponent(entity, out sprite))
return;
button.SpriteView.Sprite = sprite;
}
}
}

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();
}
}
}

View File

@@ -1,4 +1,4 @@
using Content.Client.Cooldown;
using Content.Client.Cooldown;
using Content.Client.UserInterface.Systems.Inventory.Controls;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
@@ -12,6 +12,8 @@ namespace Content.Client.UserInterface.Controls
{
private const string HighlightShader = "SelectionOutlineInrange";
public static int DefaultButtonSize = 64;
public TextureRect ButtonRect { get; }
public TextureRect BlockedRect { get; }
public TextureRect HighlightRect { get; }
@@ -111,7 +113,7 @@ namespace Content.Client.UserInterface.Controls
{
IoCManager.InjectDependencies(this);
Name = "SlotButton_null";
MinSize = (64, 64);
MinSize = (DefaultButtonSize, DefaultButtonSize);
AddChild(ButtonRect = new TextureRect
{
TextureScale = (2, 2),