HandsSystem Refactor (#38438)
* checkpoint * pt 2 * pt... i forgot * pt 4 * patch * More test fixes * optimization!!! * the REAL hand system * fix RetractableItemActionSystem.cs oversight * the review * test * remove test usage of body prototype * Update Content.IntegrationTests/Tests/Interaction/InteractionTest.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * hellcode * hellcode 2 * Minor cleanup * test * Chasing the last of the bugs * changes --------- Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
This commit is contained in:
@@ -16,7 +16,6 @@ using Robust.Client.UserInterface;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Hands.Systems
|
||||
@@ -27,16 +26,13 @@ namespace Content.Client.Hands.Systems
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IUserInterfaceManager _ui = default!;
|
||||
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly StrippableSystem _stripSys = default!;
|
||||
[Dependency] private readonly SpriteSystem _sprite = default!;
|
||||
[Dependency] private readonly ExamineSystem _examine = default!;
|
||||
[Dependency] private readonly DisplacementMapSystem _displacement = default!;
|
||||
|
||||
public event Action<string, HandLocation>? OnPlayerAddHand;
|
||||
public event Action<string>? OnPlayerRemoveHand;
|
||||
public event Action<string?>? OnPlayerSetActiveHand;
|
||||
public event Action<HandsComponent>? OnPlayerHandsAdded;
|
||||
public event Action<Entity<HandsComponent>>? OnPlayerHandsAdded;
|
||||
public event Action? OnPlayerHandsRemoved;
|
||||
public event Action<string, EntityUid>? OnPlayerItemAdded;
|
||||
public event Action<string, EntityUid>? OnPlayerItemRemoved;
|
||||
@@ -58,67 +54,28 @@ namespace Content.Client.Hands.Systems
|
||||
}
|
||||
|
||||
#region StateHandling
|
||||
private void HandleComponentState(EntityUid uid, HandsComponent component, ref ComponentHandleState args)
|
||||
private void HandleComponentState(Entity<HandsComponent> ent, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not HandsComponentState state)
|
||||
return;
|
||||
|
||||
var handsModified = component.Hands.Count != state.Hands.Count;
|
||||
// we need to check that, even if we have the same amount, that the individual hands didn't change.
|
||||
if (!handsModified)
|
||||
var newHands = state.Hands.Keys.Except(ent.Comp.Hands.Keys); // hands that were added between states
|
||||
var oldHands = ent.Comp.Hands.Keys.Except(state.Hands.Keys); // hands that were removed between states
|
||||
|
||||
foreach (var handId in oldHands)
|
||||
{
|
||||
foreach (var hand in component.Hands.Values)
|
||||
{
|
||||
if (state.Hands.Contains(hand))
|
||||
continue;
|
||||
handsModified = true;
|
||||
break;
|
||||
}
|
||||
RemoveHand(ent.AsNullable(), handId);
|
||||
}
|
||||
|
||||
var manager = EnsureComp<ContainerManagerComponent>(uid);
|
||||
|
||||
if (handsModified)
|
||||
foreach (var handId in state.SortedHands.Intersect(newHands))
|
||||
{
|
||||
List<Hand> addedHands = new();
|
||||
foreach (var hand in state.Hands)
|
||||
{
|
||||
if (component.Hands.ContainsKey(hand.Name))
|
||||
continue;
|
||||
|
||||
var container = _containerSystem.EnsureContainer<ContainerSlot>(uid, hand.Name, manager);
|
||||
var newHand = new Hand(hand.Name, hand.Location, container);
|
||||
component.Hands.Add(hand.Name, newHand);
|
||||
addedHands.Add(newHand);
|
||||
}
|
||||
|
||||
foreach (var name in component.Hands.Keys)
|
||||
{
|
||||
if (!state.HandNames.Contains(name))
|
||||
{
|
||||
RemoveHand(uid, name, component);
|
||||
}
|
||||
}
|
||||
|
||||
component.SortedHands.Clear();
|
||||
component.SortedHands.AddRange(state.HandNames);
|
||||
var sorted = addedHands.OrderBy(hand => component.SortedHands.IndexOf(hand.Name));
|
||||
|
||||
foreach (var hand in sorted)
|
||||
{
|
||||
AddHand(uid, hand, component);
|
||||
}
|
||||
AddHand(ent.AsNullable(), handId, state.Hands[handId]);
|
||||
}
|
||||
ent.Comp.SortedHands = new (state.SortedHands);
|
||||
|
||||
_stripSys.UpdateUi(uid);
|
||||
SetActiveHand(ent.AsNullable(), state.ActiveHandId);
|
||||
|
||||
if (component.ActiveHand == null && state.ActiveHand == null)
|
||||
return; //edge case
|
||||
|
||||
if (component.ActiveHand != null && state.ActiveHand != component.ActiveHand.Name)
|
||||
{
|
||||
SetActiveHand(uid, component.Hands[state.ActiveHand!], component);
|
||||
}
|
||||
_stripSys.UpdateUi(ent);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -129,47 +86,52 @@ namespace Content.Client.Hands.Systems
|
||||
return;
|
||||
}
|
||||
|
||||
OnPlayerHandsAdded?.Invoke(hands);
|
||||
OnPlayerHandsAdded?.Invoke(hands.Value);
|
||||
}
|
||||
|
||||
public override void DoDrop(EntityUid uid, Hand hand, bool doDropInteraction = true, HandsComponent? hands = null, bool log = true)
|
||||
public override void DoDrop(Entity<HandsComponent?> ent,
|
||||
string handId,
|
||||
bool doDropInteraction = true,
|
||||
bool log = true)
|
||||
{
|
||||
base.DoDrop(uid, hand, doDropInteraction, hands, log);
|
||||
base.DoDrop(ent, handId, doDropInteraction, log);
|
||||
|
||||
if (TryComp(hand.HeldEntity, out SpriteComponent? sprite))
|
||||
if (TryGetHeldItem(ent, handId, out var held) && TryComp(held, out SpriteComponent? sprite))
|
||||
sprite.RenderOrder = EntityManager.CurrentTick.Value;
|
||||
}
|
||||
|
||||
public EntityUid? GetActiveHandEntity()
|
||||
{
|
||||
return TryGetPlayerHands(out var hands) ? hands.ActiveHandEntity : null;
|
||||
return TryGetPlayerHands(out var hands) ? GetActiveItem(hands.Value.AsNullable()) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the hands component of the local player
|
||||
/// </summary>
|
||||
public bool TryGetPlayerHands([NotNullWhen(true)] out HandsComponent? hands)
|
||||
public bool TryGetPlayerHands([NotNullWhen(true)] out Entity<HandsComponent>? hands)
|
||||
{
|
||||
var player = _playerManager.LocalEntity;
|
||||
hands = null;
|
||||
return player != null && TryComp(player.Value, out hands);
|
||||
if (player == null || !TryComp<HandsComponent>(player.Value, out var handsComp))
|
||||
return false;
|
||||
|
||||
hands = (player.Value, handsComp);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when a user clicked on their hands GUI
|
||||
/// </summary>
|
||||
public void UIHandClick(HandsComponent hands, string handName)
|
||||
public void UIHandClick(Entity<HandsComponent> ent, string handName)
|
||||
{
|
||||
if (!hands.Hands.TryGetValue(handName, out var pressedHand))
|
||||
var hands = ent.Comp;
|
||||
if (hands.ActiveHandId == null)
|
||||
return;
|
||||
|
||||
if (hands.ActiveHand == null)
|
||||
return;
|
||||
var pressedEntity = GetHeldItem(ent.AsNullable(), handName);
|
||||
var activeEntity = GetActiveItem(ent.AsNullable());
|
||||
|
||||
var pressedEntity = pressedHand.HeldEntity;
|
||||
var activeEntity = hands.ActiveHand.HeldEntity;
|
||||
|
||||
if (pressedHand == hands.ActiveHand && activeEntity != null)
|
||||
if (handName == hands.ActiveHandId && activeEntity != null)
|
||||
{
|
||||
// use item in hand
|
||||
// it will always be attack_self() in my heart.
|
||||
@@ -177,24 +139,24 @@ namespace Content.Client.Hands.Systems
|
||||
return;
|
||||
}
|
||||
|
||||
if (pressedHand != hands.ActiveHand && pressedEntity == null)
|
||||
if (handName != hands.ActiveHandId && pressedEntity == null)
|
||||
{
|
||||
// change active hand
|
||||
EntityManager.RaisePredictiveEvent(new RequestSetHandEvent(handName));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pressedHand != hands.ActiveHand && pressedEntity != null && activeEntity != null)
|
||||
if (handName != hands.ActiveHandId && pressedEntity != null && activeEntity != null)
|
||||
{
|
||||
// use active item on held item
|
||||
EntityManager.RaisePredictiveEvent(new RequestHandInteractUsingEvent(pressedHand.Name));
|
||||
EntityManager.RaisePredictiveEvent(new RequestHandInteractUsingEvent(handName));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pressedHand != hands.ActiveHand && pressedEntity != null && activeEntity == null)
|
||||
if (handName != hands.ActiveHandId && pressedEntity != null && activeEntity == null)
|
||||
{
|
||||
// move the item to the active hand
|
||||
EntityManager.RaisePredictiveEvent(new RequestMoveHandItemEvent(pressedHand.Name));
|
||||
EntityManager.RaisePredictiveEvent(new RequestMoveHandItemEvent(handName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,13 +172,12 @@ namespace Content.Client.Hands.Systems
|
||||
public void UIInventoryExamine(string handName)
|
||||
{
|
||||
if (!TryGetPlayerHands(out var hands) ||
|
||||
!hands.Hands.TryGetValue(handName, out var hand) ||
|
||||
hand.HeldEntity is not { Valid: true } entity)
|
||||
!TryGetHeldItem(hands.Value.AsNullable(), handName, out var heldEntity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_examine.DoExamine(entity);
|
||||
_examine.DoExamine(heldEntity.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -226,13 +187,12 @@ namespace Content.Client.Hands.Systems
|
||||
public void UIHandOpenContextMenu(string handName)
|
||||
{
|
||||
if (!TryGetPlayerHands(out var hands) ||
|
||||
!hands.Hands.TryGetValue(handName, out var hand) ||
|
||||
hand.HeldEntity is not { Valid: true } entity)
|
||||
!TryGetHeldItem(hands.Value.AsNullable(), handName, out var heldEntity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_ui.GetUIController<VerbMenuUIController>().OpenVerbMenu(entity);
|
||||
_ui.GetUIController<VerbMenuUIController>().OpenVerbMenu(heldEntity.Value);
|
||||
}
|
||||
|
||||
public void UIHandAltActivateItem(string handName)
|
||||
@@ -246,60 +206,67 @@ namespace Content.Client.Hands.Systems
|
||||
{
|
||||
base.HandleEntityInserted(uid, hands, args);
|
||||
|
||||
if (!hands.Hands.TryGetValue(args.Container.ID, out var hand))
|
||||
if (!hands.Hands.ContainsKey(args.Container.ID))
|
||||
return;
|
||||
UpdateHandVisuals(uid, args.Entity, hand);
|
||||
|
||||
UpdateHandVisuals(uid, args.Entity, args.Container.ID);
|
||||
_stripSys.UpdateUi(uid);
|
||||
|
||||
if (uid != _playerManager.LocalEntity)
|
||||
return;
|
||||
|
||||
OnPlayerItemAdded?.Invoke(hand.Name, args.Entity);
|
||||
OnPlayerItemAdded?.Invoke(args.Container.ID, args.Entity);
|
||||
|
||||
if (HasComp<VirtualItemComponent>(args.Entity))
|
||||
OnPlayerHandBlocked?.Invoke(hand.Name);
|
||||
OnPlayerHandBlocked?.Invoke(args.Container.ID);
|
||||
}
|
||||
|
||||
protected override void HandleEntityRemoved(EntityUid uid, HandsComponent hands, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
base.HandleEntityRemoved(uid, hands, args);
|
||||
|
||||
if (!hands.Hands.TryGetValue(args.Container.ID, out var hand))
|
||||
if (!hands.Hands.ContainsKey(args.Container.ID))
|
||||
return;
|
||||
UpdateHandVisuals(uid, args.Entity, hand);
|
||||
|
||||
UpdateHandVisuals(uid, args.Entity, args.Container.ID);
|
||||
_stripSys.UpdateUi(uid);
|
||||
|
||||
if (uid != _playerManager.LocalEntity)
|
||||
return;
|
||||
|
||||
OnPlayerItemRemoved?.Invoke(hand.Name, args.Entity);
|
||||
OnPlayerItemRemoved?.Invoke(args.Container.ID, args.Entity);
|
||||
|
||||
if (HasComp<VirtualItemComponent>(args.Entity))
|
||||
OnPlayerHandUnblocked?.Invoke(hand.Name);
|
||||
OnPlayerHandUnblocked?.Invoke(args.Container.ID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the players sprite with new in-hand visuals.
|
||||
/// </summary>
|
||||
private void UpdateHandVisuals(EntityUid uid, EntityUid held, Hand hand, HandsComponent? handComp = null, SpriteComponent? sprite = null)
|
||||
private void UpdateHandVisuals(Entity<HandsComponent?, SpriteComponent?> ent, EntityUid held, string handId)
|
||||
{
|
||||
if (!Resolve(uid, ref handComp, ref sprite, false))
|
||||
if (!Resolve(ent, ref ent.Comp1, ref ent.Comp2, false))
|
||||
return;
|
||||
var handComp = ent.Comp1;
|
||||
var sprite = ent.Comp2;
|
||||
|
||||
if (!TryGetHand((ent, handComp), handId, out var hand))
|
||||
return;
|
||||
|
||||
// visual update might involve changes to the entity's effective sprite -> need to update hands GUI.
|
||||
if (uid == _playerManager.LocalEntity)
|
||||
OnPlayerItemAdded?.Invoke(hand.Name, held);
|
||||
if (ent == _playerManager.LocalEntity)
|
||||
OnPlayerItemAdded?.Invoke(handId, held);
|
||||
|
||||
if (!handComp.ShowInHands)
|
||||
return;
|
||||
|
||||
// Remove old layers. We could also just set them to invisible, but as items may add arbitrary layers, this
|
||||
// may eventually bloat the player with lots of layers.
|
||||
if (handComp.RevealedLayers.TryGetValue(hand.Location, out var revealedLayers))
|
||||
if (handComp.RevealedLayers.TryGetValue(hand.Value.Location, out var revealedLayers))
|
||||
{
|
||||
foreach (var key in revealedLayers)
|
||||
{
|
||||
_sprite.RemoveLayer((uid, sprite), key);
|
||||
_sprite.RemoveLayer((ent, sprite), key);
|
||||
}
|
||||
|
||||
revealedLayers.Clear();
|
||||
@@ -307,22 +274,22 @@ namespace Content.Client.Hands.Systems
|
||||
else
|
||||
{
|
||||
revealedLayers = new();
|
||||
handComp.RevealedLayers[hand.Location] = revealedLayers;
|
||||
handComp.RevealedLayers[hand.Value.Location] = revealedLayers;
|
||||
}
|
||||
|
||||
if (hand.HeldEntity == null)
|
||||
if (HandIsEmpty((ent, handComp), handId))
|
||||
{
|
||||
// the held item was removed.
|
||||
RaiseLocalEvent(held, new HeldVisualsUpdatedEvent(uid, revealedLayers), true);
|
||||
RaiseLocalEvent(held, new HeldVisualsUpdatedEvent(ent, revealedLayers), true);
|
||||
return;
|
||||
}
|
||||
|
||||
var ev = new GetInhandVisualsEvent(uid, hand.Location);
|
||||
var ev = new GetInhandVisualsEvent(ent, hand.Value.Location);
|
||||
RaiseLocalEvent(held, ev);
|
||||
|
||||
if (ev.Layers.Count == 0)
|
||||
{
|
||||
RaiseLocalEvent(held, new HeldVisualsUpdatedEvent(uid, revealedLayers), true);
|
||||
RaiseLocalEvent(held, new HeldVisualsUpdatedEvent(ent, revealedLayers), true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -335,7 +302,7 @@ namespace Content.Client.Hands.Systems
|
||||
continue;
|
||||
}
|
||||
|
||||
var index = _sprite.LayerMapReserve((uid, sprite), key);
|
||||
var index = _sprite.LayerMapReserve((ent, sprite), key);
|
||||
|
||||
// In case no RSI is given, use the item's base RSI as a default. This cuts down on a lot of unnecessary yaml entries.
|
||||
if (layerData.RsiPath == null
|
||||
@@ -343,35 +310,34 @@ namespace Content.Client.Hands.Systems
|
||||
&& sprite[index].Rsi == null)
|
||||
{
|
||||
if (TryComp<ItemComponent>(held, out var itemComponent) && itemComponent.RsiPath != null)
|
||||
_sprite.LayerSetRsi((uid, sprite), index, new ResPath(itemComponent.RsiPath));
|
||||
_sprite.LayerSetRsi((ent, sprite), index, new ResPath(itemComponent.RsiPath));
|
||||
else if (TryComp(held, out SpriteComponent? clothingSprite))
|
||||
_sprite.LayerSetRsi((uid, sprite), index, clothingSprite.BaseRSI);
|
||||
_sprite.LayerSetRsi((ent, sprite), index, clothingSprite.BaseRSI);
|
||||
}
|
||||
|
||||
_sprite.LayerSetData((uid, sprite), index, layerData);
|
||||
_sprite.LayerSetData((ent, sprite), index, layerData);
|
||||
|
||||
// Add displacement maps
|
||||
var displacement = hand.Location switch
|
||||
var displacement = hand.Value.Location switch
|
||||
{
|
||||
HandLocation.Left => handComp.LeftHandDisplacement,
|
||||
HandLocation.Right => handComp.RightHandDisplacement,
|
||||
_ => handComp.HandDisplacement
|
||||
};
|
||||
|
||||
if (displacement is not null && _displacement.TryAddDisplacement(displacement, (uid, sprite), index, key, out var displacementKey))
|
||||
if (displacement is not null && _displacement.TryAddDisplacement(displacement, (ent, sprite), index, key, out var displacementKey))
|
||||
revealedLayers.Add(displacementKey);
|
||||
}
|
||||
|
||||
RaiseLocalEvent(held, new HeldVisualsUpdatedEvent(uid, revealedLayers), true);
|
||||
RaiseLocalEvent(held, new HeldVisualsUpdatedEvent(ent, revealedLayers), true);
|
||||
}
|
||||
|
||||
private void OnVisualsChanged(EntityUid uid, HandsComponent component, VisualsChangedEvent args)
|
||||
{
|
||||
// update hands visuals if this item is in a hand (rather then inventory or other container).
|
||||
if (component.Hands.TryGetValue(args.ContainerId, out var hand))
|
||||
{
|
||||
UpdateHandVisuals(uid, GetEntity(args.Item), hand, component);
|
||||
}
|
||||
if (!component.Hands.ContainsKey(args.ContainerId))
|
||||
return;
|
||||
UpdateHandVisuals((uid, component), GetEntity(args.Item), args.ContainerId);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -379,7 +345,7 @@ namespace Content.Client.Hands.Systems
|
||||
|
||||
private void HandlePlayerAttached(EntityUid uid, HandsComponent component, LocalPlayerAttachedEvent args)
|
||||
{
|
||||
OnPlayerHandsAdded?.Invoke(component);
|
||||
OnPlayerHandsAdded?.Invoke((uid, component));
|
||||
}
|
||||
|
||||
private void HandlePlayerDetached(EntityUid uid, HandsComponent component, LocalPlayerDetachedEvent args)
|
||||
@@ -390,7 +356,7 @@ namespace Content.Client.Hands.Systems
|
||||
private void OnHandsStartup(EntityUid uid, HandsComponent component, ComponentStartup args)
|
||||
{
|
||||
if (_playerManager.LocalEntity == uid)
|
||||
OnPlayerHandsAdded?.Invoke(component);
|
||||
OnPlayerHandsAdded?.Invoke((uid, component));
|
||||
}
|
||||
|
||||
private void OnHandsShutdown(EntityUid uid, HandsComponent component, ComponentShutdown args)
|
||||
@@ -400,36 +366,6 @@ namespace Content.Client.Hands.Systems
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void AddHand(EntityUid uid, Hand newHand, HandsComponent? handsComp = null)
|
||||
{
|
||||
AddHand(uid, newHand.Name, newHand.Location, handsComp);
|
||||
}
|
||||
|
||||
public override void AddHand(EntityUid uid, string handName, HandLocation handLocation, HandsComponent? handsComp = null)
|
||||
{
|
||||
base.AddHand(uid, handName, handLocation, handsComp);
|
||||
|
||||
if (uid == _playerManager.LocalEntity)
|
||||
OnPlayerAddHand?.Invoke(handName, handLocation);
|
||||
|
||||
if (handsComp == null)
|
||||
return;
|
||||
|
||||
if (handsComp.ActiveHand == null)
|
||||
SetActiveHand(uid, handsComp.Hands[handName], handsComp);
|
||||
}
|
||||
public override void RemoveHand(EntityUid uid, string handName, HandsComponent? handsComp = null)
|
||||
{
|
||||
if (uid == _playerManager.LocalEntity && handsComp != null &&
|
||||
handsComp.Hands.ContainsKey(handName) && uid ==
|
||||
_playerManager.LocalEntity)
|
||||
{
|
||||
OnPlayerRemoveHand?.Invoke(handName);
|
||||
}
|
||||
|
||||
base.RemoveHand(uid, handName, handsComp);
|
||||
}
|
||||
|
||||
private void OnHandActivated(Entity<HandsComponent>? ent)
|
||||
{
|
||||
if (ent is not { } hand)
|
||||
@@ -438,13 +374,7 @@ namespace Content.Client.Hands.Systems
|
||||
if (_playerManager.LocalEntity != hand.Owner)
|
||||
return;
|
||||
|
||||
if (hand.Comp.ActiveHand == null)
|
||||
{
|
||||
OnPlayerSetActiveHand?.Invoke(null);
|
||||
return;
|
||||
}
|
||||
|
||||
OnPlayerSetActiveHand?.Invoke(hand.Comp.ActiveHand.Name);
|
||||
OnPlayerSetActiveHand?.Invoke(hand.Comp.ActiveHandId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.Examine;
|
||||
using Content.Client.Hands.Systems;
|
||||
using Content.Client.Strip;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
@@ -34,6 +35,7 @@ namespace Content.Client.Inventory
|
||||
[Dependency] private readonly IUserInterfaceManager _ui = default!;
|
||||
|
||||
private readonly ExamineSystem _examine;
|
||||
private readonly HandsSystem _hands;
|
||||
private readonly InventorySystem _inv;
|
||||
private readonly SharedCuffableSystem _cuffable;
|
||||
private readonly StrippableSystem _strippable;
|
||||
@@ -65,6 +67,7 @@ namespace Content.Client.Inventory
|
||||
public StrippableBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||
{
|
||||
_examine = EntMan.System<ExamineSystem>();
|
||||
_hands = EntMan.System<HandsSystem>();
|
||||
_inv = EntMan.System<InventorySystem>();
|
||||
_cuffable = EntMan.System<SharedCuffableSystem>();
|
||||
_strippable = EntMan.System<StrippableSystem>();
|
||||
@@ -120,28 +123,28 @@ namespace Content.Client.Inventory
|
||||
{
|
||||
// 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)
|
||||
foreach (var (id, hand) in handsComp.Hands)
|
||||
{
|
||||
if (hand.Location != HandLocation.Right)
|
||||
continue;
|
||||
|
||||
AddHandButton(hand);
|
||||
AddHandButton((Owner, handsComp), id, hand);
|
||||
}
|
||||
|
||||
foreach (var hand in handsComp.Hands.Values)
|
||||
foreach (var (id, hand) in handsComp.Hands)
|
||||
{
|
||||
if (hand.Location != HandLocation.Middle)
|
||||
continue;
|
||||
|
||||
AddHandButton(hand);
|
||||
AddHandButton((Owner, handsComp), id, hand);
|
||||
}
|
||||
|
||||
foreach (var hand in handsComp.Hands.Values)
|
||||
foreach (var (id, hand) in handsComp.Hands)
|
||||
{
|
||||
if (hand.Location != HandLocation.Left)
|
||||
continue;
|
||||
|
||||
AddHandButton(hand);
|
||||
AddHandButton((Owner, handsComp), id, hand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,20 +180,21 @@ namespace Content.Client.Inventory
|
||||
_strippingMenu.SetSize = new Vector2(horizontalMenuSize, verticalMenuSize);
|
||||
}
|
||||
|
||||
private void AddHandButton(Hand hand)
|
||||
private void AddHandButton(Entity<HandsComponent> ent, string handId, Hand hand)
|
||||
{
|
||||
var button = new HandButton(hand.Name, hand.Location);
|
||||
var button = new HandButton(handId, hand.Location);
|
||||
|
||||
button.Pressed += SlotPressed;
|
||||
|
||||
if (EntMan.TryGetComponent<VirtualItemComponent>(hand.HeldEntity, out var virt))
|
||||
var heldEntity = _hands.GetHeldItem(ent.AsNullable(), handId);
|
||||
if (EntMan.TryGetComponent<VirtualItemComponent>(heldEntity, out var virt))
|
||||
{
|
||||
button.Blocked = true;
|
||||
if (EntMan.TryGetComponent<CuffableComponent>(Owner, out var cuff) && _cuffable.GetAllCuffs(cuff).Contains(virt.BlockingEntity))
|
||||
button.BlockedRect.MouseFilter = MouseFilterMode.Ignore;
|
||||
}
|
||||
|
||||
UpdateEntityIcon(button, hand.HeldEntity);
|
||||
UpdateEntityIcon(button, heldEntity);
|
||||
_strippingMenu!.HandsContainer.AddChild(button);
|
||||
LayoutContainer.SetPosition(button, new Vector2i(_handCount, 0) * (SlotControl.DefaultButtonSize + ButtonSeparation));
|
||||
_handCount++;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Numerics;
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Client.Hands.Systems;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.RCD.Components;
|
||||
@@ -17,6 +18,7 @@ public sealed class AlignRCDConstruction : PlacementMode
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
private readonly SharedMapSystem _mapSystem;
|
||||
private readonly HandsSystem _handsSystem;
|
||||
private readonly RCDSystem _rcdSystem;
|
||||
private readonly SharedTransformSystem _transformSystem;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
@@ -34,6 +36,7 @@ public sealed class AlignRCDConstruction : PlacementMode
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_mapSystem = _entityManager.System<SharedMapSystem>();
|
||||
_handsSystem = _entityManager.System<HandsSystem>();
|
||||
_rcdSystem = _entityManager.System<RCDSystem>();
|
||||
_transformSystem = _entityManager.System<SharedTransformSystem>();
|
||||
|
||||
@@ -88,11 +91,9 @@ public sealed class AlignRCDConstruction : PlacementMode
|
||||
}
|
||||
|
||||
// Determine if player is carrying an RCD in their active hand
|
||||
if (!_entityManager.TryGetComponent<HandsComponent>(player, out var hands))
|
||||
if (!_handsSystem.TryGetActiveItem(player.Value, out var heldEntity))
|
||||
return false;
|
||||
|
||||
var heldEntity = hands.ActiveHand?.HeldEntity;
|
||||
|
||||
if (!_entityManager.TryGetComponent<RCDComponent>(heldEntity, out var rcd))
|
||||
return false;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Client.Hands.Systems;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.RCD;
|
||||
@@ -15,6 +16,7 @@ public sealed class RCDConstructionGhostSystem : EntitySystem
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IPlacementManager _placementManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
||||
[Dependency] private readonly HandsSystem _hands = default!;
|
||||
|
||||
private string _placementMode = typeof(AlignRCDConstruction).Name;
|
||||
private Direction _placementDirection = default;
|
||||
@@ -33,12 +35,11 @@ public sealed class RCDConstructionGhostSystem : EntitySystem
|
||||
return;
|
||||
|
||||
// Determine if player is carrying an RCD in their active hand
|
||||
var player = _playerManager.LocalSession?.AttachedEntity;
|
||||
|
||||
if (!TryComp<HandsComponent>(player, out var hands))
|
||||
if (_playerManager.LocalSession?.AttachedEntity is not { } player)
|
||||
return;
|
||||
|
||||
var heldEntity = hands.ActiveHand?.HeldEntity;
|
||||
if (!_hands.TryGetActiveItem(player, out var heldEntity))
|
||||
return;
|
||||
|
||||
if (!TryComp<RCDComponent>(heldEntity, out var rcd))
|
||||
{
|
||||
|
||||
@@ -68,11 +68,15 @@ public sealed class TrayScannerSystem : SharedTrayScannerSystem
|
||||
|
||||
foreach (var hand in _hands.EnumerateHands(player.Value))
|
||||
{
|
||||
if (!scannerQuery.TryGetComponent(hand.HeldEntity, out var heldScanner) || !heldScanner.Enabled)
|
||||
if (!_hands.TryGetHeldItem(player.Value, hand, out var heldEntity))
|
||||
continue;
|
||||
|
||||
if (!scannerQuery.TryGetComponent(heldEntity, out var heldScanner) || !heldScanner.Enabled)
|
||||
continue;
|
||||
|
||||
range = MathF.Max(heldScanner.Range, range);
|
||||
canSee = true;
|
||||
break;
|
||||
}
|
||||
|
||||
inRange = new HashSet<Entity<SubFloorHideComponent>>();
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Inventory.VirtualItem;
|
||||
using Content.Shared.Timing;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controllers;
|
||||
@@ -28,7 +29,7 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
|
||||
private readonly Dictionary<string, int> _handContainerIndices = new();
|
||||
private readonly Dictionary<string, HandButton> _handLookup = new();
|
||||
private HandsComponent? _playerHandsComponent;
|
||||
private HandButton? _activeHand = null;
|
||||
private HandButton? _activeHand;
|
||||
|
||||
// We only have two item status controls (left and right hand),
|
||||
// but we may have more than two hands.
|
||||
@@ -38,7 +39,7 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
|
||||
private HandButton? _statusHandLeft;
|
||||
private HandButton? _statusHandRight;
|
||||
|
||||
private int _backupSuffix = 0; //this is used when autogenerating container names if they don't have names
|
||||
private int _backupSuffix; //this is used when autogenerating container names if they don't have names
|
||||
|
||||
private HotbarGui? HandsGui => UIManager.GetActiveUIWidgetOrNull<HotbarGui>();
|
||||
|
||||
@@ -48,7 +49,7 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
|
||||
_handsSystem.OnPlayerItemAdded += OnItemAdded;
|
||||
_handsSystem.OnPlayerItemRemoved += OnItemRemoved;
|
||||
_handsSystem.OnPlayerSetActiveHand += SetActiveHand;
|
||||
_handsSystem.OnPlayerRemoveHand += RemoveHand;
|
||||
_handsSystem.OnPlayerRemoveHand += OnRemoveHand;
|
||||
_handsSystem.OnPlayerHandsAdded += LoadPlayerHands;
|
||||
_handsSystem.OnPlayerHandsRemoved += UnloadPlayerHands;
|
||||
_handsSystem.OnPlayerHandBlocked += HandBlocked;
|
||||
@@ -61,28 +62,35 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
|
||||
_handsSystem.OnPlayerItemAdded -= OnItemAdded;
|
||||
_handsSystem.OnPlayerItemRemoved -= OnItemRemoved;
|
||||
_handsSystem.OnPlayerSetActiveHand -= SetActiveHand;
|
||||
_handsSystem.OnPlayerRemoveHand -= RemoveHand;
|
||||
_handsSystem.OnPlayerRemoveHand -= OnRemoveHand;
|
||||
_handsSystem.OnPlayerHandsAdded -= LoadPlayerHands;
|
||||
_handsSystem.OnPlayerHandsRemoved -= UnloadPlayerHands;
|
||||
_handsSystem.OnPlayerHandBlocked -= HandBlocked;
|
||||
_handsSystem.OnPlayerHandUnblocked -= HandUnblocked;
|
||||
}
|
||||
|
||||
private void OnAddHand(string name, HandLocation location)
|
||||
private void OnAddHand(Entity<HandsComponent> entity, string name, HandLocation location)
|
||||
{
|
||||
if (entity.Owner != _player.LocalEntity)
|
||||
return;
|
||||
AddHand(name, location);
|
||||
}
|
||||
|
||||
private void OnRemoveHand(Entity<HandsComponent> entity, string name)
|
||||
{
|
||||
if (entity.Owner != _player.LocalEntity)
|
||||
return;
|
||||
RemoveHand(name);
|
||||
}
|
||||
|
||||
private void HandPressed(GUIBoundKeyEventArgs args, SlotControl hand)
|
||||
{
|
||||
if (_playerHandsComponent == null)
|
||||
{
|
||||
if (!_handsSystem.TryGetPlayerHands(out var hands))
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Function == EngineKeyFunctions.UIClick)
|
||||
{
|
||||
_handsSystem.UIHandClick(_playerHandsComponent, hand.SlotName);
|
||||
_handsSystem.UIHandClick(hands.Value, hand.SlotName);
|
||||
args.Handle();
|
||||
}
|
||||
else if (args.Function == EngineKeyFunctions.UseSecondary)
|
||||
@@ -122,33 +130,33 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadPlayerHands(HandsComponent handsComp)
|
||||
private void LoadPlayerHands(Entity<HandsComponent> handsComp)
|
||||
{
|
||||
DebugTools.Assert(_playerHandsComponent == null);
|
||||
if (HandsGui != null)
|
||||
HandsGui.Visible = true;
|
||||
|
||||
_playerHandsComponent = handsComp;
|
||||
foreach (var (name, hand) in handsComp.Hands)
|
||||
foreach (var (name, hand) in handsComp.Comp.Hands)
|
||||
{
|
||||
var handButton = AddHand(name, hand.Location);
|
||||
|
||||
if (_entities.TryGetComponent(hand.HeldEntity, out VirtualItemComponent? virt))
|
||||
if (_handsSystem.TryGetHeldItem(handsComp.AsNullable(), name, out var held) &&
|
||||
_entities.TryGetComponent(held, out VirtualItemComponent? virt))
|
||||
{
|
||||
handButton.SetEntity(virt.BlockingEntity);
|
||||
handButton.Blocked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
handButton.SetEntity(hand.HeldEntity);
|
||||
handButton.SetEntity(held);
|
||||
handButton.Blocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
var activeHand = handsComp.ActiveHand;
|
||||
if (activeHand == null)
|
||||
if (handsComp.Comp.ActiveHandId == null)
|
||||
return;
|
||||
SetActiveHand(activeHand.Name);
|
||||
SetActiveHand(handsComp.Comp.ActiveHandId);
|
||||
}
|
||||
|
||||
private void HandBlocked(string handName)
|
||||
@@ -260,19 +268,21 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
|
||||
if (HandsGui != null &&
|
||||
_playerHandsComponent != null &&
|
||||
_player.LocalSession?.AttachedEntity is { } playerEntity &&
|
||||
_handsSystem.TryGetHand(playerEntity, handName, out var hand, _playerHandsComponent))
|
||||
_handsSystem.TryGetHand((playerEntity, _playerHandsComponent), handName, out var hand))
|
||||
{
|
||||
var foldedLocation = hand.Location.GetUILocation();
|
||||
var heldEnt = _handsSystem.GetHeldItem((playerEntity, _playerHandsComponent), handName);
|
||||
|
||||
var foldedLocation = hand.Value.Location.GetUILocation();
|
||||
if (foldedLocation == HandUILocation.Left)
|
||||
{
|
||||
_statusHandLeft = handControl;
|
||||
HandsGui.UpdatePanelEntityLeft(hand.HeldEntity);
|
||||
HandsGui.UpdatePanelEntityLeft(heldEnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Middle or right
|
||||
_statusHandRight = handControl;
|
||||
HandsGui.UpdatePanelEntityRight(hand.HeldEntity);
|
||||
HandsGui.UpdatePanelEntityRight(heldEnt);
|
||||
}
|
||||
|
||||
HandsGui.SetHighlightHand(foldedLocation);
|
||||
@@ -292,7 +302,7 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
|
||||
button.Pressed += HandPressed;
|
||||
|
||||
if (!_handLookup.TryAdd(handName, button))
|
||||
throw new Exception("Tried to add hand with duplicate name to UI. Name:" + handName);
|
||||
return _handLookup[handName];
|
||||
|
||||
if (HandsGui != null)
|
||||
{
|
||||
@@ -362,6 +372,7 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
|
||||
RemoveHand(handName, out _);
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
private bool RemoveHand(string handName, out HandButton? handButton)
|
||||
{
|
||||
if (!_handLookup.TryGetValue(handName, out handButton))
|
||||
@@ -377,7 +388,7 @@ public sealed class HandsUIController : UIController, IOnStateEntered<GameplaySt
|
||||
_statusHandRight = null;
|
||||
|
||||
_handLookup.Remove(handName);
|
||||
handButton.Dispose();
|
||||
handButton.Orphan();
|
||||
UpdateVisibleStatusPanels();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -329,9 +329,8 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
||||
var player = _playerUid;
|
||||
|
||||
if (!control.MouseIsHovering ||
|
||||
_playerInventory == null ||
|
||||
!_entities.TryGetComponent<HandsComponent>(player, out var hands) ||
|
||||
hands.ActiveHandEntity is not { } held ||
|
||||
player == null ||
|
||||
!_handsSystem.TryGetActiveItem(player.Value, out var held) ||
|
||||
!_entities.TryGetComponent(held, out SpriteComponent? sprite) ||
|
||||
!_inventorySystem.TryGetSlotContainer(player.Value, control.SlotName, out var container, out var slotDef))
|
||||
{
|
||||
@@ -342,12 +341,12 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
||||
// Set green / red overlay at 50% transparency
|
||||
var hoverEntity = _entities.SpawnEntity("hoverentity", MapCoordinates.Nullspace);
|
||||
var hoverSprite = _entities.GetComponent<SpriteComponent>(hoverEntity);
|
||||
var fits = _inventorySystem.CanEquip(player.Value, held, control.SlotName, out _, slotDef) &&
|
||||
_container.CanInsert(held, container);
|
||||
var fits = _inventorySystem.CanEquip(player.Value, held.Value, control.SlotName, out _, slotDef) &&
|
||||
_container.CanInsert(held.Value, container);
|
||||
|
||||
if (!fits && _entities.TryGetComponent<StorageComponent>(container.ContainedEntity, out var storage))
|
||||
{
|
||||
fits = _entities.System<StorageSystem>().CanInsert(container.ContainedEntity.Value, held, out _, storage);
|
||||
fits = _entities.System<StorageSystem>().CanInsert(container.ContainedEntity.Value, held.Value, out _, storage);
|
||||
}
|
||||
else if (!fits && _entities.TryGetComponent<ItemSlotsComponent>(container.ContainedEntity, out var itemSlots))
|
||||
{
|
||||
@@ -357,14 +356,14 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
|
||||
if (!slot.InsertOnInteract)
|
||||
continue;
|
||||
|
||||
if (!itemSlotsSys.CanInsert(container.ContainedEntity.Value, held, null, slot))
|
||||
if (!itemSlotsSys.CanInsert(container.ContainedEntity.Value, held.Value, null, slot))
|
||||
continue;
|
||||
fits = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_sprite.CopySprite((held, sprite), (hoverEntity, hoverSprite));
|
||||
_sprite.CopySprite((held.Value, sprite), (hoverEntity, hoverSprite));
|
||||
_sprite.SetColor((hoverEntity, hoverSprite), fits ? new Color(0, 255, 0, 127) : new Color(255, 0, 0, 127));
|
||||
|
||||
control.HoverSpriteView.SetEntity(hoverEntity);
|
||||
|
||||
Reference in New Issue
Block a user