File scoped namespace for drawing projects

Extract color util to separate class as it's not entirely image related.
This commit is contained in:
Kurt 2021-12-10 00:15:04 -08:00
parent 9f920405df
commit aa968f56aa
25 changed files with 1095 additions and 1126 deletions

View file

@ -53,9 +53,7 @@ public static class ContestStatInfo
return initial.CNT_Sheen;
if (pokeBlock3)
{
return CalculateMaximumSheen3(s, nature, initial);
}
var avg = GetAverageFeel(s, nature, initial);
if (avg <= 0)

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>net6.0;net46</TargetFrameworks>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

View file

@ -5,10 +5,10 @@ using System.Text;
using System.Text.RegularExpressions;
using PKHeX.Core;
namespace PKHeX.Drawing.Misc
namespace PKHeX.Drawing.Misc;
public static class QRDecode
{
public static class QRDecode
{
// QR Utility
private const string DecodeAPI = "http://api.qrserver.com/v1/read-qr-code/?fileurl=";
@ -35,9 +35,7 @@ namespace PKHeX.Drawing.Misc
if (data.Contains("filetype not supported"))
return QRDecodeResult.BadType;
}
#pragma warning disable CA1031 // Do not catch general exception types
catch { return QRDecodeResult.BadConnection; }
#pragma warning restore CA1031 // Do not catch general exception types
// Quickly convert the json response to a data string
try
@ -45,9 +43,7 @@ namespace PKHeX.Drawing.Misc
result = DecodeQRJson(data);
return QRDecodeResult.Success;
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
{
Debug.WriteLine(e.Message);
return QRDecodeResult.BadConversion;
@ -104,5 +100,4 @@ namespace PKHeX.Drawing.Misc
QRDecodeResult.BadConversion => MessageStrings.MsgQRUrlFailConvert,
_ => throw new ArgumentOutOfRangeException(nameof(result), result, null),
};
}
}

View file

@ -1,12 +1,11 @@
namespace PKHeX.Drawing.Misc
namespace PKHeX.Drawing.Misc;
public enum QRDecodeResult
{
public enum QRDecodeResult
{
Success,
BadPath,
BadImage,
BadType,
BadConnection,
BadConversion,
}
}

View file

@ -2,10 +2,10 @@
using PKHeX.Core;
using QRCoder;
namespace PKHeX.Drawing.Misc
namespace PKHeX.Drawing.Misc;
public static class QREncode
{
public static class QREncode
{
public static Image GenerateQRCode(DataMysteryGift mg) => GenerateQRCode(QRMessageUtil.GetMessage(mg));
public static Image GenerateQRCode(PKM pkm) => GenerateQRCode(QRMessageUtil.GetMessage(pkm));
@ -23,5 +23,4 @@ namespace PKHeX.Drawing.Misc
using var code = new QRCode(data);
return code.GetGraphic(ppm);
}
}
}

View file

@ -1,10 +1,10 @@
using System;
using System.Drawing;
namespace PKHeX.Drawing.Misc
namespace PKHeX.Drawing.Misc;
public static class QRImageUtil
{
public static class QRImageUtil
{
public static Bitmap GetQRImage(Image qr, Image preview)
{
// create a small area with the pkm sprite, with a white background
@ -47,5 +47,4 @@ namespace PKHeX.Drawing.Misc
}
private static string GetLine(string[] lines, int line) => lines.Length <= line ? string.Empty : lines[line];
}
}

View file

@ -3,10 +3,10 @@ using PKHeX.Core;
using PKHeX.Drawing.Misc.Properties;
using PKHeX.Drawing.PokeSprite;
namespace PKHeX.Drawing.Misc
namespace PKHeX.Drawing.Misc;
public static class MysteryGiftSpriteUtil
{
public static class MysteryGiftSpriteUtil
{
public static Image Sprite(this MysteryGift gift) => GetSprite(gift);
private static Image GetSprite(MysteryGift gift)
@ -38,5 +38,4 @@ namespace PKHeX.Drawing.Misc
}
return PokeSprite.Properties.Resources.b_unknown;
}
}
}

View file

@ -2,10 +2,10 @@
using PKHeX.Core;
using PKHeX.Drawing.Misc.Properties;
namespace PKHeX.Drawing.Misc
namespace PKHeX.Drawing.Misc;
public static class PlayerSpriteUtil
{
public static class PlayerSpriteUtil
{
public static Image? Sprite(this SaveFile sav) => GetSprite(sav);
private static Image? GetSprite(SaveFile sav)
@ -17,5 +17,4 @@ namespace PKHeX.Drawing.Misc
}
return null;
}
}
}

