diff --git a/Content.Client/GameObjects/Components/PlaceableSurfaceComponent.cs b/Content.Client/GameObjects/Components/PlaceableSurfaceComponent.cs index 090c187e2a..ff207ce795 100644 --- a/Content.Client/GameObjects/Components/PlaceableSurfaceComponent.cs +++ b/Content.Client/GameObjects/Components/PlaceableSurfaceComponent.cs @@ -1,6 +1,7 @@ #nullable enable using Content.Shared.GameObjects.Components; using Robust.Shared.GameObjects; +using Robust.Shared.Maths; namespace Content.Client.GameObjects.Components { @@ -9,6 +10,8 @@ namespace Content.Client.GameObjects.Components public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent { private bool _isPlaceable; + private bool _placeCentered; + private Vector2 _positionOffset; public override bool IsPlaceable { @@ -22,7 +25,36 @@ namespace Content.Client.GameObjects.Components _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; + _placeCentered = state.PlaceCentered; + _positionOffset = state.PositionOffset; } } } diff --git a/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs b/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs index 34e40e69d5..1230842be4 100644 --- a/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs +++ b/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs @@ -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 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; } } diff --git a/Content.Shared/GameObjects/Components/SharedPlaceableSurfaceComponent.cs b/Content.Shared/GameObjects/Components/SharedPlaceableSurfaceComponent.cs index 9ed7a48cd1..ef84393789 100644 --- a/Content.Shared/GameObjects/Components/SharedPlaceableSurfaceComponent.cs +++ b/Content.Shared/GameObjects/Components/SharedPlaceableSurfaceComponent.cs @@ -1,5 +1,6 @@ using System; using Robust.Shared.GameObjects; +using Robust.Shared.Maths; using Robust.Shared.Serialization; namespace Content.Shared.GameObjects.Components @@ -8,18 +9,23 @@ namespace Content.Shared.GameObjects.Components { public override string Name => "PlaceableSurface"; public override uint? NetID => ContentNetIDs.PLACEABLE_SURFACE; - public virtual bool IsPlaceable { get; set; } + public virtual bool PlaceCentered { get; set; } + public virtual Vector2 PositionOffset { get; set; } } [Serializable, NetSerializable] public class PlaceableSurfaceComponentState : ComponentState { 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; + PlaceCentered = centered; + PositionOffset = offset; } } } diff --git a/Resources/Prototypes/Entities/Constructible/Storage/Closets/closet.yml b/Resources/Prototypes/Entities/Constructible/Storage/Closets/closet.yml index 6798e6fd6a..bfab9479d3 100644 --- a/Resources/Prototypes/Entities/Constructible/Storage/Closets/closet.yml +++ b/Resources/Prototypes/Entities/Constructible/Storage/Closets/closet.yml @@ -38,6 +38,7 @@ - SmallImpassable - type: EntityStorage - type: PlaceableSurface + placeCentered: true - type: Damageable resistances: metallicResistances - type: Destructible