Revert to old cooldown and unify with DoAfter (#2469)

Co-authored-by: Tomeno <tomeno@lulzsec.co.uk>
This commit is contained in:
Tomeno
2020-11-02 11:32:03 +01:00
committed by GitHub
parent b5d48e4db0
commit 015539dcdc
2 changed files with 14 additions and 26 deletions

View File

@@ -56,23 +56,20 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
/// Is the cancellation bar red? /// Is the cancellation bar red?
/// </summary> /// </summary>
private bool _flash = true; private bool _flash = true;
/// <summary> /// <summary>
/// Last time we swapped the flash. /// Last time we swapped the flash.
/// </summary> /// </summary>
private TimeSpan _lastFlash; private TimeSpan _lastFlash;
/// <summary> /// <summary>
/// How long each cancellation bar flash lasts in seconds. /// How long each cancellation bar flash lasts in seconds.
/// </summary> /// </summary>
private const float FlashTime = 0.125f; private const float FlashTime = 0.125f;
private const int XPixelDiff = 20 * DoAfterBarScale; private const int XPixelDiff = 20 * DoAfterBarScale;
public const byte DoAfterBarScale = 2; public const byte DoAfterBarScale = 2;
private static readonly Color StartColor = new Color(0.8f, 0.0f, 0.2f); // red
private static readonly Color EndColor = new Color(0.92f, 0.77f, 0.34f); // yellow
private static readonly Color CompletedColor = new Color(0.0f, 0.8f, 0.27f); // green
public DoAfterBar() public DoAfterBar()
{ {
@@ -108,28 +105,25 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
} }
color = new Color(1.0f, 0.0f, 0.0f, _flash ? 1.0f : 0.0f); color = new Color(1.0f, 0.0f, 0.0f, _flash ? 1.0f : 0.0f);
} }
else if (Ratio >= 1.0f) else if (Ratio >= 1.0f)
{ {
color = CompletedColor; color = new Color(0f, 1f, 0f);
} }
else else
{ {
// lerp // lerp
color = new Color( var hue = (5f / 18f) * Ratio;
StartColor.R + (EndColor.R - StartColor.R) * Ratio, color = Color.FromHsv((hue, 1f, 0.75f, 1f));
StartColor.G + (EndColor.G - StartColor.G) * Ratio,
StartColor.B + (EndColor.B - StartColor.B) * Ratio,
StartColor.A);
} }
handle.UseShader(_shader); handle.UseShader(_shader);
// If you want to make this less hard-coded be my guest // If you want to make this less hard-coded be my guest
var leftOffset = 2 * DoAfterBarScale; var leftOffset = 2 * DoAfterBarScale;
var box = new UIBox2i( var box = new UIBox2i(
leftOffset, leftOffset,
-2 + 2 * DoAfterBarScale, -2 + 2 * DoAfterBarScale,
leftOffset + (int) (XPixelDiff * Ratio), leftOffset + (int) (XPixelDiff * Ratio),
-2); -2);
handle.DrawRect(box, color); handle.DrawRect(box, color);
} }

View File

@@ -27,29 +27,23 @@ namespace Content.Client.UserInterface
/// Possible values range from 1 to -1, where 1 to 0 is a depleting circle animation and 0 to -1 is a blink animation. /// Possible values range from 1 to -1, where 1 to 0 is a depleting circle animation and 0 to -1 is a blink animation.
/// </summary> /// </summary>
public float Progress { get; set; } public float Progress { get; set; }
private static readonly Color StartColor = new Color(0.8f, 0.0f, 0.2f); // red
private static readonly Color EndColor = new Color(0.92f, 0.77f, 0.34f); // yellow
private static readonly Color CompletedColor = new Color(0.0f, 0.8f, 0.27f); // green
protected override void Draw(DrawingHandleScreen handle) protected override void Draw(DrawingHandleScreen handle)
{ {
Span<float> x = stackalloc float[10]; Span<float> x = new float[10];
Color color; Color color;
var lerp = 1f - MathF.Abs(Progress); // for future bikeshedding purposes var lerp = 1f - MathF.Abs(Progress); // for future bikeshedding purposes
if (Progress >= 0f) if (Progress >= 0f)
{ {
color = new Color( var hue = (5f / 18f) * lerp;
EndColor.R + (StartColor.R - EndColor.R) * Progress, color = Color.FromHsv((hue, 0.75f, 0.75f, 0.50f));
EndColor.G + (StartColor.G - EndColor.G) * Progress,
EndColor.B + (StartColor.B - EndColor.B) * Progress,
EndColor.A);
} }
else else
{ {
var alpha = MathHelper.Clamp(0.5f * lerp, 0f, 0.5f); var alpha = MathHelper.Clamp(0.5f * lerp, 0f, 0.5f);
color = CompletedColor.WithAlpha(alpha); color = new Color(1f, 1f, 1f, alpha);
} }
_shader.SetParameter("progress", Progress); _shader.SetParameter("progress", Progress);