Stripping (#1668)
* Start work on stripping. * more strippable work * Stripping works * Nullable * MORE NULLABLE * nullable moment * life is pain * Interaction check. * Update Content.Client/GameObjects/Components/HUD/Inventory/StrippableBoundUserInterface.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Client/GameObjects/Components/HUD/Inventory/StrippableBoundUserInterface.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Server/GameObjects/Components/GUI/HandsComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Server/GameObjects/Components/GUI/HandsComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Server/GameObjects/Components/GUI/HandsComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Server/GameObjects/Components/GUI/StrippableComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Server/GameObjects/Components/GUI/StrippableComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Server/GameObjects/Components/GUI/HandsComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Server/GameObjects/Components/GUI/StrippableComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Server/GameObjects/Components/GUI/StrippableComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Shared/GameObjects/Components/GUI/SharedStrippableComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Update Content.Server/GameObjects/Components/GUI/StrippableComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Rename InventoryComponent and HandsComponent's OnChanged event to OnItemChanged * Apply suggestions from code review Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Use static EquipmentSlotDefines * Do not expose ContainerSlot on Inventory or Hands. Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
e047262289
commit
c3df108b27
@@ -0,0 +1,22 @@
|
||||
using Content.Client.GameObjects.Components.Items;
|
||||
using Content.Client.Interfaces.GameObjects.Components.Interaction;
|
||||
using Content.Shared.GameObjects.Components.GUI;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.GUI
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class StrippableComponent : SharedStrippableComponent, IClientDraggable
|
||||
{
|
||||
public bool ClientCanDropOn(CanDropEventArgs eventArgs)
|
||||
{
|
||||
return eventArgs.Target.HasComponent<HandsComponent>()
|
||||
&& eventArgs.Target != eventArgs.Dragged && eventArgs.Target == eventArgs.User;
|
||||
}
|
||||
|
||||
public bool ClientCanDrag(CanDragEventArgs eventArgs)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.GameObjects.Components.GUI;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.HUD.Inventory
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class StrippableBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
public Dictionary<Slots, string> Inventory { get; private set; }
|
||||
public Dictionary<string, string> Hands { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
private StrippingMenu _strippingMenu;
|
||||
|
||||
public StrippableBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
_strippingMenu = new StrippingMenu($"{Owner.Owner.Name}'s inventory");
|
||||
_strippingMenu.OpenCentered();
|
||||
UpdateMenu();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing) return;
|
||||
_strippingMenu.Dispose();
|
||||
|
||||
_strippingMenu.Close();
|
||||
}
|
||||
|
||||
private void UpdateMenu()
|
||||
{
|
||||
if (_strippingMenu == null) return;
|
||||
|
||||
_strippingMenu.ClearButtons();
|
||||
|
||||
if(Inventory != null)
|
||||
foreach (var (slot, name) in Inventory)
|
||||
{
|
||||
_strippingMenu.AddButton(EquipmentSlotDefines.SlotNames[slot], name, (ev) =>
|
||||
{
|
||||
SendMessage(new StrippingInventoryButtonPressed(slot));
|
||||
});
|
||||
}
|
||||
|
||||
if(Hands != null)
|
||||
foreach (var (hand, name) in Hands)
|
||||
{
|
||||
_strippingMenu.AddButton(hand, name, (ev) =>
|
||||
{
|
||||
SendMessage(new StrippingHandButtonPressed(hand));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (!(state is StrippingBoundUserInterfaceState stripState)) return;
|
||||
|
||||
Inventory = stripState.Inventory;
|
||||
Hands = stripState.Hands;
|
||||
|
||||
UpdateMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ namespace Content.Client.GameObjects.Components.Items
|
||||
[Dependency] private readonly IGameHud _gameHud = default!;
|
||||
#pragma warning restore 649
|
||||
|
||||
/// <inheritdoc />
|
||||
private readonly List<Hand> _hands = new List<Hand>();
|
||||
|
||||
[ViewVariables] public IReadOnlyList<Hand> Hands => _hands;
|
||||
|
||||
64
Content.Client/UserInterface/StrippingMenu.cs
Normal file
64
Content.Client/UserInterface/StrippingMenu.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using Content.Client.UserInterface.Stylesheets;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.UserInterface
|
||||
{
|
||||
public class StrippingMenu : SS14Window
|
||||
{
|
||||
protected override Vector2? CustomSize => new Vector2(400, 600);
|
||||
|
||||
private readonly VBoxContainer _vboxContainer;
|
||||
|
||||
public StrippingMenu(string title)
|
||||
{
|
||||
Title = title;
|
||||
|
||||
_vboxContainer = new VBoxContainer()
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SeparationOverride = 5,
|
||||
};
|
||||
|
||||
Contents.AddChild(_vboxContainer);
|
||||
}
|
||||
|
||||
public void ClearButtons()
|
||||
{
|
||||
_vboxContainer.DisposeAllChildren();
|
||||
}
|
||||
|
||||
public void AddButton(string title, string name, Action<BaseButton.ButtonEventArgs> onPressed)
|
||||
{
|
||||
var button = new Button()
|
||||
{
|
||||
Text = name,
|
||||
StyleClasses = { StyleBase.ButtonOpenRight }
|
||||
};
|
||||
|
||||
button.OnPressed += onPressed;
|
||||
|
||||
_vboxContainer.AddChild(new HBoxContainer()
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SeparationOverride = 5,
|
||||
Children =
|
||||
{
|
||||
new Label()
|
||||
{
|
||||
Text = $"{title}:"
|
||||
},
|
||||
new Control()
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand
|
||||
},
|
||||
button,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
private string? _activeHand;
|
||||
private uint _nextHand;
|
||||
|
||||
public event Action? OnItemChanged;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? ActiveHand
|
||||
{
|
||||
@@ -60,6 +62,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
[ViewVariables] private readonly List<Hand> _hands = new List<Hand>();
|
||||
|
||||
public IEnumerable<string> Hands => _hands.Select(h => h.Name);
|
||||
|
||||
// Mostly arbitrary.
|
||||
public const float PickupRange = 2;
|
||||
|
||||
@@ -105,6 +109,12 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
return GetHand(handName)?.Entity?.GetComponent<ItemComponent>();
|
||||
}
|
||||
|
||||
public bool TryGetItem(string handName, [MaybeNullWhen(false)] out ItemComponent item)
|
||||
{
|
||||
item = GetItem(handName);
|
||||
return item != null;
|
||||
}
|
||||
|
||||
public ItemComponent? GetActiveHand => ActiveHand == null
|
||||
? null
|
||||
: GetItem(ActiveHand);
|
||||
@@ -136,6 +146,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
{
|
||||
if (PutInHand(item, hand, false))
|
||||
{
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -156,6 +168,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
if (success)
|
||||
{
|
||||
item.Owner.Transform.LocalPosition = Vector2.Zero;
|
||||
OnItemChanged?.Invoke();
|
||||
}
|
||||
|
||||
_entitySystemManager.GetEntitySystem<InteractionSystem>().HandSelectedInteraction(Owner, item.Owner);
|
||||
@@ -250,6 +263,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
container.Insert(item.Owner);
|
||||
}
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
return true;
|
||||
}
|
||||
@@ -300,6 +315,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
container.Insert(item.Owner);
|
||||
}
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
return true;
|
||||
}
|
||||
@@ -364,6 +381,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
return true;
|
||||
}
|
||||
@@ -415,6 +434,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
ActiveHand ??= name;
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
}
|
||||
|
||||
@@ -435,6 +456,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
_activeHand = _hands.FirstOrDefault()?.Name;
|
||||
}
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
}
|
||||
|
||||
@@ -645,7 +668,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
Dirty();
|
||||
|
||||
if (!message.Entity.TryGetComponent(out IPhysicsComponent physics))
|
||||
if (!message.Entity.TryGetComponent(out ICollidableComponent physics))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,9 +33,13 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
#pragma warning restore 649
|
||||
|
||||
[ViewVariables]
|
||||
private readonly Dictionary<Slots, ContainerSlot> SlotContainers = new Dictionary<Slots, ContainerSlot>();
|
||||
private readonly Dictionary<Slots, ContainerSlot> _slotContainers = new Dictionary<Slots, ContainerSlot>();
|
||||
|
||||
private KeyValuePair<Slots, (EntityUid entity, bool fits)>? HoverEntity;
|
||||
private KeyValuePair<Slots, (EntityUid entity, bool fits)>? _hoverEntity;
|
||||
|
||||
public IEnumerable<Slots> Slots => _slotContainers.Keys;
|
||||
|
||||
public event Action OnItemChanged;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -43,7 +47,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
foreach (var slotName in InventoryInstance.SlotMasks)
|
||||
{
|
||||
if (slotName != Slots.NONE)
|
||||
if (slotName != EquipmentSlotDefines.Slots.NONE)
|
||||
{
|
||||
AddSlot(slotName);
|
||||
}
|
||||
@@ -58,7 +62,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
{
|
||||
var multiplier = 1f;
|
||||
|
||||
foreach (var (slot, containerSlot) in SlotContainers)
|
||||
foreach (var (slot, containerSlot) in _slotContainers)
|
||||
{
|
||||
foreach (var entity in containerSlot.ContainedEntities)
|
||||
{
|
||||
@@ -81,7 +85,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
{
|
||||
var multiplier = 1f;
|
||||
|
||||
foreach (var (slot, containerSlot) in SlotContainers)
|
||||
foreach (var (slot, containerSlot) in _slotContainers)
|
||||
{
|
||||
foreach (var entity in containerSlot.ContainedEntities)
|
||||
{
|
||||
@@ -99,7 +103,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
bool IEffectBlocker.CanSlip()
|
||||
{
|
||||
if(Owner.TryGetComponent(out InventoryComponent inventoryComponent) &&
|
||||
inventoryComponent.TryGetSlotItem(Slots.SHOES, out ItemComponent shoes)
|
||||
inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.SHOES, out ItemComponent shoes)
|
||||
)
|
||||
{
|
||||
return EffectBlockerSystem.CanSlip(shoes.Owner);
|
||||
@@ -110,7 +114,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
var slots = SlotContainers.Keys.ToList();
|
||||
var slots = _slotContainers.Keys.ToList();
|
||||
foreach (var slot in slots)
|
||||
{
|
||||
RemoveSlot(slot);
|
||||
@@ -140,15 +144,15 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
}
|
||||
public T GetSlotItem<T>(Slots slot) where T : ItemComponent
|
||||
{
|
||||
if (!SlotContainers.ContainsKey(slot))
|
||||
if (!_slotContainers.ContainsKey(slot))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var containedEntity = SlotContainers[slot].ContainedEntity;
|
||||
var containedEntity = _slotContainers[slot].ContainedEntity;
|
||||
if (containedEntity?.Deleted == true)
|
||||
{
|
||||
SlotContainers[slot] = null;
|
||||
_slotContainers[slot] = null;
|
||||
containedEntity = null;
|
||||
Dirty();
|
||||
}
|
||||
@@ -169,7 +173,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
/// </remarks>
|
||||
/// <param name="slot">The slot to put the item in.</param>
|
||||
/// <param name="item">The item to insert into the slot.</param>
|
||||
/// <param name="reason">The translated reason why the item cannot be equiped, if this function returns false. Can be null.</param>
|
||||
/// <param name="reason">The translated reason why the item cannot be equipped, if this function returns false. Can be null.</param>
|
||||
/// <returns>True if the item was successfully inserted, false otherwise.</returns>
|
||||
public bool Equip(Slots slot, ItemComponent item, out string reason)
|
||||
{
|
||||
@@ -184,7 +188,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
return false;
|
||||
}
|
||||
|
||||
var inventorySlot = SlotContainers[slot];
|
||||
var inventorySlot = _slotContainers[slot];
|
||||
if (!inventorySlot.Insert(item.Owner))
|
||||
{
|
||||
return false;
|
||||
@@ -192,6 +196,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
_entitySystemManager.GetEntitySystem<InteractionSystem>().EquippedInteraction(Owner, item.Owner, slot);
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
|
||||
return true;
|
||||
@@ -239,7 +245,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
reason = Loc.GetString("You can't equip this!");
|
||||
}
|
||||
|
||||
return pass && SlotContainers[slot].CanInsert(item.Owner);
|
||||
return pass && _slotContainers[slot].CanInsert(item.Owner);
|
||||
}
|
||||
|
||||
public bool CanEquip(Slots slot, ItemComponent item) => CanEquip(slot, item, out var _);
|
||||
@@ -258,7 +264,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
return false;
|
||||
}
|
||||
|
||||
var inventorySlot = SlotContainers[slot];
|
||||
var inventorySlot = _slotContainers[slot];
|
||||
var item = inventorySlot.ContainedEntity.GetComponent<ItemComponent>();
|
||||
if (!inventorySlot.Remove(inventorySlot.ContainedEntity))
|
||||
{
|
||||
@@ -271,6 +277,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
_entitySystemManager.GetEntitySystem<InteractionSystem>().UnequippedInteraction(Owner, item.Owner, slot);
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
|
||||
return true;
|
||||
@@ -288,7 +296,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
if (!ActionBlockerSystem.CanUnequip(Owner))
|
||||
return false;
|
||||
|
||||
var InventorySlot = SlotContainers[slot];
|
||||
var InventorySlot = _slotContainers[slot];
|
||||
return InventorySlot.ContainedEntity != null && InventorySlot.CanRemove(InventorySlot.ContainedEntity);
|
||||
}
|
||||
|
||||
@@ -307,7 +315,12 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
}
|
||||
|
||||
Dirty();
|
||||
return SlotContainers[slot] = ContainerManagerComponent.Create<ContainerSlot>(GetSlotString(slot), Owner);
|
||||
|
||||
_slotContainers[slot] = ContainerManagerComponent.Create<ContainerSlot>(GetSlotString(slot), Owner);
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
return _slotContainers[slot];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -331,7 +344,10 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
"Unable to remove slot as the contained clothing could not be dropped");
|
||||
}
|
||||
|
||||
SlotContainers.Remove(slot);
|
||||
_slotContainers.Remove(slot);
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
}
|
||||
|
||||
@@ -342,7 +358,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
/// <returns>True if the slot exists, false otherwise.</returns>
|
||||
public bool HasSlot(Slots slot)
|
||||
{
|
||||
return SlotContainers.ContainsKey(slot);
|
||||
return _slotContainers.ContainsKey(slot);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -354,7 +370,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
// make sure this is one of our containers.
|
||||
// Technically the correct way would be to enumerate the possible slot names
|
||||
// comparing with this container, but I might as well put the dictionary to good use.
|
||||
if (!(container is ContainerSlot slot) || !SlotContainers.ContainsValue(slot))
|
||||
if (!(container is ContainerSlot slot) || !_slotContainers.ContainsValue(slot))
|
||||
return;
|
||||
|
||||
if (entity.TryGetComponent(out ItemComponent itemComp))
|
||||
@@ -362,6 +378,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
itemComp.RemovedFromSlot();
|
||||
}
|
||||
|
||||
OnItemChanged?.Invoke();
|
||||
|
||||
Dirty();
|
||||
}
|
||||
|
||||
@@ -417,7 +435,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
if (activeHand != null && GetSlotItem(msg.Inventoryslot) == null)
|
||||
{
|
||||
var canEquip = CanEquip(msg.Inventoryslot, activeHand, out var reason);
|
||||
HoverEntity = new KeyValuePair<Slots, (EntityUid entity, bool fits)>(msg.Inventoryslot, (activeHand.Owner.Uid, canEquip));
|
||||
_hoverEntity = new KeyValuePair<Slots, (EntityUid entity, bool fits)>(msg.Inventoryslot, (activeHand.Owner.Uid, canEquip));
|
||||
|
||||
Dirty();
|
||||
}
|
||||
@@ -476,7 +494,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
var list = new List<KeyValuePair<Slots, EntityUid>>();
|
||||
foreach (var (slot, container) in SlotContainers)
|
||||
foreach (var (slot, container) in _slotContainers)
|
||||
{
|
||||
if (container.ContainedEntity != null)
|
||||
{
|
||||
@@ -484,8 +502,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
}
|
||||
}
|
||||
|
||||
var hover = HoverEntity;
|
||||
HoverEntity = null;
|
||||
var hover = _hoverEntity;
|
||||
_hoverEntity = null;
|
||||
|
||||
return new InventoryComponentState(list, hover);
|
||||
}
|
||||
@@ -497,7 +515,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var slot in SlotContainers.Values.ToList())
|
||||
foreach (var slot in _slotContainers.Values.ToList())
|
||||
{
|
||||
foreach (var entity in slot.ContainedEntities)
|
||||
{
|
||||
|
||||
372
Content.Server/GameObjects/Components/GUI/StrippableComponent.cs
Normal file
372
Content.Server/GameObjects/Components/GUI/StrippableComponent.cs
Normal file
@@ -0,0 +1,372 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.EntitySystems.DoAfter;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.GameObjects.Components.GUI;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects.Components.UserInterface;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.GUI
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class StrippableComponent : SharedStrippableComponent, IDragDrop
|
||||
{
|
||||
[Dependency] private IServerNotifyManager _notifyManager = default!;
|
||||
|
||||
public const float StripDelay = 2f;
|
||||
|
||||
[ViewVariables]
|
||||
private BoundUserInterface _userInterface;
|
||||
|
||||
private InventoryComponent _inventoryComponent;
|
||||
private HandsComponent _handsComponent;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>().GetBoundUserInterface(StrippingUiKey.Key);
|
||||
_userInterface.OnReceiveMessage += HandleUserInterfaceMessage;
|
||||
|
||||
_inventoryComponent = Owner.GetComponent<InventoryComponent>();
|
||||
_handsComponent = Owner.GetComponent<HandsComponent>();
|
||||
|
||||
_inventoryComponent.OnItemChanged += UpdateSubscribed;
|
||||
|
||||
// Initial update.
|
||||
UpdateSubscribed();
|
||||
}
|
||||
|
||||
private void UpdateSubscribed()
|
||||
{
|
||||
var inventory = GetInventorySlots();
|
||||
var hands = GetHandSlots();
|
||||
|
||||
_userInterface.SetState(new StrippingBoundUserInterfaceState(inventory, hands));
|
||||
}
|
||||
|
||||
public bool CanDragDrop(DragDropEventArgs eventArgs)
|
||||
{
|
||||
return eventArgs.User.HasComponent<HandsComponent>()
|
||||
&& eventArgs.Target != eventArgs.Dropped && eventArgs.Target == eventArgs.User;
|
||||
}
|
||||
|
||||
public bool DragDrop(DragDropEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) return false;
|
||||
|
||||
OpenUserInterface(actor.playerSession);
|
||||
return true;
|
||||
}
|
||||
|
||||
private Dictionary<Slots, string> GetInventorySlots()
|
||||
{
|
||||
var dictionary = new Dictionary<Slots, string>();
|
||||
|
||||
foreach (var slot in _inventoryComponent.Slots)
|
||||
{
|
||||
dictionary[slot] = _inventoryComponent.GetSlotItem(slot)?.Owner.Name ?? "None";
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
private Dictionary<string, string> GetHandSlots()
|
||||
{
|
||||
var dictionary = new Dictionary<string, string>();
|
||||
|
||||
foreach (var hand in _handsComponent.Hands)
|
||||
{
|
||||
dictionary[hand] = _handsComponent.GetItem(hand)?.Owner.Name ?? "None";
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
private void OpenUserInterface(IPlayerSession session)
|
||||
{
|
||||
_userInterface.Open(session);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Places item in user's active hand to an inventory slot.
|
||||
/// </summary>
|
||||
private async void PlaceActiveHandItemInInventory(IEntity user, Slots slot)
|
||||
{
|
||||
var inventory = Owner.GetComponent<InventoryComponent>();
|
||||
var userHands = user.GetComponent<HandsComponent>();
|
||||
var item = userHands.GetActiveHand;
|
||||
|
||||
bool Check()
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
return false;
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("You aren't holding anything!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!userHands.CanDrop(userHands.ActiveHand!))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("You can't drop that!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inventory.HasSlot(slot))
|
||||
return false;
|
||||
|
||||
if (inventory.TryGetSlotItem(slot, out ItemComponent _))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("{0:They} already {0:have} something there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inventory.CanEquip(slot, item))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("{0:They} cannot equip that there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
||||
|
||||
var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
|
||||
{
|
||||
ExtraCheck = Check,
|
||||
BreakOnStun = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
NeedHand = true,
|
||||
};
|
||||
|
||||
var result = await doAfterSystem.DoAfter(doAfterArgs);
|
||||
if (result != DoAfterStatus.Finished) return;
|
||||
|
||||
userHands.Drop(item!.Owner, false);
|
||||
inventory.Equip(slot, item!.Owner);
|
||||
|
||||
UpdateSubscribed();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Places item in user's active hand in one of the entity's hands.
|
||||
/// </summary>
|
||||
private async void PlaceActiveHandItemInHands(IEntity user, string hand)
|
||||
{
|
||||
var hands = Owner.GetComponent<HandsComponent>();
|
||||
var userHands = user.GetComponent<HandsComponent>();
|
||||
var item = userHands.GetActiveHand;
|
||||
|
||||
bool Check()
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
return false;
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("You aren't holding anything!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!userHands.CanDrop(userHands.ActiveHand!))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("You can't drop that!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hands.HasHand(hand))
|
||||
return false;
|
||||
|
||||
if (hands.TryGetItem(hand, out var _))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("{0:They} already {0:have} something there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hands.CanPutInHand(item, hand))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("{0:They} cannot put that there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
||||
|
||||
var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
|
||||
{
|
||||
ExtraCheck = Check,
|
||||
BreakOnStun = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
NeedHand = true,
|
||||
};
|
||||
|
||||
var result = await doAfterSystem.DoAfter(doAfterArgs);
|
||||
if (result != DoAfterStatus.Finished) return;
|
||||
|
||||
userHands.Drop(hand, false);
|
||||
hands.PutInHand(item, hand, false);
|
||||
UpdateSubscribed();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an item from the inventory and places it in the user's active hand.
|
||||
/// </summary>
|
||||
private async void TakeItemFromInventory(IEntity user, Slots slot)
|
||||
{
|
||||
var inventory = Owner.GetComponent<InventoryComponent>();
|
||||
var userHands = user.GetComponent<HandsComponent>();
|
||||
|
||||
bool Check()
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
return false;
|
||||
|
||||
if (!inventory.HasSlot(slot))
|
||||
return false;
|
||||
|
||||
if (!inventory.TryGetSlotItem(slot, out ItemComponent itemToTake))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("{0:They} {0:have} nothing there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inventory.CanUnequip(slot))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("{0:They} cannot unequip that!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
||||
|
||||
var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
|
||||
{
|
||||
ExtraCheck = Check,
|
||||
BreakOnStun = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
};
|
||||
|
||||
var result = await doAfterSystem.DoAfter(doAfterArgs);
|
||||
if (result != DoAfterStatus.Finished) return;
|
||||
|
||||
var item = inventory.GetSlotItem(slot);
|
||||
inventory.Unequip(slot);
|
||||
userHands.PutInHandOrDrop(item);
|
||||
UpdateSubscribed();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes an item from a hand and places it in the user's active hand.
|
||||
/// </summary>
|
||||
private async void TakeItemFromHands(IEntity user, string hand)
|
||||
{
|
||||
var hands = Owner.GetComponent<HandsComponent>();
|
||||
var userHands = user.GetComponent<HandsComponent>();
|
||||
|
||||
bool Check()
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
return false;
|
||||
|
||||
if (!hands.HasHand(hand))
|
||||
return false;
|
||||
|
||||
if (!hands.TryGetItem(hand, out var heldItem))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("{0:They} {0:have} nothing there!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hands.CanDrop(hand))
|
||||
{
|
||||
_notifyManager.PopupMessageCursor(user, Loc.GetString("{0:They} cannot drop that!", Owner));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
||||
|
||||
var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
|
||||
{
|
||||
ExtraCheck = Check,
|
||||
BreakOnStun = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnUserMove = true,
|
||||
};
|
||||
|
||||
var result = await doAfterSystem.DoAfter(doAfterArgs);
|
||||
if (result != DoAfterStatus.Finished) return;
|
||||
|
||||
var item = hands.GetItem(hand);
|
||||
hands.Drop(hand, false);
|
||||
userHands.PutInHandOrDrop(item);
|
||||
UpdateSubscribed();
|
||||
}
|
||||
|
||||
private void HandleUserInterfaceMessage(ServerBoundUserInterfaceMessage obj)
|
||||
{
|
||||
var user = obj.Session.AttachedEntity;
|
||||
if (user == null || !(user.TryGetComponent(out HandsComponent userHands))) return;
|
||||
|
||||
var placingItem = userHands.GetActiveHand != null;
|
||||
|
||||
switch (obj.Message)
|
||||
{
|
||||
case StrippingInventoryButtonPressed inventoryMessage:
|
||||
var inventory = Owner.GetComponent<InventoryComponent>();
|
||||
|
||||
if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent _))
|
||||
placingItem = false;
|
||||
|
||||
if(placingItem)
|
||||
PlaceActiveHandItemInInventory(user, inventoryMessage.Slot);
|
||||
else
|
||||
TakeItemFromInventory(user, inventoryMessage.Slot);
|
||||
break;
|
||||
case StrippingHandButtonPressed handMessage:
|
||||
var hands = Owner.GetComponent<HandsComponent>();
|
||||
|
||||
if (hands.TryGetItem(handMessage.Hand, out _))
|
||||
placingItem = false;
|
||||
|
||||
if(placingItem)
|
||||
PlaceActiveHandItemInHands(user, handMessage.Hand);
|
||||
else
|
||||
TakeItemFromHands(user, handMessage.Hand);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,12 +132,12 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
if (!HasMind)
|
||||
{
|
||||
message.AddMarkup(!dead
|
||||
? $"[color=red]" + Loc.GetString("{0:They} are totally catatonic. The stresses of life in deep-space must have been too much for {0:them}. Any recovery is unlikely.", Owner) + "[/color]"
|
||||
? $"[color=red]" + Loc.GetString("{0:They} {0:are} totally catatonic. The stresses of life in deep-space must have been too much for {0:them}. Any recovery is unlikely.", Owner) + "[/color]"
|
||||
: $"[color=purple]" + Loc.GetString("{0:Their} soul has departed.", Owner) + "[/color]");
|
||||
}
|
||||
else if (Mind?.Session == null)
|
||||
{
|
||||
message.AddMarkup("[color=yellow]" + Loc.GetString("{0:They} have a blank, absent-minded stare and appears completely unresponsive to anything. {0:They} may snap out of it soon.", Owner) + "[/color]");
|
||||
message.AddMarkup("[color=yellow]" + Loc.GetString("{0:They} {0:have} a blank, absent-minded stare and appears completely unresponsive to anything. {0:They} may snap out of it soon.", Owner) + "[/color]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
@@ -12,10 +17,20 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
|
||||
{
|
||||
public interface IHandsComponent : ISharedHandsComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked when the hand contents changes or when a hand is added/removed.
|
||||
/// </summary>
|
||||
event Action? OnItemChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The hands in this component.
|
||||
/// </summary>
|
||||
IEnumerable<string> Hands { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The hand name of the currently active hand.
|
||||
/// </summary>
|
||||
string ActiveHand { get; set; }
|
||||
string? ActiveHand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Enumerates over every held item.
|
||||
@@ -27,12 +42,20 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
|
||||
/// </summary>
|
||||
/// <param name="handName">The name of the hand to get.</param>
|
||||
/// <returns>The item in the held, null if no item is held</returns>
|
||||
ItemComponent GetItem(string handName);
|
||||
ItemComponent? GetItem(string handName);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get an item in a hand.
|
||||
/// </summary>
|
||||
/// <param name="handName">The name of the hand to get.</param>
|
||||
/// <param name="item">The item in the held, null if no item is held</param>
|
||||
/// <returns>Whether it was holding an item</returns>
|
||||
bool TryGetItem(string handName, [MaybeNullWhen(false)] out ItemComponent item);
|
||||
|
||||
/// <summary>
|
||||
/// Gets item held by the current active hand
|
||||
/// </summary>
|
||||
ItemComponent GetActiveHand { get; }
|
||||
ItemComponent? GetActiveHand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Puts an item into any empty hand, preferring the active hand.
|
||||
@@ -78,7 +101,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Items
|
||||
/// <returns>
|
||||
/// true if the entity is held, false otherwise
|
||||
/// </returns>
|
||||
bool TryHand(IEntity entity, out string handName);
|
||||
bool TryHand(IEntity entity, [MaybeNullWhen(false)] out string handName);
|
||||
|
||||
/// <summary>
|
||||
/// Drops the item contained in the slot to the same position as our entity.
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.Serialization;
|
||||
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.GUI
|
||||
{
|
||||
public class SharedStrippableComponent : Component
|
||||
{
|
||||
public override string Name => "Strippable";
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public enum StrippingUiKey
|
||||
{
|
||||
Key,
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class StrippingInventoryButtonPressed : BoundUserInterfaceMessage
|
||||
{
|
||||
public Slots Slot { get; }
|
||||
|
||||
public StrippingInventoryButtonPressed(Slots slot)
|
||||
{
|
||||
Slot = slot;
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class StrippingHandButtonPressed : BoundUserInterfaceMessage
|
||||
{
|
||||
public string Hand { get; }
|
||||
|
||||
public StrippingHandButtonPressed(string hand)
|
||||
{
|
||||
Hand = hand;
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class StrippingBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public Dictionary<Slots, string> Inventory { get; }
|
||||
public Dictionary<string, string> Hands { get; }
|
||||
|
||||
public StrippingBoundUserInterfaceState(Dictionary<Slots, string> inventory, Dictionary<string, string> hands)
|
||||
{
|
||||
Inventory = inventory;
|
||||
Hands = hands;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,6 +144,12 @@
|
||||
- type: Pullable
|
||||
- type: CanSeeGases
|
||||
- type: DoAfter
|
||||
- type: Strippable
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.StrippingUiKey.Key
|
||||
type: StrippableBoundUserInterface
|
||||
|
||||
|
||||
- type: entity
|
||||
save: false
|
||||
|
||||
@@ -71,10 +71,12 @@
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Soundfont/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=soundfonts/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Spawner/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Strippable/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=stunnable/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=superconduction/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=swsl/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=underplating/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=unequip/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=unexcite/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=uplink/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Wirecutter/@EntryIndexedValue">True</s:Boolean>
|
||||
|
||||
Reference in New Issue
Block a user