mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-17 01:39:38 -06:00
37 lines
985 B
C#
37 lines
985 B
C#
using RMROC451.TweaksAndThings.Patches;
|
|
using Serilog;
|
|
using UnityEngine;
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
namespace RMROC451.TweaksAndThings.Extensions;
|
|
|
|
public static class TextSprite_Extensions
|
|
{
|
|
public static string TriColorPiePercent(this float quantity, float capacity, string name = "")
|
|
{
|
|
int num;
|
|
if (capacity <= 0f)
|
|
{
|
|
num = 0;
|
|
}
|
|
else
|
|
{
|
|
float num2 = Mathf.Clamp01(quantity / capacity);
|
|
int num3 = ((!(num2 < 0.01f)) ? ((!(num2 > 0.99f)) ? (Mathf.FloorToInt(num2 * 15f) + 1) : 16) : 0);
|
|
num = num3;
|
|
}
|
|
string color = "#219106"; //Green
|
|
if (num > 5 && num <= 10)
|
|
{
|
|
color = "#CE8326"; //orange
|
|
} else if (num <= 5)
|
|
{
|
|
color = "#D53427"; //Red
|
|
}
|
|
|
|
string sprite = string.IsNullOrEmpty(name) ? $"Pie{num:D2}" : name;
|
|
|
|
return $"<sprite tint=1 color={color} name={sprite}>";
|
|
}
|
|
}
|