Fix tabletop error (#7830)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Content.Client.Tabletop.Components;
|
||||
using Content.Client.Tabletop.UI;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Shared.Tabletop;
|
||||
using Content.Shared.Tabletop.Components;
|
||||
using Content.Shared.Tabletop.Events;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
@@ -10,14 +10,10 @@ using Robust.Client.Input;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using static Robust.Shared.Input.Binding.PointerInputCmdHandler;
|
||||
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
|
||||
@@ -51,6 +47,13 @@ namespace Content.Client.Tabletop
|
||||
|
||||
SubscribeNetworkEvent<TabletopPlayEvent>(OnTabletopPlay);
|
||||
SubscribeLocalEvent<TabletopDraggableComponent, ComponentHandleState>(HandleComponentState);
|
||||
SubscribeLocalEvent<TabletopDraggableComponent, ComponentRemove>(HandleDraggableRemoved);
|
||||
}
|
||||
|
||||
private void HandleDraggableRemoved(EntityUid uid, TabletopDraggableComponent component, ComponentRemove args)
|
||||
{
|
||||
if (_draggedEntity == uid)
|
||||
StopDragging(false);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -59,13 +62,11 @@ namespace Content.Client.Tabletop
|
||||
if (!_gameTiming.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
// If there is no player entity, return
|
||||
if (_playerManager.LocalPlayer is not {ControlledEntity: { } playerEntity}) return;
|
||||
if (_window == null)
|
||||
return;
|
||||
|
||||
if (StunnedOrNoHands(playerEntity))
|
||||
{
|
||||
StopDragging();
|
||||
}
|
||||
// If there is no player entity, return
|
||||
if (_playerManager.LocalPlayer is not { ControlledEntity: { } playerEntity }) return;
|
||||
|
||||
if (!CanSeeTable(playerEntity, _table))
|
||||
{
|
||||
@@ -77,8 +78,11 @@ namespace Content.Client.Tabletop
|
||||
// If no entity is being dragged or no viewport is clicked, return
|
||||
if (_draggedEntity == null || _viewport == null) return;
|
||||
|
||||
// Make sure the dragged entity has a draggable component
|
||||
if (!EntityManager.TryGetComponent<TabletopDraggableComponent>(_draggedEntity.Value, out var draggableComponent)) return;
|
||||
if (!CanDrag(playerEntity, _draggedEntity.Value, out var draggableComponent))
|
||||
{
|
||||
StopDragging();
|
||||
return;
|
||||
}
|
||||
|
||||
// If the dragged entity has another dragging player, drop the item
|
||||
// This should happen if the local player is dragging an item, and another player grabs it out of their hand
|
||||
@@ -179,21 +183,7 @@ namespace Content.Client.Tabletop
|
||||
return false;
|
||||
|
||||
// Return if can not see table or stunned/no hands
|
||||
if (!CanSeeTable(playerEntity, _table) || StunnedOrNoHands(playerEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var draggedEntity = args.EntityUid;
|
||||
|
||||
// Set the entity being dragged and the viewport under the mouse
|
||||
if (!EntityManager.EntityExists(draggedEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure that entity can be dragged
|
||||
if (!EntityManager.HasComponent<TabletopDraggableComponent>(draggedEntity))
|
||||
if (!CanSeeTable(playerEntity, _table) || !CanDrag(playerEntity, args.EntityUid, out _))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -204,7 +194,7 @@ namespace Content.Client.Tabletop
|
||||
return false;
|
||||
}
|
||||
|
||||
StartDragging(draggedEntity, viewport);
|
||||
StartDragging(args.EntityUid, viewport);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user