2021-01-10 13:07:33 +01:00
|
|
|
using System.Threading.Tasks;
|
2020-08-18 14:39:08 +02:00
|
|
|
using Content.Server.GameObjects.Components.GUI;
|
2020-07-25 15:11:16 +02:00
|
|
|
using Content.Shared.GameObjects.Components;
|
2020-07-18 22:51:56 -07:00
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2019-04-25 22:22:51 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-01-10 13:07:33 +01:00
|
|
|
using Robust.Shared.Maths;
|
2021-02-18 09:09:07 +01:00
|
|
|
using Robust.Shared.Players;
|
2019-04-17 23:26:00 +02:00
|
|
|
using Robust.Shared.Serialization;
|
2020-09-08 13:30:22 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
2019-04-17 23:26:00 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components
|
|
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2020-10-14 15:24:07 +02:00
|
|
|
[ComponentReference(typeof(SharedPlaceableSurfaceComponent))]
|
2020-07-06 14:27:03 -07:00
|
|
|
public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent, IInteractUsing
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
|
|
|
|
private bool _isPlaceable;
|
2021-01-10 13:07:33 +01:00
|
|
|
private bool _placeCentered;
|
|
|
|
|
private Vector2 _positionOffset;
|
2020-10-14 15:24:07 +02:00
|
|
|
|
2020-09-08 13:30:22 +02:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2020-10-14 15:24:07 +02:00
|
|
|
public override bool IsPlaceable
|
|
|
|
|
{
|
|
|
|
|
get => _isPlaceable;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_isPlaceable == value)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_isPlaceable = value;
|
|
|
|
|
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
|
2021-01-10 13:07:33 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public override bool PlaceCentered
|
|
|
|
|
{
|
|
|
|
|
get => _placeCentered;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_placeCentered == value)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_placeCentered = value;
|
|
|
|
|
|
|
|
|
|
Dirty();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public override Vector2 PositionOffset
|
|
|
|
|
{
|
|
|
|
|
get => _positionOffset;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_positionOffset.EqualsApprox(value))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_positionOffset = value;
|
|
|
|
|
|
|
|
|
|
Dirty();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 13:30:22 +02:00
|
|
|
[ViewVariables]
|
2020-11-20 16:58:06 +02:00
|
|
|
int IInteractUsing.Priority => -10;
|
2020-08-13 20:14:07 +02:00
|
|
|
|
2019-04-17 23:26:00 +02:00
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
|
|
|
{
|
|
|
|
|
base.ExposeData(serializer);
|
|
|
|
|
|
|
|
|
|
serializer.DataField(ref _isPlaceable, "IsPlaceable", true);
|
2021-01-10 13:07:33 +01:00
|
|
|
serializer.DataField(ref _placeCentered, "placeCentered", false);
|
|
|
|
|
serializer.DataField(ref _positionOffset, "positionOffset", Vector2.Zero);
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
2020-07-25 15:11:16 +02:00
|
|
|
|
2021-02-18 09:09:07 +01:00
|
|
|
public override ComponentState GetComponentState(ICommonSession player)
|
2020-10-14 15:24:07 +02:00
|
|
|
{
|
2021-01-10 13:07:33 +01:00
|
|
|
return new PlaceableSurfaceComponentState(_isPlaceable,_placeCentered,_positionOffset);
|
2020-10-14 15:24:07 +02:00
|
|
|
}
|
2020-08-18 14:39:08 +02:00
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
2019-04-25 22:22:51 +01:00
|
|
|
{
|
2020-02-09 06:42:12 -03:00
|
|
|
if (!IsPlaceable)
|
|
|
|
|
return false;
|
|
|
|
|
|
2019-04-25 22:22:51 +01:00
|
|
|
if(!eventArgs.User.TryGetComponent<HandsComponent>(out var handComponent))
|
|
|
|
|
{
|
2020-02-09 06:42:12 -03:00
|
|
|
return false;
|
2019-04-25 22:22:51 +01:00
|
|
|
}
|
2020-05-23 17:23:25 +02:00
|
|
|
handComponent.Drop(eventArgs.Using);
|
2021-01-10 13:07:33 +01:00
|
|
|
if (_placeCentered)
|
|
|
|
|
eventArgs.Using.Transform.WorldPosition = eventArgs.Target.Transform.WorldPosition + _positionOffset;
|
|
|
|
|
else
|
|
|
|
|
eventArgs.Using.Transform.WorldPosition = eventArgs.ClickLocation.Position;
|
2019-04-25 22:22:51 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
}
|