Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

antitryaska #7

Merged
merged 3 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Client/Content.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

АААА?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

уээээ

<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework>
Expand Down
3 changes: 2 additions & 1 deletion Content.Client/Options/UI/Tabs/GraphicsTab.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tabs:GraphicsTab xmlns="https://spacestation14.io"
<tabs:GraphicsTab xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:tabs="clr-namespace:Content.Client.Options.UI.Tabs">
<BoxContainer Orientation="Vertical">
Expand Down Expand Up @@ -40,6 +40,7 @@
Text="{Loc 'ui-options-vp-vertical-fit'}"
ToolTip="{Loc 'ui-options-vp-vertical-fit-tooltip'}" />
<CheckBox Name="ViewportLowResCheckBox" Text="{Loc 'ui-options-vp-low-res'}" />
<CheckBox Name="PixelSnapCameraCheckBox" Text="{Loc 'ui-options-pixel-snap-camera-experimental'}" /> <!-- wwdp edit -->
<CheckBox Name="ParallaxLowQualityCheckBox" Text="{Loc 'ui-options-parallax-low-quality'}" />
<CheckBox Name="FpsCounterCheckBox" Text="{Loc 'ui-options-fps-counter'}" />
<CheckBox Name="MoodVisualEffectsCheckBox" Text="{Loc 'ui-options-mood-visual-effects'}" />
Expand Down
6 changes: 6 additions & 0 deletions Content.Client/Options/UI/Tabs/GraphicsTab.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared._White;
using Content.Shared.CCVar;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
Expand Down Expand Up @@ -75,6 +76,7 @@ public GraphicsTab()

IntegerScalingCheckBox.OnToggled += OnCheckBoxToggled;
ViewportLowResCheckBox.OnToggled += OnCheckBoxToggled;
PixelSnapCameraCheckBox.OnToggled += OnCheckBoxToggled; // WWDP EDIT
ParallaxLowQualityCheckBox.OnToggled += OnCheckBoxToggled;
FpsCounterCheckBox.OnToggled += OnCheckBoxToggled;
MoodVisualEffectsCheckBox.OnToggled += OnCheckBoxToggled;
Expand All @@ -88,6 +90,7 @@ public GraphicsTab()
IntegerScalingCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0;
ViewportVerticalFitCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportVerticalFit);
ViewportLowResCheckBox.Pressed = !_cfg.GetCVar(CCVars.ViewportScaleRender);
PixelSnapCameraCheckBox.Pressed = _cfg.GetCVar(WhiteCVars.PixelSnapCamera); // WWDP EDIT
ParallaxLowQualityCheckBox.Pressed = _cfg.GetCVar(CCVars.ParallaxLowQuality);
FpsCounterCheckBox.Pressed = _cfg.GetCVar(CCVars.HudFpsCounterVisible);
MoodVisualEffectsCheckBox.Pressed = _cfg.GetCVar(CCVars.MoodVisualEffects);
Expand Down Expand Up @@ -122,6 +125,7 @@ private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
IntegerScalingCheckBox.Pressed ? CCVars.ViewportSnapToleranceMargin.DefaultValue : 0);
_cfg.SetCVar(CCVars.ViewportVerticalFit, ViewportVerticalFitCheckBox.Pressed);
_cfg.SetCVar(CCVars.ViewportScaleRender, !ViewportLowResCheckBox.Pressed);
_cfg.SetCVar(WhiteCVars.PixelSnapCamera, PixelSnapCameraCheckBox.Pressed); // WWDP EDIT
_cfg.SetCVar(CCVars.ParallaxLowQuality, ParallaxLowQualityCheckBox.Pressed);
_cfg.SetCVar(CCVars.HudFpsCounterVisible, FpsCounterCheckBox.Pressed);
_cfg.SetCVar(CCVars.MoodVisualEffects, MoodVisualEffectsCheckBox.Pressed);
Expand Down Expand Up @@ -152,6 +156,7 @@ private void UpdateApplyButton()
var isVPScaleSame = (int) ViewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
var isIntegerScalingSame = IntegerScalingCheckBox.Pressed == (_cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0);
var isVPVerticalFitSame = ViewportVerticalFitCheckBox.Pressed == _cfg.GetCVar(CCVars.ViewportVerticalFit);
var isPixelSnapCameraSame = PixelSnapCameraCheckBox.Pressed == _cfg.GetCVar(WhiteCVars.PixelSnapCamera); // WWDP EDIT
var isVPResSame = ViewportLowResCheckBox.Pressed == !_cfg.GetCVar(CCVars.ViewportScaleRender);
var isPLQSame = ParallaxLowQualityCheckBox.Pressed == _cfg.GetCVar(CCVars.ParallaxLowQuality);
var isFpsCounterVisibleSame = FpsCounterCheckBox.Pressed == _cfg.GetCVar(CCVars.HudFpsCounterVisible);
Expand All @@ -165,6 +170,7 @@ private void UpdateApplyButton()
isVPScaleSame &&
isIntegerScalingSame &&
isVPVerticalFitSame &&
isPixelSnapCameraSame && // WWDP EDIT
isVPResSame &&
isPLQSame &&
isFpsCounterVisibleSame &&
Expand Down
64 changes: 64 additions & 0 deletions Content.Client/_White/AntiParkinsons/AntiParkinsonsRevertSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Content.Shared._White;
using Content.Shared.CCVar;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Content.Client._White.AntiParkinsons;