View file

@ -1,10 +1,10 @@
using System.Drawing;
using PKHeX.Drawing.Misc.Properties;
namespace PKHeX.Drawing.Misc
namespace PKHeX.Drawing.Misc;
public static class RibbonSpriteUtil
{
public static class RibbonSpriteUtil
{
public static Image? GetRibbonSprite(string name)
{
var resource = name.Replace("CountG3", "G3").ToLowerInvariant();
@ -37,5 +37,4 @@ namespace PKHeX.Drawing.Misc
_ => n,
};
}
}
}

View file

@ -2,15 +2,14 @@
using PKHeX.Core;
using PKHeX.Drawing.Misc.Properties;
namespace PKHeX.Drawing.Misc
namespace PKHeX.Drawing.Misc;
public static class TypeSpriteUtil
{
public static class TypeSpriteUtil
{
public static Image? GetTypeSprite(int type, int generation = PKX.Generation)
{
if (generation <= 2)
type = (int)((MoveType)type).GetMoveTypeGeneration(generation);
return (Bitmap?)Resources.ResourceManager.GetObject($"type_icon_{type:00}");
}
}
}

View file

@ -3,10 +3,10 @@ using PKHeX.Core;
using PKHeX.Drawing.Misc.Properties;
using static PKHeX.Core.GameVersion;
namespace PKHeX.Drawing.Misc
namespace PKHeX.Drawing.Misc;
public static class WallpaperUtil
{
public static class WallpaperUtil
{
public static Image WallpaperImage(this SaveFile sav, int box) => GetWallpaper(sav, box);
private static Image GetWallpaper(SaveFile sav, int box)
@ -38,5 +38,4 @@ namespace PKHeX.Drawing.Misc
8 => BDSP.Contains(version) ? "bdsp" : "swsh",
_ => string.Empty,
};
}
}

View file

@ -1,7 +1,7 @@
namespace PKHeX.Drawing.PokeSprite
namespace PKHeX.Drawing.PokeSprite;
public interface ISpriteSettings
{
public interface ISpriteSettings
{
bool ShowEggSpriteAsHeldItem { get; set; }
bool ShowEncounterBall { get; set; }
@ -11,5 +11,4 @@
byte ShowEncounterOpacityBackground { get; set; }
byte ShowEncounterOpacityStripe { get; set; }
bool ShowExperiencePercent { get; set; }
}
}

View file

@ -1,9 +1,8 @@
namespace PKHeX.Drawing.PokeSprite
namespace PKHeX.Drawing.PokeSprite;
public enum SpriteBackgroundType
{
public enum SpriteBackgroundType
{
None,
BottomStripe,
FullBackground,
}
}

View file

@ -2,10 +2,10 @@
using PKHeX.Core;
using PKHeX.Drawing.PokeSprite.Properties;
namespace PKHeX.Drawing.PokeSprite
namespace PKHeX.Drawing.PokeSprite;
public abstract class SpriteBuilder : ISpriteBuilder<Image>
{
public abstract class SpriteBuilder : ISpriteBuilder<Image>
{
public static bool ShowEggSpriteAsItem { get; set; } = true;
public static bool ShowEncounterBall { get; set; } = true;
public static SpriteBackgroundType ShowEncounterColor { get; set; } = SpriteBackgroundType.FullBackground;
@ -204,5 +204,4 @@ namespace PKHeX.Drawing.PokeSprite
ShowEncounterOpacityStripe = sprite.ShowEncounterOpacityStripe;
ShowExperiencePercent = sprite.ShowExperiencePercent;
}
}
}

View file

@ -2,13 +2,13 @@
using PKHeX.Core;
using PKHeX.Drawing.PokeSprite.Properties;
namespace PKHeX.Drawing.PokeSprite
namespace PKHeX.Drawing.PokeSprite;
/// <summary>
/// 56 high, 68 wide sprite builder
/// </summary>
public sealed class SpriteBuilder5668 : SpriteBuilder
{
/// <summary>
/// 56 high, 68 wide sprite builder
/// </summary>
public sealed class SpriteBuilder5668 : SpriteBuilder
{
public override int Height => 56;
public override int Width => 68;
@ -35,5 +35,4 @@ namespace PKHeX.Drawing.PokeSprite
public override Bitmap ItemTM => Resources.bitem_tm;
public override Bitmap ItemTR => Resources.bitem_tr;
public override Bitmap ShadowLugia => Resources.b_249x;
}
}

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>net6.0;net46</TargetFrameworks>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

View file

