Files
wwdpublic/Content.Client/DoAfter/DoAfterOverlay.cs
SimpleStation14 e4b8f701e3 Mirror: Add a toggle for colorblind friendly progress bar colors (#130)
## Mirror of PR #25318: [Add a toggle for colorblind friendly progress
bar
colors](https://github.com/space-wizards/space-station-14/pull/25318)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `f3f4616c49317898aeeff304160b0b50df9ee851`

PR opened by <img
src="https://avatars.githubusercontent.com/u/98561806?v=4"
width="16"/><a href="https://github.com/EmoGarbage404">
EmoGarbage404</a> at 2024-02-16 17:40:39 UTC
PR merged by <img
src="https://avatars.githubusercontent.com/u/19864447?v=4"
width="16"/><a href="https://github.com/web-flow"> web-flow</a> at
2024-03-09 11:43:20 UTC

---

PR changed 8 files with 169 additions and 84 deletions.

The PR had the following labels:
- Changes: UI
- Status: Needs Review


---

<details open="true"><summary><h1>Original Body</h1></summary>

> <!-- Please read these guidelines before opening your PR:
https://docs.spacestation14.io/en/getting-started/pr-guideline -->
> <!-- The text between the arrows are comments - they will not be
visible on your PR. -->
> 
> ## About the PR
> <!-- What did you change in this PR? -->
> Adds a toggle in the accessibility menu that lets 'progress bars'
(doafters, medhud) toggle between a standard rainbow palette and the
colorblind-friendly Viridis palette.
> 
> also makes the medhud bar unshaded to match the icon and to improve
readability.
> 
> ## Why / Balance
> <!-- Why was it changed? Link any discussions or issues here. Please
discuss how this would affect game balance. -->
> Medical huds used a (frankly) bastardized version of Viridis without
proper smoothing. Doafters used the standard rainbow palette but with
actual smoothing. I personally don't really like the medhud colors, but
i figured if i wanted to get rid of them it was best to unify and make
it an option broadly so that people who needed it could get more use out
of it.
> 
> ## Technical details
> <!-- If this is a code change, summarize at high level how your new
code works. This makes it easier to review. -->
> Makes a new static method in ProgressColorSystem that handles the
CVAR. also adds a new checkbox to MiscTab.xaml
> 
> ## Media
> <!-- 
> PRs which make ingame changes (adding clothing, items, new features,
etc) are required to have media attached that showcase the changes.
> Small fixes/refactors are exempt.
> Any media may be used in SS14 progress reports, with clear credit
given.
> 
> If you're unsure whether your PR will require media, ask a maintainer.
> 
> Check the box below to confirm that you have in fact seen this (put an
X in the brackets, like [X]):
> -->
> 
>
https://github.com/space-wizards/space-station-14/assets/98561806/743c2c31-6504-4693-ab6b-7f54e0d65e06
> 
> - [x] I have added screenshots/videos to this PR showcasing its
changes ingame, **or** this PR does not require an ingame showcase
> 
> **Changelog**
> <!--
> Make players aware of new features and changes that could affect how
they play the game by adding a Changelog entry. Please read the
Changelog guidelines located at:
https://docs.spacestation14.io/en/getting-started/pr-guideline#changelog
> -->
> 
> 🆑
> - add: Added a new "colorblind friendly" toggle in the accessibility
menu. This allows you to toggle between a standard and
colorblind-friendly palette for things like progress bars and the
medical HUD.
> - tweak: The medical HUD is now bright, even in low light levels.
> 


</details>

Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
2024-05-08 23:47:48 -04:00

156 lines
6.4 KiB
C#

using System.Numerics;
using Content.Shared.DoAfter;
using Content.Client.UserInterface.Systems;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Client.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.DoAfter;
public sealed class DoAfterOverlay : Overlay
{
private readonly IEntityManager _entManager;
private readonly IGameTiming _timing;
private readonly IPlayerManager _player;
private readonly SharedTransformSystem _transform;
private readonly MetaDataSystem _meta;
private readonly ProgressColorSystem _progressColor;
private readonly Texture _barTexture;
private readonly ShaderInstance _shader;
/// <summary>
/// Flash time for cancelled DoAfters
/// </summary>
private const float FlashTime = 0.125f;
// Hardcoded width of the progress bar because it doesn't match the texture.
private const float StartX = 2;
private const float EndX = 22f;
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
public DoAfterOverlay(IEntityManager entManager, IPrototypeManager protoManager, IGameTiming timing, IPlayerManager player)
{
_entManager = entManager;
_timing = timing;
_player = player;
_transform = _entManager.EntitySysManager.GetEntitySystem<SharedTransformSystem>();
_meta = _entManager.EntitySysManager.GetEntitySystem<MetaDataSystem>();
_progressColor = _entManager.System<ProgressColorSystem>();
var sprite = new SpriteSpecifier.Rsi(new("/Textures/Interface/Misc/progress_bar.rsi"), "icon");
_barTexture = _entManager.EntitySysManager.GetEntitySystem<SpriteSystem>().Frame0(sprite);
_shader = protoManager.Index<ShaderPrototype>("unshaded").Instance();
}
protected override void Draw(in OverlayDrawArgs args)
{
var handle = args.WorldHandle;
var rotation = args.Viewport.Eye?.Rotation ?? Angle.Zero;
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
// If you use the display UI scale then need to set max(1f, displayscale) because 0 is valid.
const float scale = 1f;
var scaleMatrix = Matrix3.CreateScale(new Vector2(scale, scale));
var rotationMatrix = Matrix3.CreateRotation(-rotation);
handle.UseShader(_shader);
var curTime = _timing.CurTime;
var bounds = args.WorldAABB.Enlarged(5f);
var localEnt = _player.LocalSession?.AttachedEntity;
var metaQuery = _entManager.GetEntityQuery<MetaDataComponent>();
var enumerator = _entManager.AllEntityQueryEnumerator<ActiveDoAfterComponent, DoAfterComponent, SpriteComponent, TransformComponent>();
while (enumerator.MoveNext(out var uid, out _, out var comp, out var sprite, out var xform))
{
if (xform.MapID != args.MapId)
continue;
if (comp.DoAfters.Count == 0)
continue;
var worldPosition = _transform.GetWorldPosition(xform, xformQuery);
if (!bounds.Contains(worldPosition))
continue;
// If the entity is paused, we will draw the do-after as it was when the entity got paused.
var meta = metaQuery.GetComponent(uid);
var time = meta.EntityPaused
? curTime - _meta.GetPauseTime(uid, meta)
: curTime;
var worldMatrix = Matrix3.CreateTranslation(worldPosition);
Matrix3.Multiply(scaleMatrix, worldMatrix, out var scaledWorld);
Matrix3.Multiply(rotationMatrix, scaledWorld, out var matty);
handle.SetTransform(matty);
var offset = 0f;
foreach (var doAfter in comp.DoAfters.Values)
{
// Hide some DoAfters from other players for stealthy actions (ie: thieving gloves)
var alpha = 1f;
if (doAfter.Args.Hidden)
{
if (uid != localEnt)
continue;
// Hints to the local player that this do-after is not visible to other players.
alpha = 0.5f;
}
// Use the sprite itself if we know its bounds. This means short or tall sprites don't get overlapped
// by the bar.
float yOffset = sprite.Bounds.Height / 2f + 0.05f;
// Position above the entity (we've already applied the matrix transform to the entity itself)
// Offset by the texture size for every do_after we have.
var position = new Vector2(-_barTexture.Width / 2f / EyeManager.PixelsPerMeter,
yOffset / scale + offset / EyeManager.PixelsPerMeter * scale);
// Draw the underlying bar texture
handle.DrawTexture(_barTexture, position);
Color color;
float elapsedRatio;
// if we're cancelled then flick red / off.
if (doAfter.CancelledTime != null)
{
var elapsed = doAfter.CancelledTime.Value - doAfter.StartTime;
elapsedRatio = (float) Math.Min(1, elapsed.TotalSeconds / doAfter.Args.Delay.TotalSeconds);
var cancelElapsed = (time - doAfter.CancelledTime.Value).TotalSeconds;
var flash = Math.Floor(cancelElapsed / FlashTime) % 2 == 0;
color = GetProgressColor(0, flash ? alpha : 0);
}
else
{
var elapsed = time - doAfter.StartTime;
elapsedRatio = (float) Math.Min(1, elapsed.TotalSeconds / doAfter.Args.Delay.TotalSeconds);
color = GetProgressColor(elapsedRatio, alpha);
}
var xProgress = (EndX - StartX) * elapsedRatio + StartX;
var box = new Box2(new Vector2(StartX, 3f) / EyeManager.PixelsPerMeter, new Vector2(xProgress, 4f) / EyeManager.PixelsPerMeter);
box = box.Translated(position);
handle.DrawRect(box, color);
offset += _barTexture.Height / scale;
}
}
handle.UseShader(null);
handle.SetTransform(Matrix3.Identity);
}
public Color GetProgressColor(float progress, float alpha = 1f)
{
return _progressColor.GetProgressColor(progress).WithAlpha(alpha);
}
}