Add PlaceCentered bool to PlaceableSurfaceComponent (#2771)
* Added bool _placeCentered to check if an entity must be placed at mouse position or center of the PlaceableSurface (+ offset) when dropped. * private variables formatted to camel case * Use EqualsApprox in the setter for PositionOffset * -Changed client-side SurfaceComponent to camelCase -Added placeCentered and positionOffset to PlaceableSurfaceComponentState -Getter and setters for placeCentered and positionOffset client-side * Update Content.Client/GameObjects/Components/PlaceableSurfaceComponent.cs Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> * Add "_" to private vars name * Made YAML properties camelCase * Add "_" to private vars name * Call Dirty() when IsPlaceable,PlaceCentered and PositionOffset are changed. * Removed Dirty() from client. Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -13,6 +14,8 @@ namespace Content.Server.GameObjects.Components
|
||||
public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent, IInteractUsing
|
||||
{
|
||||
private bool _isPlaceable;
|
||||
private bool _placeCentered;
|
||||
private Vector2 _positionOffset;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public override bool IsPlaceable
|
||||
@@ -31,6 +34,42 @@ namespace Content.Server.GameObjects.Components
|
||||
}
|
||||
}
|
||||
|
||||
[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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables]
|
||||
int IInteractUsing.Priority => -10;
|
||||
|
||||
@@ -39,11 +78,13 @@ namespace Content.Server.GameObjects.Components
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _isPlaceable, "IsPlaceable", true);
|
||||
serializer.DataField(ref _placeCentered, "placeCentered", false);
|
||||
serializer.DataField(ref _positionOffset, "positionOffset", Vector2.Zero);
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new PlaceableSurfaceComponentState(_isPlaceable);
|
||||
return new PlaceableSurfaceComponentState(_isPlaceable,_placeCentered,_positionOffset);
|
||||
}
|
||||
|
||||
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
@@ -56,7 +97,10 @@ namespace Content.Server.GameObjects.Components
|
||||
return false;
|
||||
}
|
||||
handComponent.Drop(eventArgs.Using);
|
||||
eventArgs.Using.Transform.WorldPosition = eventArgs.ClickLocation.Position;
|
||||
if (_placeCentered)
|
||||
eventArgs.Using.Transform.WorldPosition = eventArgs.Target.Transform.WorldPosition + _positionOffset;
|
||||
else
|
||||
eventArgs.Using.Transform.WorldPosition = eventArgs.ClickLocation.Position;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user