@ -1,35 +1,28 @@
using PKHeX.Core;
using static PKHeX.Core.GameVersion;
namespace PKHeX.Drawing.PokeSprite
{
internal static class BoxWallpaper
{
public static bool IsWallpaperRed(GameVersion version, int wallpaperID)
{
switch (version.GetGeneration())
{
case 3:
if (CXD.Contains(version))
return wallpaperID == 7; // flame pattern in XD
namespace PKHeX.Drawing.PokeSprite;
return wallpaperID switch
internal static class BoxWallpaper
{
public static bool IsWallpaperRed(GameVersion version, int wallpaperID) => version.GetGeneration() switch
{
3 when CXD.Contains(version) => wallpaperID == 7, // flame pattern in XD
3 => wallpaperID switch
{
5 => true, // Volcano
13 => E == version, // PokéCenter
_ => false,
};
case 4:
return wallpaperID switch
},
4 => wallpaperID switch
{
5 => true, // Volcano
12 => true, // Checks
13 => true, // PokéCenter
22 => true, // Special
_ => false,
};
case 5:
return wallpaperID switch
},
5 => wallpaperID switch
{
5 => true, // Volcano
12 => true, // Checks
@ -38,17 +31,15 @@ namespace PKHeX.Drawing.PokeSprite
21 => BW.Contains(version), // Zoroark
23 => BW.Contains(version), // Musical
_ => false,
};
case 6 or 7:
return wallpaperID switch
},
6 or 7 => wallpaperID switch
{
5 => true, // Volcano
12 => true, // PokéCenter
20 => true, // Special5 Flare/Magma
_ => false,
};
case 8 when BDSP.Contains(version):
return wallpaperID switch
},
8 when BDSP.Contains(version) => wallpaperID switch
{
6 => true, // Volcano
15 => true, // Checks
@ -56,15 +47,8 @@ namespace PKHeX.Drawing.PokeSprite
29 => true, // Nostalgic (Platinum)
30 => true, // Legend (Platinum)
_ => false,
},
8 => true, // Bad contrast with lots of void space, better to just highlight the shiny red.
_ => false,
};
case 8:
return wallpaperID switch
{
_ => true, // Bad contrast with lots of void space, better to just highlight the shiny red.
};
default:
return false;
}
}
}
}

View file

@ -2,10 +2,10 @@
using System.Text;
using PKHeX.Core;
namespace PKHeX.Drawing.PokeSprite
namespace PKHeX.Drawing.PokeSprite;
public static class SpriteName
{
public static class SpriteName
{
public static bool AllowShinySprite { get; set; }
private const char Separator = '_';
@ -96,5 +96,4 @@ namespace PKHeX.Drawing.PokeSprite
(int)Species.Jellicent,
(int)Species.Pyroar,
};
}
}

View file

@ -4,10 +4,10 @@ using System.Linq;
using PKHeX.Core;
using PKHeX.Drawing.PokeSprite.Properties;
namespace PKHeX.Drawing.PokeSprite
namespace PKHeX.Drawing.PokeSprite;
public static class SpriteUtil
{
public static class SpriteUtil
{
public static readonly SpriteBuilder5668 SB8 = new();
public static SpriteBuilder Spriter { get; set; } = SB8;
@ -222,5 +222,4 @@ namespace PKHeX.Drawing.PokeSprite
}
return img;
}
}
}

View file

@ -0,0 +1,29 @@
using System;
using System.Drawing;
namespace PKHeX.Drawing;
public static class ColorUtil
{
public static Color ColorBaseStat(int v)
{
const float maxval = 180; // shift the green cap down
float x = 100f * v / maxval;
if (x > 100)
x = 100;
double red = 255f * (x > 50 ? 1 - (2 * (x - 50) / 100.0) : 1.0);
double green = 255f * (x > 50 ? 1.0 : 2 * x / 100.0);
return Blend(Color.FromArgb((int)red, (int)green, 0), Color.White, 0.4);
}
public static Color ColorBaseStatTotal(int tot) => ColorBaseStat((int) (Math.Max(0, tot - 175) / 3f));
public static Color Blend(Color color, Color backColor, double amount)
{
byte r = (byte)((color.R * amount) + (backColor.R * (1 - amount)));
byte g = (byte)((color.G * amount) + (backColor.G * (1 - amount)));
byte b = (byte)((color.B * amount) + (backColor.B * (1 - amount)));
return Color.FromArgb(r, g, b);
}
}

View file

