Apc variable charge bar color (#240)
* Make Apc chargebar color dependent on charge amount * Adjust orange color and increase brightness
This commit is contained in:
committed by
Pieter-Jan Briers
parent
2afb515a8a
commit
241aa353e9
@@ -3,12 +3,14 @@ using Content.Shared.GameObjects.Components.Power;
|
||||
using NJsonSchema.Validation;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.Interfaces.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Power
|
||||
@@ -65,6 +67,45 @@ namespace Content.Client.GameObjects.Components.Power
|
||||
}
|
||||
|
||||
_chargeBar.Value = castState.Charge;
|
||||
UpdateChargeBarColor(castState.Charge);
|
||||
}
|
||||
|
||||
private void UpdateChargeBarColor(float charge)
|
||||
{
|
||||
float normalizedCharge = charge / _chargeBar.MaxValue;
|
||||
|
||||
float leftHue = 0.0f;// Red
|
||||
float middleHue = 0.066f;// Orange
|
||||
float rightHue = 0.33f;// Green
|
||||
float saturation = 1.0f;// Uniform saturation
|
||||
float value = 0.8f;// Uniform value / brightness
|
||||
float alpha = 1.0f;// Uniform alpha
|
||||
|
||||
// These should add up to 1.0 or your transition won't be smooth
|
||||
float leftSideSize = 0.5f;// Fraction of _chargeBar lerped from leftHue to middleHue
|
||||
float rightSideSize = 0.5f;// Fraction of _chargeBar lerped from middleHue to rightHue
|
||||
|
||||
float finalHue;
|
||||
if (normalizedCharge <= leftSideSize)
|
||||
{
|
||||
normalizedCharge /= leftSideSize;// Adjust range to 0.0 to 1.0
|
||||
finalHue = FloatMath.Lerp(leftHue, middleHue, normalizedCharge);
|
||||
}
|
||||
else
|
||||
{
|
||||
normalizedCharge = (normalizedCharge - leftSideSize) / rightSideSize;// Adjust range to 0.0 to 1.0.
|
||||
finalHue = FloatMath.Lerp(middleHue, rightHue, normalizedCharge);
|
||||
}
|
||||
|
||||
// Check if null first to avoid repeatedly creating this.
|
||||
if (_chargeBar.ForegroundStyleBoxOverride == null)
|
||||
{
|
||||
_chargeBar.ForegroundStyleBoxOverride = new StyleBoxFlat();
|
||||
}
|
||||
|
||||
var foregroundStyleBoxOverride = (StyleBoxFlat)_chargeBar.ForegroundStyleBoxOverride;
|
||||
foregroundStyleBoxOverride.BackgroundColor =
|
||||
Color.FromHsv(new Vector4(finalHue, saturation, value, alpha));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
Reference in New Issue
Block a user