// The following code is slightly esoteric and higly schizophrenic. You have been warned.

#pragma warning disable RA0002

public sealed class AntiParkinsonsRevertSystem : EntitySystem
{
[Dependency] private readonly IReflectionManager _refl = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IPlayerManager _player = default!;


public override void Initialize()
{
UpdatesOutsidePrediction = true;

// dnas tae
foreach (Type sys in _refl.GetAllChildren<EntitySystem>())
{
if (sys.IsAbstract || sys == typeof(AntiParkinsonsRevertSystem))
continue;

UpdatesBefore.Add(sys);
}
}

// dnas tae
public override void FrameUpdate(float frameTime)
{
var query = AllEntityQuery<PixelSnapEyeComponent>();

while (query.MoveNext(out var uid, out var ppComp))
{
if (!TryComp<EyeComponent>(uid, out var eyeComp) || eyeComp.Eye == null)
continue;

eyeComp.Eye.Position = PPCamHelper.CheckForChange(eyeComp.Eye.Position, ppComp.EyePositionModified, ppComp.EyePosition);
eyeComp.Eye.Offset = PPCamHelper.CheckForChange(eyeComp.Eye.Offset, ppComp.EyeOffsetModified, ppComp.EyeOffset);
eyeComp.Offset = eyeComp.Eye.Offset;

if(TryComp<SpriteComponent>(uid, out var sprite))
sprite.Offset = PPCamHelper.CheckForChange(sprite.Offset, ppComp.SpriteOffsetModified, ppComp.SpriteOffset);
}
}
}

#pragma warning restore RA0002
163 changes: 163 additions & 0 deletions Content.Client/_White/AntiParkinsons/AntiParkinsonsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
using Content.Shared._White;
using Content.Shared.CCVar;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Content.Client._White.AntiParkinsons;

// The following code is slightly esoteric and higly schizophrenic. You have been warned.

#pragma warning disable RA0002

