-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a576bb
commit f62493a
Showing
14 changed files
with
357 additions
and
7 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Content.Client/ADT/Overlays/Shaders/MonochromacyOverlay.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,46 @@ | ||
// Simple Station | ||
|
||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Enums; | ||
using Robust.Shared.Prototypes; | ||
using Content.Shared.ADT.Traits; | ||
using Matrix3x2 = System.Numerics.Matrix3x2; | ||
|
||
namespace Content.Client.ADT.Overlays | ||
{ | ||
public sealed partial class MonochromacyOverlay : Overlay | ||
{ | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
[Dependency] private readonly IPlayerManager _playerManager = default!; | ||
[Dependency] IEntityManager _entityManager = default!; | ||
|
||
|
||
public override bool RequestScreenTexture => true; | ||
public override OverlaySpace Space => OverlaySpace.WorldSpace; | ||
private readonly ShaderInstance _greyscaleShader; | ||
|
||
public MonochromacyOverlay() | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
_greyscaleShader = _prototypeManager.Index<ShaderPrototype>("GreyscaleFullscreen").InstanceUnique(); | ||
} | ||
|
||
protected override void Draw(in OverlayDrawArgs args) | ||
{ | ||
if (ScreenTexture == null) return; | ||
if (_playerManager.LocalPlayer?.ControlledEntity is not { Valid: true } player) return; | ||
if (!_entityManager.HasComponent<MonochromacyComponent>(player)) return; | ||
|
||
_greyscaleShader?.SetParameter("SCREEN_TEXTURE", ScreenTexture); | ||
|
||
|
||
var worldHandle = args.WorldHandle; | ||
var viewport = args.WorldBounds; | ||
worldHandle.SetTransform(Matrix3x2.Identity); | ||
worldHandle.UseShader(_greyscaleShader); | ||
worldHandle.DrawRect(viewport, Color.White); | ||
worldHandle.UseShader(null); | ||
} | ||
} | ||
} |
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,93 @@ | ||
using Content.Shared.ADT.Silicon.Components; | ||
using Content.Shared.ADT.Silicon.Systems; | ||
using Content.Shared.StatusEffect; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Enums; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Timing; | ||
|
||
|
||
namespace Content.Client.ADT.Overlays.Shaders; | ||
|
||
public sealed class StaticOverlay : Overlay | ||
{ | ||
[Dependency] private readonly IEntityManager _entityManager = default!; | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
[Dependency] private readonly IPlayerManager _playerManager = default!; | ||
|
||
public override OverlaySpace Space => OverlaySpace.WorldSpace; | ||
public override bool RequestScreenTexture => true; | ||
private readonly ShaderInstance _staticShader; | ||
|
||
private (TimeSpan, TimeSpan)? _time; | ||
private float? _fullTimeLeft; | ||
private float? _curTimeLeft; | ||
|
||
public float MixAmount = 0; | ||
|
||
public StaticOverlay() | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
_staticShader = _prototypeManager.Index<ShaderPrototype>("SeeingStatic").InstanceUnique(); | ||
} | ||
|
||
protected override void FrameUpdate(FrameEventArgs args) | ||
{ | ||
var playerEntity = _playerManager.LocalPlayer?.ControlledEntity; | ||
|
||
if (playerEntity == null) | ||
return; | ||
|
||
if (!_entityManager.TryGetComponent<SeeingStaticComponent>(playerEntity, out var staticComp) | ||
|| !_entityManager.TryGetComponent<StatusEffectsComponent>(playerEntity, out var statusComp)) | ||
return; | ||
|
||
var status = _entityManager.EntitySysManager.GetEntitySystem<StatusEffectsSystem>(); | ||
|
||
if (playerEntity == null || statusComp == null) | ||
return; | ||
|
||
if (!status.TryGetTime(playerEntity.Value, SharedSeeingStaticSystem.StaticKey, out var timeTemp, statusComp)) | ||
return; | ||
|
||
if (_time != timeTemp) // Resets the shader if the times change. This should factor in wheather it's a reset, or a increase, but I have a lot of cough syrup in me, so TODO. | ||
{ | ||
_time = timeTemp; | ||
_fullTimeLeft = null; | ||
_curTimeLeft = null; | ||
} | ||
|
||
_fullTimeLeft ??= (float) (timeTemp.Value.Item2 - timeTemp.Value.Item1).TotalSeconds; | ||
_curTimeLeft ??= _fullTimeLeft; | ||
|
||
_curTimeLeft -= args.DeltaSeconds; | ||
|
||
MixAmount = Math.Clamp(_curTimeLeft.Value / _fullTimeLeft.Value * staticComp.Multiplier, 0, 1); | ||
} | ||
|
||
protected override bool BeforeDraw(in OverlayDrawArgs args) | ||
{ | ||
if (!_entityManager.TryGetComponent(_playerManager.LocalPlayer?.ControlledEntity, out EyeComponent? eyeComp)) | ||
return false; | ||
|
||
if (args.Viewport.Eye != eyeComp.Eye) | ||
return false; | ||
|
||
return MixAmount > 0; | ||
} | ||
|
||
protected override void Draw(in OverlayDrawArgs args) | ||
{ | ||
if (ScreenTexture == null) | ||
return; | ||
|
||
var handle = args.WorldHandle; | ||
_staticShader.SetParameter("SCREEN_TEXTURE", ScreenTexture); | ||
_staticShader.SetParameter("mixAmount", MixAmount); | ||
handle.UseShader(_staticShader); | ||
handle.DrawRect(args.WorldBounds, Color.White); | ||
handle.UseShader(null); | ||
} | ||
} |
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,56 @@ | ||
// Simple Station | ||
|
||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Network; | ||
using Content.Shared.ADT.Traits; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Client.ADT.Overlays; | ||
public sealed class MonochromacySystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[Dependency] private readonly IOverlayManager _overlayMan = default!; | ||
[Dependency] private readonly INetManager _net = default!; | ||
[Dependency] private readonly IEntityManager _entityManager = default!; | ||
|
||
private MonochromacyOverlay _overlay = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<MonochromacyComponent, ComponentStartup>(OnMonochromacyStartup); | ||
SubscribeLocalEvent<MonochromacyComponent, ComponentShutdown>(OnMonochromacyShutdown); | ||
|
||
SubscribeLocalEvent<MonochromacyComponent, PlayerAttachedEvent>(OnPlayerAttached); | ||
SubscribeLocalEvent<MonochromacyComponent, PlayerDetachedEvent>(OnPlayerDetached); | ||
|
||
_overlay = new(); | ||
} | ||
|
||
private void OnMonochromacyStartup(EntityUid uid, MonochromacyComponent component, ComponentStartup args) | ||
{ | ||
if (_player.LocalPlayer?.ControlledEntity == uid) | ||
_overlayMan.AddOverlay(_overlay); | ||
} | ||
|
||
private void OnMonochromacyShutdown(EntityUid uid, MonochromacyComponent component, ComponentShutdown args) | ||
{ | ||
if (_player.LocalPlayer?.ControlledEntity == uid) | ||
{ | ||
_overlayMan.RemoveOverlay(_overlay); | ||
} | ||
} | ||
|
||
private void OnPlayerAttached(EntityUid uid, MonochromacyComponent component, PlayerAttachedEvent args) | ||
{ | ||
_overlayMan.AddOverlay(_overlay); | ||
} | ||
|
||
private void OnPlayerDetached(EntityUid uid, MonochromacyComponent component, PlayerDetachedEvent args) | ||
{ | ||
_overlayMan.RemoveOverlay(_overlay); | ||
} | ||
} |
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,57 @@ | ||
using Content.Client.ADT.Overlays.Shaders; | ||
using Content.Shared.ADT.Silicon.Components; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Client.ADT.Overlays; | ||
|
||
/// <summary> | ||
/// System to handle the SeeingStatic overlay. | ||
/// </summary> | ||
public sealed class SeeingStaticSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[Dependency] private readonly IOverlayManager _overlayMan = default!; | ||
|
||
private StaticOverlay _overlay = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<SeeingStaticComponent, ComponentInit>(OnInit); | ||
SubscribeLocalEvent<SeeingStaticComponent, ComponentShutdown>(OnShutdown); | ||
|
||
SubscribeLocalEvent<SeeingStaticComponent, LocalPlayerAttachedEvent>(OnPlayerAttached); | ||
SubscribeLocalEvent<SeeingStaticComponent, LocalPlayerDetachedEvent>(OnPlayerDetached); | ||
|
||
_overlay = new(); | ||
} | ||
|
||
private void OnPlayerAttached(EntityUid uid, SeeingStaticComponent component, LocalPlayerAttachedEvent args) | ||
{ | ||
_overlayMan.AddOverlay(_overlay); | ||
} | ||
|
||
private void OnPlayerDetached(EntityUid uid, SeeingStaticComponent component, LocalPlayerDetachedEvent args) | ||
{ | ||
_overlay.MixAmount = 0; | ||
_overlayMan.RemoveOverlay(_overlay); | ||
} | ||
|
||
private void OnInit(EntityUid uid, SeeingStaticComponent component, ComponentInit args) | ||
{ | ||
if (_player.LocalPlayer?.ControlledEntity == uid) | ||
_overlayMan.AddOverlay(_overlay); | ||
} | ||
|
||
private void OnShutdown(EntityUid uid, SeeingStaticComponent component, ComponentShutdown args) | ||
{ | ||
if (_player.LocalPlayer?.ControlledEntity == uid) | ||
{ | ||
_overlay.MixAmount = 0; | ||
_overlayMan.RemoveOverlay(_overlay); | ||
} | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
Content.Shared/ADT/Traits/Components/MonochromacyComponent.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,15 @@ | ||
// Simple Station | ||
|
||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.ADT.Traits | ||
{ | ||
/// <summary> | ||
/// Entity cannot see color. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent] | ||
public sealed partial class MonochromacyComponent : Component | ||
{ | ||
|
||
} | ||
} |
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,2 @@ | ||
trait-monochromacy-name = Цветовая слепота | ||
trait-monochromacy-description = Ваши глаза получили необратимые повреждения, из-за чего вы видите только в оттенках серого. |
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,6 @@ | ||
# Simple Station | ||
|
||
- type: shader | ||
id: SeeingStatic | ||
kind: source | ||
path: "/Textures/ADT/Shaders/seeing_static.swsl" |
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,4 @@ | ||
# Simple Station | ||
|
||
- type: statusEffect | ||
id: SeeingStatic |
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,9 @@ | ||
# Simple Station | ||
|
||
- type: trait | ||
id: ColorBlindnessMonochrome | ||
name: trait-monochromacy-name | ||
description: trait-monochromacy-description | ||
category: Disabilities | ||
components: | ||
- type: Monochromacy |
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.