mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-05-02 21:17:30 +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>
168 lines
6.7 KiB
C#
168 lines
6.7 KiB
C#
using Content.Shared.Damage;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.Mobs;
|
|
using Content.Shared.Mobs.Components;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Shared.Enums;
|
|
using System.Numerics;
|
|
using Content.Shared.StatusIcon.Components;
|
|
using Content.Client.UserInterface.Systems;
|
|
using Robust.Shared.Prototypes;
|
|
using static Robust.Shared.Maths.Color;
|
|
|
|
namespace Content.Client.Overlays;
|
|
|
|
/// <summary>
|
|
/// Overlay that shows a health bar on mobs.
|
|
/// </summary>
|
|
public sealed class EntityHealthBarOverlay : Overlay
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
|
private readonly IEntityManager _entManager;
|
|
private readonly SharedTransformSystem _transform;
|
|
private readonly MobStateSystem _mobStateSystem;
|
|
private readonly MobThresholdSystem _mobThresholdSystem;
|
|
private readonly ProgressColorSystem _progressColor;
|
|
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
|
|
public HashSet<string> DamageContainers = new();
|
|
private readonly ShaderInstance _shader;
|
|
|
|
public EntityHealthBarOverlay(IEntityManager entManager)
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
_entManager = entManager;
|
|
_transform = _entManager.System<SharedTransformSystem>();
|
|
_mobStateSystem = _entManager.System<MobStateSystem>();
|
|
_mobThresholdSystem = _entManager.System<MobThresholdSystem>();
|
|
_progressColor = _entManager.System<ProgressColorSystem>();
|
|
_shader = _prototype.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>();
|
|
|
|
const float scale = 1f;
|
|
var scaleMatrix = Matrix3.CreateScale(new Vector2(scale, scale));
|
|
var rotationMatrix = Matrix3.CreateRotation(-rotation);
|
|
|
|
handle.UseShader(_shader);
|
|
|
|
var query = _entManager.AllEntityQueryEnumerator<MobThresholdsComponent, MobStateComponent, DamageableComponent, SpriteComponent>();
|
|
while (query.MoveNext(out var uid,
|
|
out var mobThresholdsComponent,
|
|
out var mobStateComponent,
|
|
out var damageableComponent,
|
|
out var spriteComponent))
|
|
{
|
|
if (_entManager.TryGetComponent<MetaDataComponent>(uid, out var metaDataComponent) &&
|
|
metaDataComponent.Flags.HasFlag(MetaDataFlags.InContainer))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!xformQuery.TryGetComponent(uid, out var xform) ||
|
|
xform.MapID != args.MapId)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (damageableComponent.DamageContainerID == null || !DamageContainers.Contains(damageableComponent.DamageContainerID))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// we use the status icon component bounds if specified otherwise use sprite
|
|
var bounds = _entManager.GetComponentOrNull<StatusIconComponent>(uid)?.Bounds ?? spriteComponent.Bounds;
|
|
var worldPos = _transform.GetWorldPosition(xform, xformQuery);
|
|
|
|
if (!bounds.Translated(worldPos).Intersects(args.WorldAABB))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var worldPosition = _transform.GetWorldPosition(xform);
|
|
var worldMatrix = Matrix3.CreateTranslation(worldPosition);
|
|
|
|
Matrix3.Multiply(scaleMatrix, worldMatrix, out var scaledWorld);
|
|
Matrix3.Multiply(rotationMatrix, scaledWorld, out var matty);
|
|
|
|
handle.SetTransform(matty);
|
|
|
|
var yOffset = bounds.Height * EyeManager.PixelsPerMeter / 2 - 3f;
|
|
var widthOfMob = bounds.Width * EyeManager.PixelsPerMeter;
|
|
|
|
var position = new Vector2(-widthOfMob / EyeManager.PixelsPerMeter / 2, yOffset / EyeManager.PixelsPerMeter);
|
|
|
|
// we are all progressing towards death every day
|
|
(float ratio, bool inCrit) deathProgress = CalcProgress(uid, mobStateComponent, damageableComponent, mobThresholdsComponent);
|
|
|
|
var color = GetProgressColor(deathProgress.ratio, deathProgress.inCrit);
|
|
|
|
// Hardcoded width of the progress bar because it doesn't match the texture.
|
|
const float startX = 8f;
|
|
var endX = widthOfMob - 8f;
|
|
|
|
var xProgress = (endX - startX) * deathProgress.ratio + startX;
|
|
|
|
var boxBackground = new Box2(new Vector2(startX, 0f) / EyeManager.PixelsPerMeter, new Vector2(endX, 3f) / EyeManager.PixelsPerMeter);
|
|
boxBackground = boxBackground.Translated(position);
|
|
handle.DrawRect(boxBackground, Black.WithAlpha(192));
|
|
|
|
var boxMain = new Box2(new Vector2(startX, 0f) / EyeManager.PixelsPerMeter, new Vector2(xProgress, 3f) / EyeManager.PixelsPerMeter);
|
|
boxMain = boxMain.Translated(position);
|
|
handle.DrawRect(boxMain, color);
|
|
|
|
var pixelDarken = new Box2(new Vector2(startX, 2f) / EyeManager.PixelsPerMeter, new Vector2(xProgress, 3f) / EyeManager.PixelsPerMeter);
|
|
pixelDarken = pixelDarken.Translated(position);
|
|
handle.DrawRect(pixelDarken, Black.WithAlpha(128));
|
|
}
|
|
|
|
handle.UseShader(null);
|
|
handle.SetTransform(Matrix3.Identity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a ratio between 0 and 1, and whether the entity is in crit.
|
|
/// </summary>
|
|
private (float, bool) CalcProgress(EntityUid uid, MobStateComponent component, DamageableComponent dmg, MobThresholdsComponent thresholds)
|
|
{
|
|
if (_mobStateSystem.IsAlive(uid, component))
|
|
{
|
|
if (!_mobThresholdSystem.TryGetThresholdForState(uid, MobState.Critical, out var threshold, thresholds) &&
|
|
!_mobThresholdSystem.TryGetThresholdForState(uid, MobState.Dead, out threshold, thresholds))
|
|
return (1, false);
|
|
|
|
var ratio = 1 - ((FixedPoint2) (dmg.TotalDamage / threshold)).Float();
|
|
return (ratio, false);
|
|
}
|
|
|
|
if (_mobStateSystem.IsCritical(uid, component))
|
|
{
|
|
if (!_mobThresholdSystem.TryGetThresholdForState(uid, MobState.Critical, out var critThreshold, thresholds) ||
|
|
!_mobThresholdSystem.TryGetThresholdForState(uid, MobState.Dead, out var deadThreshold, thresholds))
|
|
{
|
|
return (1, true);
|
|
}
|
|
|
|
var ratio = 1 - ((dmg.TotalDamage - critThreshold) / (deadThreshold - critThreshold)).Value.Float();
|
|
|
|
return (ratio, true);
|
|
}
|
|
|
|
return (0, true);
|
|
}
|
|
|
|
public Color GetProgressColor(float progress, bool crit)
|
|
{
|
|
if (crit)
|
|
progress = 0;
|
|
|
|
return _progressColor.GetProgressColor(progress);
|
|
}
|
|
}
|