public sealed class AntiParkinsonsSystem : EntitySystem
{
[Dependency] private readonly IReflectionManager _refl = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;


private bool _enabled = false;

public override void Initialize()
{
UpdatesOutsidePrediction = true;
_cfg.OnValueChanged(WhiteCVars.PixelSnapCamera, OnEnabledDisabled, true);
// eat sand
foreach(Type sys in _refl.GetAllChildren<EntitySystem>())
{
if (sys.IsAbstract || sys == typeof(AntiParkinsonsSystem))
continue;

UpdatesAfter.Add(sys);
}

SubscribeLocalEvent<LocalPlayerAttachedEvent>(OnAttached);
SubscribeLocalEvent<PixelSnapEyeComponent, LocalPlayerDetachedEvent>(OnDetached);
}

private void OnEnabledDisabled(bool val)
{
_enabled = val;
if (_enabled)
{
if (_player.LocalEntity is not EntityUid player)
return;

var ppComp = EnsureComp<PixelSnapEyeComponent>(player);
if (TryComp<EyeComponent>(player, out var eyeComp) && eyeComp.Eye != null)
{
ppComp.EyePosition = eyeComp.Eye.Position;
ppComp.EyePositionModified = eyeComp.Eye.Position;
ppComp.EyeOffset = eyeComp.Eye.Offset;
ppComp.EyeOffsetModified = eyeComp.Eye.Offset;
}
if (TryComp<SpriteComponent>(player, out var sprite))
ppComp.SpriteOffset = sprite.Offset;

}
else
{
if (_player.LocalEntity is not EntityUid player || !TryComp<PixelSnapEyeComponent>(player, out var ppComp))
return;

if (TryComp<EyeComponent>(player, out var eyeComp) && eyeComp.Eye != null)
{
eyeComp.Eye.Position = ppComp.EyePosition;
eyeComp.Eye.Offset = ppComp.EyeOffset;
eyeComp.Offset = ppComp.EyeOffset;
}

if (TryComp<SpriteComponent>(player, out var sprite) && ppComp.SpriteOffset is System.Numerics.Vector2 orig)
sprite.Offset = orig;

RemComp<PixelSnapEyeComponent>(player);
}
}

private void OnAttached(LocalPlayerAttachedEvent args)
{
if (!_enabled)
return;

EnsureComp<PixelSnapEyeComponent>(args.Entity);
}

private void OnDetached(EntityUid uid, PixelSnapEyeComponent comp, LocalPlayerDetachedEvent args)
{
if (!_enabled)
return;

if (TryComp<EyeComponent>(uid, out var eyeComp) && eyeComp.Eye != null)
{
eyeComp.Eye.Position = comp.EyePosition;
eyeComp.Eye.Offset = comp.EyeOffset;
eyeComp.Offset = comp.EyeOffset;
}

if (TryComp<SpriteComponent>(uid, out var sprite) && comp.SpriteOffset is System.Numerics.Vector2 orig)
sprite.Offset = orig;

RemComp<PixelSnapEyeComponent>(uid);
}

public override void FrameUpdate(float frameTime)
{
var query = AllEntityQuery<PixelSnapEyeComponent>();

while (query.MoveNext(out var uid, out var ppComp))
{
if (!TryComp<EyeComponent>(uid, out var eyeComp) || eyeComp.Eye == null)
continue;

if (!TryComp<TransformComponent>(eyeComp.Target, out var xform))
xform = Transform(uid);

if (xform.GridUid.HasValue && xform.GridUid.Value.IsValid())
ppComp.LastParent = xform.GridUid.Value;
else
if (!ppComp.LastParent.IsValid())
ppComp.LastParent = xform.ParentUid; // fallback to whatever parent we have (in this case this will probably end up being the map)

var vec = xform.LocalPosition;
var offset = Vector2.Zero;

ppComp.EyePosition = eyeComp.Eye.Position;
ppComp.EyeOffset = eyeComp.Eye.Offset;

var eyePos = PPCamHelper.WorldPosPixelRoundToParent(eyeComp.Eye.Position.Position, ppComp.LastParent, _transform);
var eyeOffset = PPCamHelper.WorldPosPixelRoundToParent(eyeComp.Eye.Offset, ppComp.LastParent, _transform);
//var eyePosDiff = eyePos - eyeComp.Eye.Position.Position;

eyeComp.Eye.Position = new(eyePos, xform.MapID);
eyeComp.Eye.Offset = eyeOffset;
eyeComp.Offset = eyeOffset;

ppComp.EyePositionModified = eyeComp.Eye.Position;
ppComp.EyeOffsetModified = eyeComp.Eye.Offset;

if (!TryComp<SpriteComponent>(uid, out var sprite))
continue;

ppComp.SpriteOffset = sprite.Offset;

var (_, diff) = PPCamHelper.WorldPosPixelRoundToParentWithDiff(xform.WorldPosition, ppComp.LastParent, _transform);
sprite.Offset += diff;
ppComp.SpriteOffsetModified = sprite.Offset;
}
}
}