@ -3,13 +3,13 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace PKHeX.Drawing
namespace PKHeX.Drawing;
/// <summary>
/// Image Layering/Blending Utility
/// </summary>
public static class ImageUtil
{
/// <summary>
/// Image Layering/Blending Utility
/// </summary>
public static class ImageUtil
{
public static Bitmap LayerImage(Image baseLayer, Image overLayer, int x, int y, double transparency)
{
overLayer = ChangeOpacity(overLayer, transparency);
@ -261,27 +261,4 @@ namespace PKHeX.Drawing
data[i + 3] = transparency;
}
}
public static Color ColorBaseStat(int v)
{
const float maxval = 180; // shift the green cap down
float x = 100f * v / maxval;
if (x > 100)
x = 100;
double red = 255f * (x > 50 ? 1 - (2 * (x - 50) / 100.0) : 1.0);
double green = 255f * (x > 50 ? 1.0 : 2 * x / 100.0);
return Blend(Color.FromArgb((int)red, (int)green, 0), Color.White, 0.4);
}
public static Color ColorBaseStatTotal(int tot) => ColorBaseStat((int) (Math.Max(0, tot - 175) / 3f));
public static Color Blend(Color color, Color backColor, double amount)
{
byte r = (byte)((color.R * amount) + (backColor.R * (1 - amount)));
byte g = (byte)((color.G * amount) + (backColor.G * (1 - amount)));
byte b = (byte)((color.B * amount) + (backColor.B * (1 - amount)));
return Color.FromArgb(r, g, b);
}
}
}

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>net6.0;net46</TargetFrameworks>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>

View file

@ -368,11 +368,11 @@ namespace PKHeX.WinForms.Controls
for (int i = 0; i < stats.Count; i++)
{
MT_Base[i].Text = stats[i].ToString("000");
MT_Base[i].BackColor = ImageUtil.ColorBaseStat(stats[i]);
MT_Base[i].BackColor = ColorUtil.ColorBaseStat(stats[i]);
}
var bst = pi.Stats.Sum();
TB_BST.Text = bst.ToString("000");
TB_BST.BackColor = ImageUtil.ColorBaseStatTotal(bst);
TB_BST.BackColor = ColorUtil.ColorBaseStatTotal(bst);
}
public void UpdateRandomIVs(object sender, EventArgs e)

View file

@ -114,6 +114,6 @@ namespace PKHeX.WinForms.Controls
return cache[frameIndex] = frame;
}
private Color GetFrameColor(double elapsedFraction) => ImageUtil.Blend(GlowToColor, GlowFromColor, elapsedFraction);
private Color GetFrameColor(double elapsedFraction) => ColorUtil.Blend(GlowToColor, GlowFromColor, elapsedFraction);
}
}

View file

@ -55,22 +55,22 @@ namespace PKHeX.WinForms
row.Cells[r++].Value = SpriteUtil.GetSprite(s, f, 0, 0, 0, false, false, SAV.Generation);
row.Cells[r++].Value = species[index];
row.Cells[r++].Value = GetIsNative(p, s);
row.Cells[r].Style.BackColor = ImageUtil.ColorBaseStatTotal(p.BST);
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStatTotal(p.BST);
row.Cells[r++].Value = p.BST.ToString("000");
row.Cells[r++].Value = p.CatchRate.ToString("000");
row.Cells[r++].Value = TypeSpriteUtil.GetTypeSprite(p.Type1, SAV.Generation);
row.Cells[r++].Value = p.Type1 == p.Type2 ? SpriteUtil.Spriter.Transparent : TypeSpriteUtil.GetTypeSprite(p.Type2, SAV.Generation);
row.Cells[r].Style.BackColor = ImageUtil.ColorBaseStat(p.HP);
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.HP);
row.Cells[r++].Value = p.HP.ToString("000");
row.Cells[r].Style.BackColor = ImageUtil.ColorBaseStat(p.ATK);
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.ATK);
row.Cells[r++].Value = p.ATK.ToString("000");
row.Cells[r].Style.BackColor = ImageUtil.ColorBaseStat(p.DEF);
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.DEF);
row.Cells[r++].Value = p.DEF.ToString("000");
row.Cells[r].Style.BackColor = ImageUtil.ColorBaseStat(p.SPA);
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.SPA);
row.Cells[r++].Value = p.SPA.ToString("000");
row.Cells[r].Style.BackColor = ImageUtil.ColorBaseStat(p.SPD);
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.SPD);
row.Cells[r++].Value = p.SPD.ToString("000");
row.Cells[r].Style.BackColor = ImageUtil.ColorBaseStat(p.SPE);
row.Cells[r].Style.BackColor = ColorUtil.ColorBaseStat(p.SPE);
row.Cells[r++].Value = p.SPE.ToString("000");
var abils = p.Abilities;
row.Cells[r++].Value = GetAbility(abils, 0);