-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'space-wizards:master' into sec-jetpack
- Loading branch information
Showing
262 changed files
with
28,813 additions
and
21,243 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
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
19 changes: 19 additions & 0 deletions
19
Content.Client/Movement/Components/EyeCursorOffsetComponent.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,19 @@ | ||
using System.Numerics; | ||
using Content.Client.Movement.Systems; | ||
using Content.Shared.Movement.Components; | ||
|
||
namespace Content.Client.Movement.Components; | ||
|
||
[RegisterComponent] | ||
public sealed partial class EyeCursorOffsetComponent : SharedEyeCursorOffsetComponent | ||
{ | ||
/// <summary> | ||
/// The location the offset will attempt to pan towards; based on the cursor's position in the game window. | ||
/// </summary> | ||
public Vector2 TargetPosition = Vector2.Zero; | ||
|
||
/// <summary> | ||
/// The current positional offset being applied. Used to enable gradual panning. | ||
/// </summary> | ||
public Vector2 CurrentPosition = Vector2.Zero; | ||
} |
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,91 @@ | ||
using System.Numerics; | ||
using Content.Client.Movement.Components; | ||
using Content.Shared.Camera; | ||
using Content.Shared.Inventory; | ||
using Content.Shared.Movement.Systems; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Input; | ||
using Robust.Shared.Map; | ||
using Robust.Client.Player; | ||
|
||
namespace Content.Client.Movement.Systems; | ||
|
||
public partial class EyeCursorOffsetSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IEyeManager _eyeManager = default!; | ||
[Dependency] private readonly IInputManager _inputManager = default!; | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
[Dependency] private readonly SharedContentEyeSystem _contentEye = default!; | ||
[Dependency] private readonly IMapManager _mapManager = default!; | ||
[Dependency] private readonly IClyde _clyde = default!; | ||
|
||
// This value is here to make sure the user doesn't have to move their mouse | ||
// all the way out to the edge of the screen to get the full offset. | ||
static private float _edgeOffset = 0.9f; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<EyeCursorOffsetComponent, GetEyeOffsetEvent>(OnGetEyeOffsetEvent); | ||
} | ||
|
||
private void OnGetEyeOffsetEvent(EntityUid uid, EyeCursorOffsetComponent component, ref GetEyeOffsetEvent args) | ||
{ | ||
var offset = OffsetAfterMouse(uid, component); | ||
if (offset == null) | ||
return; | ||
|
||
args.Offset += offset.Value; | ||
} | ||
|
||
public Vector2? OffsetAfterMouse(EntityUid uid, EyeCursorOffsetComponent? component) | ||
{ | ||
var localPlayer = _player.LocalPlayer?.ControlledEntity; | ||
var mousePos = _inputManager.MouseScreenPosition; | ||
var screenSize = _clyde.MainWindow.Size; | ||
var minValue = MathF.Min(screenSize.X / 2, screenSize.Y / 2) * _edgeOffset; | ||
|
||
var mouseNormalizedPos = new Vector2(-(mousePos.X - screenSize.X / 2) / minValue, (mousePos.Y - screenSize.Y / 2) / minValue); // X needs to be inverted here for some reason, otherwise it ends up flipped. | ||
|
||
if (localPlayer == null) | ||
return null; | ||
|
||
var playerPos = _transform.GetWorldPosition(localPlayer.Value); | ||
|
||
if (component == null) | ||
{ | ||
component = EnsureComp<EyeCursorOffsetComponent>(uid); | ||
} | ||
|
||
// Doesn't move the offset if the mouse has left the game window! | ||
if (mousePos.Window != WindowId.Invalid) | ||
{ | ||
// The offset must account for the in-world rotation. | ||
var eyeRotation = _eyeManager.CurrentEye.Rotation; | ||
var mouseActualRelativePos = Vector2.Transform(mouseNormalizedPos, System.Numerics.Quaternion.CreateFromAxisAngle(-System.Numerics.Vector3.UnitZ, (float)(eyeRotation.Opposite().Theta))); // I don't know, it just works. | ||
|
||
// Caps the offset into a circle around the player. | ||
mouseActualRelativePos *= component.MaxOffset; | ||
if (mouseActualRelativePos.Length() > component.MaxOffset) | ||
{ | ||
mouseActualRelativePos = mouseActualRelativePos.Normalized() * component.MaxOffset; | ||
} | ||
|
||
component.TargetPosition = mouseActualRelativePos; | ||
|
||
//Makes the view not jump immediately when moving the cursor fast. | ||
if (component.CurrentPosition != component.TargetPosition) | ||
{ | ||
Vector2 vectorOffset = component.TargetPosition - component.CurrentPosition; | ||
if (vectorOffset.Length() > component.OffsetSpeed) | ||
{ | ||
vectorOffset = vectorOffset.Normalized() * component.OffsetSpeed; | ||
} | ||
component.CurrentPosition += vectorOffset; | ||
} | ||
} | ||
return component.CurrentPosition; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,39 +1,80 @@ | ||
using Content.Client.Storage.Systems; | ||
using Content.Client.UserInterface.Systems.Storage; | ||
using Content.Client.UserInterface.Systems.Storage.Controls; | ||
using Content.Shared.Storage; | ||
using JetBrains.Annotations; | ||
using Robust.Client.UserInterface; | ||
|
||
namespace Content.Client.Storage; | ||
|
||
[UsedImplicitly] | ||
public sealed class StorageBoundUserInterface : BoundUserInterface | ||
{ | ||
[Dependency] private readonly IEntityManager _entManager = default!; | ||
|
||
private readonly StorageSystem _storage; | ||
|
||
[Obsolete] public override bool DeferredClose => false; | ||
private StorageWindow? _window; | ||
|
||
public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
_storage = _entManager.System<StorageSystem>(); | ||
} | ||
|
||
protected override void Open() | ||
{ | ||
base.Open(); | ||
|
||
if (_entManager.TryGetComponent<StorageComponent>(Owner, out var comp)) | ||
_storage.OpenStorageWindow((Owner, comp)); | ||
_window = IoCManager.Resolve<IUserInterfaceManager>() | ||
.GetUIController<StorageUIController>() | ||
.CreateStorageWindow(Owner); | ||
|
||
if (EntMan.TryGetComponent(Owner, out StorageComponent? storage)) | ||
{ | ||
_window.UpdateContainer((Owner, storage)); | ||
} | ||
|
||
_window.OnClose += Close; | ||
_window.FlagDirty(); | ||
} | ||
|
||
public void Refresh() | ||
{ | ||
_window?.FlagDirty(); | ||
} | ||
|
||
public void Reclaim() | ||
{ | ||
if (_window == null) | ||
return; | ||
|
||
_window.OnClose -= Close; | ||
_window.Orphan(); | ||
_window = null; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
if (!disposing) | ||
|
||
Reclaim(); | ||
} | ||
|
||
public void Hide() | ||
{ | ||
if (_window == null) | ||
return; | ||
|
||
_window.Visible = false; | ||
} | ||
|
||
public void Show() | ||
{ | ||
if (_window == null) | ||
return; | ||
|
||
_storage.CloseStorageWindow(Owner); | ||
_window.Visible = true; | ||
} | ||
|
||
public void ReOpen() | ||
{ | ||
_window?.Orphan(); | ||
_window = null; | ||
Open(); | ||
} | ||
} | ||
|
Oops, something went wrong.