#pragma warning restore RA0002
57 changes: 57 additions & 0 deletions Content.Client/_White/AntiParkinsons/PPCamHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Content.Shared._White;
using Content.Shared.CCVar;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Content.Client._White.AntiParkinsons;

public static class PPCamHelper
{
private static int roundFactor => EyeManager.PixelsPerMeter;

public static Vector2 RoundXY(Vector2 vec) => new Vector2(MathF.Round(vec.X * roundFactor) / roundFactor, MathF.Round(vec.Y * roundFactor) / roundFactor);

/// <summary>
/// Translates world vector into local (to parent) vector, rounds it to a 1 over <see cref="EyeManager.PixelsPerMeter"/> and translates back to world space.
/// </summary>
/// <param name="worldPos"></param>
/// <param name="parentXform"></param>
/// <returns></returns>
public static Vector2 WorldPosPixelRoundToParent(Vector2 worldPos, EntityUid parent, SharedTransformSystem xformSystem)
{
var (_, _, mat, invmat) = xformSystem.GetWorldPositionRotationMatrixWithInv(parent);
Vector2 localSpacePos = Vector2.Transform(worldPos, invmat);
localSpacePos = RoundXY(localSpacePos);
Vector2 worldRoundedPos = Vector2.Transform(localSpacePos, mat);
return worldRoundedPos;
}

public static (Vector2 roundedWorldPos, Vector2 LocalSpaceDiff) WorldPosPixelRoundToParentWithDiff(Vector2 worldPos, EntityUid parent, SharedTransformSystem xformSystem)
{
var (_, _, mat, invmat) = xformSystem.GetWorldPositionRotationMatrixWithInv(parent);
Vector2 localSpacePos = Vector2.Transform(worldPos, invmat);
var roundedLocalSpacePos = RoundXY(localSpacePos);
Vector2 worldRoundedPos = Vector2.Transform(localSpacePos, mat);
return (worldRoundedPos, roundedLocalSpacePos - localSpacePos);
}

public static T CheckForChange<T>(T currentValue, T modifiedValue, T originalValue) where T : IEquatable<T>
{
// if this is false, this means that the value tracked was changed outside
// of the engine's FrameUpdate loop, and this change should be preserved.
if (currentValue.Equals(modifiedValue))
return originalValue;
return currentValue;
}
}
32 changes: 32 additions & 0 deletions Content.Client/_White/AntiParkinsons/PixelSnapEyeComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Content.Shared._White;
using Content.Shared.CCVar;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace Content.Client._White.AntiParkinsons;

[RegisterComponent]
[UnsavedComponent]
public sealed partial class PixelSnapEyeComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
public EntityUid LastParent;
[ViewVariables(VVAccess.ReadWrite)]
public System.Numerics.Vector2 SpriteOffset, SpriteOffsetModified;
[ViewVariables(VVAccess.ReadWrite)]
public MapCoordinates EyePosition, EyePositionModified;
[ViewVariables(VVAccess.ReadWrite)]
public System.Numerics.Vector2 EyeOffset, EyeOffsetModified;

}
3 changes: 2 additions & 1 deletion Content.Server/Entry/IgnoredComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public static class IgnoredComponents
"InventorySlots",
"LightFade",
"HolidayRsiSwap",
"OptionsVisualizer"
"OptionsVisualizer",
"PixelSnapEye" // WWDP EDIT
};
}
}
Loading
Loading