-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- This is a semi-strict format, you can add/remove sections as needed but the order/format should be kept the same Remove these comments before submitting --> # Description <!-- Explain this PR in as much detail as applicable Some example prompts to consider: How might this affect the game? The codebase? What might be some alternatives to this? How/Who does this benefit/hurt [the game/codebase]? --> adds PR #414 from Floof Station Fansana/floofstation1#414 - Leashes now have configurable length. You can choose the preferred length in the verb menu. - The short leash proto has been removed and an appropriate prototype migration has been added. - Leashes were made anchorable (so we can finally keep Seb safe) - Leash sprites were visually scaled down (70% the original size) - Shock and bell collars have been reparented to ClothingNeckCollarBase. - Leash anchors now a visual offset field, that properly incorporates the visual rotation and scaling of the entity. - Leashes now use a brand new overlay renderer (a refactored JointVisualsOverlay) - Fixed a bug where the "remove leash" verb would not appear on the respective clothing.
- Loading branch information
Showing
20 changed files
with
288 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System.Numerics; | ||
using Content.Shared.Floofstation.Leash.Components; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Shared.Enums; | ||
|
||
namespace Content.Client.Floofstation.Leash; | ||
|
||
public sealed class LeashVisualsOverlay : Overlay | ||
{ | ||
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV; | ||
|
||
private readonly IEntityManager _entMan; | ||
private readonly SpriteSystem _sprites; | ||
private readonly SharedTransformSystem _xform; | ||
private readonly EntityQuery<TransformComponent> _xformQuery; | ||
private readonly EntityQuery<SpriteComponent> _spriteQuery; | ||
|
||
public LeashVisualsOverlay(IEntityManager entMan) | ||
{ | ||
_entMan = entMan; | ||
_sprites = _entMan.System<SpriteSystem>(); | ||
_xform = _entMan.System<SharedTransformSystem>(); | ||
_xformQuery = _entMan.GetEntityQuery<TransformComponent>(); | ||
_spriteQuery = _entMan.GetEntityQuery<SpriteComponent>(); | ||
} | ||
|
||
protected override void Draw(in OverlayDrawArgs args) | ||
{ | ||
var worldHandle = args.WorldHandle; | ||
worldHandle.SetTransform(Vector2.Zero, Angle.Zero); | ||
|
||
var query = _entMan.EntityQueryEnumerator<LeashedVisualsComponent>(); | ||
while (query.MoveNext(out var visualsComp)) | ||
{ | ||
if (visualsComp.Source is not {Valid: true} source | ||
|| visualsComp.Target is not {Valid: true} target | ||
|| !_xformQuery.TryGetComponent(source, out var xformComp) | ||
|| !_xformQuery.TryGetComponent(target, out var otherXformComp) | ||
|| xformComp.MapID != args.MapId | ||
|| otherXformComp.MapID != xformComp.MapID) | ||
continue; | ||
|
||
var texture = _sprites.Frame0(visualsComp.Sprite); | ||
var width = texture.Width / (float) EyeManager.PixelsPerMeter; | ||
|
||
var coordsA = xformComp.Coordinates; | ||
var coordsB = otherXformComp.Coordinates; | ||
|
||
// If both coordinates are in the same spot (e.g. the leash is being held by the leashed), don't render anything | ||
if (coordsA.TryDistance(_entMan, _xform, coordsB, out var dist) && dist < 0.01f) | ||
continue; | ||
|
||
var rotA = xformComp.LocalRotation; | ||
var rotB = otherXformComp.LocalRotation; | ||
var offsetA = visualsComp.OffsetSource; | ||
var offsetB = visualsComp.OffsetTarget; | ||
|
||
// Sprite rotation is the rotation along the Z axis | ||
// Which is different from transform rotation for all mobs that are seen from the side (instead of top-down) | ||
if (_spriteQuery.TryGetComponent(source, out var spriteA)) | ||
{ | ||
offsetA *= spriteA.Scale; | ||
rotA = spriteA.Rotation; | ||
} | ||
if (_spriteQuery.TryGetComponent(target, out var spriteB)) | ||
{ | ||
offsetB *= spriteB.Scale; | ||
rotB = spriteB.Rotation; | ||
} | ||
|
||
coordsA = coordsA.Offset(rotA.RotateVec(offsetA)); | ||
coordsB = coordsB.Offset(rotB.RotateVec(offsetB)); | ||
|
||
var posA = _xform.ToMapCoordinates(coordsA).Position; | ||
var posB = _xform.ToMapCoordinates(coordsB).Position; | ||
var diff = (posB - posA); | ||
var length = diff.Length(); | ||
|
||
// So basically, we find the midpoint, then create a box that describes the sprite boundaries, then rotate it | ||
var midPoint = diff / 2f + posA; | ||
var angle = (posB - posA).ToWorldAngle(); | ||
var box = new Box2(-width / 2f, -length / 2f, width / 2f, length / 2f); | ||
var rotate = new Box2Rotated(box.Translated(midPoint), angle, midPoint); | ||
|
||
worldHandle.DrawTextureRect(texture, rotate); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Content.Client.Physics; | ||
using Robust.Client.Graphics; | ||
|
||
namespace Content.Client.Floofstation.Leash; | ||
|
||
public sealed class LeashVisualsSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IOverlayManager _overlay = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
_overlay.AddOverlay(new LeashVisualsOverlay(EntityManager)); | ||
} | ||
|
||
public override void Shutdown() | ||
{ | ||
base.Shutdown(); | ||
_overlay.RemoveOverlay<LeashVisualsOverlay>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Content.Shared/Floofstation/Leash/Components/LeashedVisualsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Numerics; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Shared.Floofstation.Leash.Components; | ||
|
||
/// <summary> | ||
/// Draws a line between this entity and the target. Same as JointVisualsComponent. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
public sealed partial class LeashedVisualsComponent : Component | ||
{ | ||
[DataField(required: true), AutoNetworkedField] | ||
public SpriteSpecifier Sprite = default!; | ||
|
||
[DataField, AutoNetworkedField] | ||
public EntityUid Source, Target; | ||
|
||
[DataField, AutoNetworkedField] | ||
public Vector2 OffsetSource, OffsetTarget; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
verb-categories-leash-config = Set Length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
verb-leash-text = Attach leash | ||
verb-leash-error-message = Cannot attach the leash to this anchor. | ||
verb-unleash-text = Detach leash | ||
verb-leash-set-length-text = {$length} meters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# 2024-08-16 Floof Only Please message @FracturedSwords on discord if there are any merge conflicts upcoming | ||
SpawnMobArcticFoxSiobhan: SpawnMobArcticFoxSeb | ||
MobArcticFoxSiobhan: MobArcticFoxSeb | ||
|
||
# 2024-12-15: Leash now supports changing the length intrinsically | ||
ShortLeash: LeashBasic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.