-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'frontier-guns' of https://github.com/sleepyyapril/TheDen …
…into frontier-guns
- Loading branch information
Showing
87 changed files
with
528 additions
and
110 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
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
Oops, something went wrong.