PKHeX/PKHeX.Drawing.Misc/Util/RibbonSpriteUtil.cs
Kurt d47bb1d297
Update .NET Runtime to .NET 8.0 (#4082)
With the new version of Visual Studio bringing C# 12, we can revise our logic for better readability as well as use new methods/APIs introduced in the .NET 8.0 BCL.
2023-12-03 20:13:20 -08:00

47 lines
1.3 KiB
C#

using System.Drawing;
using PKHeX.Core;
using PKHeX.Drawing.Misc.Properties;
namespace PKHeX.Drawing.Misc;
public static class RibbonSpriteUtil
{
public static Bitmap? GetRibbonSprite(RibbonIndex ribbon)
{
var name = $"Ribbon{ribbon}";
return GetRibbonSprite(name);
}
public static Bitmap? GetRibbonSprite(string name)
{
var resource = name.Replace("CountG3", "G3").ToLowerInvariant();
return (Bitmap?)Resources.ResourceManager.GetObject(resource);
}
public static Bitmap? GetRibbonSprite(string name, int max, int value)
{
var resource = GetRibbonSpriteName(name, max, value);
return (Bitmap?)Resources.ResourceManager.GetObject(resource);
}
private static string GetRibbonSpriteName(string name, int max, int value)
{
if (max != 4) // Memory
{
var sprite = name.ToLowerInvariant();
if (max == value)
return sprite + "2";
return sprite;
}
// Count ribbons
string n = name.Replace("Count", string.Empty).ToLowerInvariant();
return value switch
{
2 => n + "super",
3 => n + "hyper",
4 => n + "master",
_ => n,
};
}
}