mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
## 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>
78 lines
2.1 KiB
C#
78 lines
2.1 KiB
C#
using Content.Shared.CCVar;
|
|
using Robust.Shared.Configuration;
|
|
|
|
namespace Content.Client.UserInterface.Systems;
|
|
|
|
/// <summary>
|
|
/// This system handles getting an interpolated color based on the value of a cvar.
|
|
/// </summary>
|
|
public sealed class ProgressColorSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IConfigurationManager _configuration = default!;
|
|
|
|
private bool _colorBlindFriendly;
|
|
|
|
private static readonly Color[] Plasma =
|
|
{
|
|
new(240, 249, 33),
|
|
new(248, 149, 64),
|
|
new(204, 71, 120),
|
|
new(126, 3, 168),
|
|
new(13, 8, 135)
|
|
};
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
Subs.CVar(_configuration, CCVars.AccessibilityColorblindFriendly, OnColorBlindFriendlyChanged, true);
|
|
}
|
|
|
|
private void OnColorBlindFriendlyChanged(bool value, in CVarChangeInfo info)
|
|
{
|
|
_colorBlindFriendly = value;
|
|
}
|
|
|
|
public Color GetProgressColor(float progress)
|
|
{
|
|
if (!_colorBlindFriendly)
|
|
{
|
|
if (progress >= 1.0f)
|
|
{
|
|
return new Color(0f, 1f, 0f);
|
|
}
|
|
|
|
// lerp
|
|
var hue = 5f / 18f * progress;
|
|
return Color.FromHsv((hue, 1f, 0.75f, 1f));
|
|
}
|
|
|
|
return InterpolateColorGaussian(Plasma, progress);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Interpolates between multiple colors based on a gaussian distribution.
|
|
/// Taken from https://stackoverflow.com/a/26103117
|
|
/// </summary>
|
|
public static Color InterpolateColorGaussian(Color[] colors, double x)
|
|
{
|
|
double r = 0.0, g = 0.0, b = 0.0;
|
|
var total = 0f;
|
|
var step = 1.0 / (colors.Length - 1);
|
|
var mu = 0.0;
|
|
const double sigma2 = 0.035;
|
|
|
|
foreach(var color in colors)
|
|
{
|
|
var percent = Math.Exp(-(x - mu) * (x - mu) / (2.0 * sigma2)) / Math.Sqrt(2.0 * Math.PI * sigma2);
|
|
total += (float) percent;
|
|
mu += step;
|
|
|
|
r += color.R * percent;
|
|
g += color.G * percent;
|
|
b += color.B * percent;
|
|
}
|
|
|
|
return new Color((float) r / total, (float) g / total, (float) b / total);
|
|
}
|
|
}
|