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,6 +1,7 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using Content.Shared.GameObjects.Components;
|
using Content.Shared.GameObjects.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
|
|
||||||
namespace Content.Client.GameObjects.Components
|
namespace Content.Client.GameObjects.Components
|
||||||
{
|
{
|
||||||
@@ -9,6 +10,8 @@ namespace Content.Client.GameObjects.Components
|
|||||||
public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent
|
public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent
|
||||||
{
|
{
|
||||||
private bool _isPlaceable;
|
private bool _isPlaceable;
|
||||||
|
private bool _placeCentered;
|
||||||
|
private Vector2 _positionOffset;
|
||||||
|
|
||||||
public override bool IsPlaceable
|
public override bool IsPlaceable
|
||||||
{
|
{
|
||||||
@@ -22,7 +25,36 @@ namespace Content.Client.GameObjects.Components
|
|||||||
|
|
||||||
_isPlaceable = value;
|
_isPlaceable = value;
|
||||||
|
|
||||||
Dirty();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool PlaceCentered
|
||||||
|
{
|
||||||
|
get => _placeCentered;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_placeCentered == value)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_placeCentered = value;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Vector2 PositionOffset
|
||||||
|
{
|
||||||
|
get => _positionOffset;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_positionOffset.EqualsApprox(value))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_positionOffset = value;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +68,8 @@ namespace Content.Client.GameObjects.Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
_isPlaceable = state.IsPlaceable;
|
_isPlaceable = state.IsPlaceable;
|
||||||
|
_placeCentered = state.PlaceCentered;
|
||||||
|
_positionOffset = state.PositionOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.Server.GameObjects.Components.GUI;
|
using Content.Server.GameObjects.Components.GUI;
|
||||||
using Content.Shared.GameObjects.Components;
|
using Content.Shared.GameObjects.Components;
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
@@ -13,6 +14,8 @@ namespace Content.Server.GameObjects.Components
|
|||||||
public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent, IInteractUsing
|
public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent, IInteractUsing
|
||||||
{
|
{
|
||||||
private bool _isPlaceable;
|
private bool _isPlaceable;
|
||||||
|
private bool _placeCentered;
|
||||||
|
private Vector2 _positionOffset;
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public override bool IsPlaceable
|
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]
|
[ViewVariables]
|
||||||
int IInteractUsing.Priority => -10;
|
int IInteractUsing.Priority => -10;
|
||||||
|
|
||||||
@@ -39,11 +78,13 @@ namespace Content.Server.GameObjects.Components
|
|||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
|
|
||||||
serializer.DataField(ref _isPlaceable, "IsPlaceable", true);
|
serializer.DataField(ref _isPlaceable, "IsPlaceable", true);
|
||||||
|
serializer.DataField(ref _placeCentered, "placeCentered", false);
|
||||||
|
serializer.DataField(ref _positionOffset, "positionOffset", Vector2.Zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ComponentState GetComponentState()
|
public override ComponentState GetComponentState()
|
||||||
{
|
{
|
||||||
return new PlaceableSurfaceComponentState(_isPlaceable);
|
return new PlaceableSurfaceComponentState(_isPlaceable,_placeCentered,_positionOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
|
||||||
@@ -56,7 +97,10 @@ namespace Content.Server.GameObjects.Components
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
handComponent.Drop(eventArgs.Using);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.GameObjects.Components
|
namespace Content.Shared.GameObjects.Components
|
||||||
@@ -8,18 +9,23 @@ namespace Content.Shared.GameObjects.Components
|
|||||||
{
|
{
|
||||||
public override string Name => "PlaceableSurface";
|
public override string Name => "PlaceableSurface";
|
||||||
public override uint? NetID => ContentNetIDs.PLACEABLE_SURFACE;
|
public override uint? NetID => ContentNetIDs.PLACEABLE_SURFACE;
|
||||||
|
|
||||||
public virtual bool IsPlaceable { get; set; }
|
public virtual bool IsPlaceable { get; set; }
|
||||||
|
public virtual bool PlaceCentered { get; set; }
|
||||||
|
public virtual Vector2 PositionOffset { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public class PlaceableSurfaceComponentState : ComponentState
|
public class PlaceableSurfaceComponentState : ComponentState
|
||||||
{
|
{
|
||||||
public readonly bool IsPlaceable;
|
public readonly bool IsPlaceable;
|
||||||
|
public readonly bool PlaceCentered;
|
||||||
|
public readonly Vector2 PositionOffset;
|
||||||
|
|
||||||
public PlaceableSurfaceComponentState(bool placeable) : base(ContentNetIDs.PLACEABLE_SURFACE)
|
public PlaceableSurfaceComponentState(bool placeable, bool centered, Vector2 offset) : base(ContentNetIDs.PLACEABLE_SURFACE)
|
||||||
{
|
{
|
||||||
IsPlaceable = placeable;
|
IsPlaceable = placeable;
|
||||||
|
PlaceCentered = centered;
|
||||||
|
PositionOffset = offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
- SmallImpassable
|
- SmallImpassable
|
||||||
- type: EntityStorage
|
- type: EntityStorage
|
||||||
- type: PlaceableSurface
|
- type: PlaceableSurface
|
||||||
|
placeCentered: true
|
||||||
- type: Damageable
|
- type: Damageable
|
||||||
resistances: metallicResistances
|
resistances: metallicResistances
|
||||||
- type: Destructible
|
- type: Destructible
|
||||||
|
|||||||
Reference in New Issue
Block a user