NaughtyAttributes icon indicating copy to clipboard operation
NaughtyAttributes copied to clipboard

[Request] "High" value and colours for Progress Bar

Open TheEmbracedOne opened this issue 3 years ago • 1 comments

It would be handy if there was a way to add a high value for progress bars at which point it'd change its colour:

[ProgressBar("Stamina", "maxStamina", EColor.Green, "highStamina", EColor.Yellow)] 
public int stamina = 50;
public int highStamina = 150;
public int maxStamina = 200;

In this example, above 150, the bar would change colour to yellow. Additionally, it'd be great if there was an option to add a third colour for when the bar's value matches max value:

[ProgressBar("Stamina", "maxStamina", EColor.Green, "highStamina", EColor.Yellow, EColor.Red)]

In this example, if stamina reaches 200, the bar becomes red from yellow.

Thank you for your consideration and thank you for making NaughtyAttributes

TheEmbracedOne avatar Apr 25 '21 17:04 TheEmbracedOne

Here if you dont mind to have a try:

_MXLRB4P5$Z}L$3@Z %`X

image

image

[ProgressBar(0, nameof(maxStamina), colorCallback: nameof(StaminaColor), titleCallback: nameof(StaminaTitle))]
[RichLabel(null)]
public int stamina = 50;
public int highStamina = 150;
public int maxStamina = 200;

private Color StaminaColor()
{
    if (stamina < highStamina)
    {
        return Color.red;
    }
    return Color.Lerp(Color.yellow, Color.green, Mathf.InverseLerp(highStamina, maxStamina, stamina));
}

private string StaminaTitle(float curValue, float min, float max, string label) => $"[{label}] {curValue / max:P}";

TylerTemp avatar Jan 25 '24 11:01 TylerTemp