Add click dragging for buckle (#1290)

This commit is contained in:
DrSmugleaf
2020-07-07 00:04:30 +02:00
committed by GitHub
parent 5056ded35e
commit c78ce3e27a
8 changed files with 69 additions and 11 deletions

View File

@@ -1,10 +1,12 @@
using Content.Shared.GameObjects.Components.Mobs; using Content.Client.GameObjects.Components.Strap;
using Content.Client.Interfaces.GameObjects.Components.Interaction;
using Content.Shared.GameObjects.Components.Mobs;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
namespace Content.Client.GameObjects.Components.Mobs namespace Content.Client.GameObjects.Components.Mobs
{ {
[RegisterComponent] [RegisterComponent]
public class BuckleComponent : SharedBuckleComponent public class BuckleComponent : SharedBuckleComponent, IClientDraggable
{ {
private bool _buckled; private bool _buckled;
@@ -19,5 +21,15 @@ namespace Content.Client.GameObjects.Components.Mobs
} }
protected override bool Buckled => _buckled; protected override bool Buckled => _buckled;
bool IClientDraggable.ClientCanDropOn(CanDropEventArgs eventArgs)
{
return eventArgs.Target.HasComponent<StrapComponent>();
}
bool IClientDraggable.ClientCanDrag(CanDragEventArgs eventArgs)
{
return true;
}
} }
} }

View File

@@ -17,7 +17,7 @@ namespace Content.Client.GameObjects.Components.Mobs
return; return;
} }
if (!component.TryGetData<int>(SharedStrapComponent.StrapVisuals.RotationAngle, out var angle)) if (!component.TryGetData<int>(StrapVisuals.RotationAngle, out var angle))
{ {
return; return;
} }

View File

@@ -0,0 +1,22 @@
#nullable enable
using Content.Shared.GameObjects.Components.Strap;
using Robust.Shared.GameObjects;
namespace Content.Client.GameObjects.Components.Strap
{
[RegisterComponent]
public class StrapComponent : SharedStrapComponent
{
public override StrapPosition Position { get; protected set; }
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (!(curState is StrapComponentState strap))
{
return;
}
Position = strap.Position;
}
}
}

View File

@@ -115,7 +115,6 @@
"Utensil", "Utensil",
"UnarmedCombat", "UnarmedCombat",
"TimedSpawner", "TimedSpawner",
"Strap",
"NodeContainer", "NodeContainer",
"PowerSupplier", "PowerSupplier",
"PowerConsumer", "PowerConsumer",

View File

@@ -22,7 +22,7 @@ using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Mobs namespace Content.Server.GameObjects.Components.Mobs
{ {
[RegisterComponent] [RegisterComponent]
public class BuckleComponent : SharedBuckleComponent, IInteractHand public class BuckleComponent : SharedBuckleComponent, IInteractHand, IDragDrop
{ {
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystem; [Dependency] private readonly IEntitySystemManager _entitySystem;
@@ -299,6 +299,11 @@ namespace Content.Server.GameObjects.Components.Mobs
return TryUnbuckle(eventArgs.User); return TryUnbuckle(eventArgs.User);
} }
bool IDragDrop.DragDrop(DragDropEventArgs eventArgs)
{
return TryBuckle(eventArgs.User, eventArgs.Target);
}
[Verb] [Verb]
private sealed class BuckleVerb : Verb<BuckleComponent> private sealed class BuckleVerb : Verb<BuckleComponent>
{ {

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.GameObjects.Components.Interaction; using Content.Server.Interfaces.GameObjects.Components.Interaction;
using Content.Shared.GameObjects; using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Strap; using Content.Shared.GameObjects.Components.Strap;
@@ -35,7 +34,7 @@ namespace Content.Server.GameObjects.Components.Strap
public override StrapPosition Position public override StrapPosition Position
{ {
get => _position; get => _position;
set protected set
{ {
_position = value; _position = value;
Dirty(); Dirty();
@@ -150,6 +149,11 @@ namespace Content.Server.GameObjects.Components.Strap
OccupiedSize = 0; OccupiedSize = 0;
} }
public override ComponentState GetComponentState()
{
return new StrapComponentState(Position);
}
[Verb] [Verb]
private sealed class StrapVerb : Verb<StrapComponent> private sealed class StrapVerb : Verb<StrapComponent>
{ {

View File

@@ -26,12 +26,27 @@ namespace Content.Shared.GameObjects.Components.Strap
{ {
public sealed override string Name => "Strap"; public sealed override string Name => "Strap";
public virtual StrapPosition Position { get; set; } public sealed override uint? NetID => ContentNetIDs.STRAP;
[Serializable, NetSerializable] public abstract StrapPosition Position { get; protected set; }
public enum StrapVisuals }
[Serializable, NetSerializable]
public sealed class StrapComponentState : ComponentState
{
public readonly StrapPosition Position;
public StrapComponentState(StrapPosition position) : base(ContentNetIDs.BUCKLE)
{ {
RotationAngle Position = position;
} }
public bool Buckled { get; }
}
[Serializable, NetSerializable]
public enum StrapVisuals
{
RotationAngle
} }
} }

View File

@@ -59,6 +59,7 @@
public const uint BUCKLE = 1052; public const uint BUCKLE = 1052;
public const uint PROJECTILE = 1053; public const uint PROJECTILE = 1053;
public const uint THROWN_ITEM = 1054; public const uint THROWN_ITEM = 1054;
public const uint STRAP = 1055;
// Net IDs for integration tests. // Net IDs for integration tests.
public const uint PREDICTION_TEST = 10001; public const uint PREDICTION_TEST = 10001;