Make held entity nullable (#5923)
This commit is contained in:
@@ -86,7 +86,7 @@ namespace Content.Client.Hands
|
||||
private void UpdateGui()
|
||||
{
|
||||
HandsContainer.DisposeAllChildren();
|
||||
|
||||
var entManager = IoCManager.Resolve<IEntityManager>();
|
||||
foreach (var hand in _hands)
|
||||
{
|
||||
var newButton = MakeHandButton(hand.HandLocation);
|
||||
@@ -97,17 +97,17 @@ namespace Content.Client.Hands
|
||||
newButton.OnPressed += args => OnHandPressed(args, handName);
|
||||
newButton.OnStoragePressed += _ => OnStoragePressed(handName);
|
||||
|
||||
_itemSlotManager.SetItemSlot(newButton, hand.HeldItem);
|
||||
_itemSlotManager.SetItemSlot(newButton, hand.HeldItem ?? EntityUid.Invalid);
|
||||
|
||||
// Show blocked overlay if hand is blocked.
|
||||
newButton.Blocked.Visible =
|
||||
hand.HeldItem != null && IoCManager.Resolve<IEntityManager>().HasComponent<HandVirtualItemComponent>(hand.HeldItem);
|
||||
hand.HeldItem != null && entManager.HasComponent<HandVirtualItemComponent>(hand.HeldItem.Value);
|
||||
}
|
||||
|
||||
if (TryGetActiveHand(out var activeHand))
|
||||
{
|
||||
activeHand.HandButton.SetActiveHand(true);
|
||||
StatusPanel.Update(activeHand.HeldItem);
|
||||
StatusPanel.Update(activeHand.HeldItem ?? EntityUid.Invalid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace Content.Client.Hands
|
||||
}
|
||||
else if (TryGetHand(handName, out var hand))
|
||||
{
|
||||
_itemSlotManager.OnButtonPressed(args, hand.HeldItem);
|
||||
_itemSlotManager.OnButtonPressed(args, hand.HeldItem ?? EntityUid.Invalid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace Content.Client.Hands
|
||||
|
||||
foreach (var hand in _hands)
|
||||
{
|
||||
_itemSlotManager.UpdateCooldown(hand.HandButton, hand.HeldItem);
|
||||
_itemSlotManager.UpdateCooldown(hand.HandButton, hand.HeldItem ?? EntityUid.Invalid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ namespace Content.Client.Hands
|
||||
/// The item being held in this hand.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public EntityUid HeldItem { get; }
|
||||
public EntityUid? HeldItem { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The button in the gui associated with this hand. Assumed to be set by gui shortly after being received from the client HandsComponent.
|
||||
@@ -258,7 +258,7 @@ namespace Content.Client.Hands
|
||||
[ViewVariables]
|
||||
public HandButton HandButton { get; set; } = default!;
|
||||
|
||||
public GuiHand(string name, HandLocation handLocation, EntityUid heldItem)
|
||||
public GuiHand(string name, HandLocation handLocation, EntityUid? heldItem)
|
||||
{
|
||||
Name = name;
|
||||
HandLocation = handLocation;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
@@ -46,7 +46,7 @@ namespace Content.Client.Hands
|
||||
var sys = EntitySystem.Get<HandsSystem>();
|
||||
var handEntity = sys.GetActiveHandEntity();
|
||||
|
||||
if (handEntity == default || !_cfg.GetCVar(CCVars.HudHeldItemShow) || !IoCManager.Resolve<IEntityManager>().HasComponent<ISpriteComponent>(handEntity))
|
||||
if (handEntity == null || !_cfg.GetCVar(CCVars.HudHeldItemShow) || !IoCManager.Resolve<IEntityManager>().HasComponent<ISpriteComponent>(handEntity))
|
||||
return;
|
||||
|
||||
var screen = args.ScreenHandle;
|
||||
@@ -56,7 +56,7 @@ namespace Content.Client.Hands
|
||||
|
||||
screen.RenderInRenderTarget(_renderBackbuffer, () =>
|
||||
{
|
||||
screen.DrawEntity(handEntity, halfSize, new Vector2(1f, 1f) * uiScale, Direction.South);
|
||||
screen.DrawEntity(handEntity.Value, halfSize, new Vector2(1f, 1f) * uiScale, Direction.South);
|
||||
}, Color.Transparent);
|
||||
|
||||
var offset = _cfg.GetCVar(CCVars.HudHeldItemOffset);
|
||||
|
||||
@@ -77,10 +77,10 @@ namespace Content.Client.Hands
|
||||
return new HandsGuiState(states, hands.ActiveHand);
|
||||
}
|
||||
|
||||
public EntityUid GetActiveHandEntity()
|
||||
public EntityUid? GetActiveHandEntity()
|
||||
{
|
||||
if (GetPlayerHandsComponent() is not { ActiveHand: { } active } hands)
|
||||
return default;
|
||||
return null;
|
||||
|
||||
return hands.GetHand(active).HeldEntity;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ namespace Content.Client.Hands
|
||||
var pressedEntity = pressedHand.HeldEntity;
|
||||
var activeEntity = activeHand.HeldEntity;
|
||||
|
||||
if (pressedHand == activeHand && activeEntity != default)
|
||||
if (pressedHand == activeHand && activeEntity != null)
|
||||
{
|
||||
// use item in hand
|
||||
// it will always be attack_self() in my heart.
|
||||
@@ -114,14 +114,14 @@ namespace Content.Client.Hands
|
||||
return;
|
||||
}
|
||||
|
||||
if (pressedHand != activeHand && pressedEntity == default)
|
||||
if (pressedHand != activeHand && pressedEntity == null)
|
||||
{
|
||||
// change active hand
|
||||
RaiseNetworkEvent(new RequestSetHandEvent(handName));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pressedHand != activeHand && pressedEntity != default && activeEntity != default)
|
||||
if (pressedHand != activeHand && pressedEntity != null && activeEntity != null)
|
||||
{
|
||||
// use active item on held item
|
||||
RaiseNetworkEvent(new ClientInteractUsingInHandMsg(pressedHand.Name));
|
||||
|
||||
Reference in New Issue
Block a user