Add optional EXP stripe toggle for sprite draw

helps visual identification of suspect EXP values
This commit is contained in:
Kurt 2021-11-07 14:48:59 -08:00
parent 692898fe46
commit b77a197b74
4 changed files with 51 additions and 0 deletions

View file

@ -63,6 +63,19 @@ namespace PKHeX.Drawing
return bmp;
}
public static Bitmap WritePixels(Image img, Color c, int start, int end)
{
var bmp = (Bitmap)img.Clone();
GetBitmapData(bmp, out BitmapData bmpData, out IntPtr ptr, out byte[] data);
Marshal.Copy(ptr, data, 0, data.Length);
ChangeAllTo(data, c, start, end);
Marshal.Copy(data, 0, ptr, data.Length);
bmp.UnlockBits(bmpData);
return bmp;
}
public static Bitmap ToGrayscale(Image img)
{
var bmp = (Bitmap)img.Clone();
@ -146,6 +159,21 @@ namespace PKHeX.Drawing
}
}
public static void ChangeAllTo(byte[] data, Color c, int start, int end)
{
byte R = c.R;
byte G = c.G;
byte B = c.B;
byte A = c.A;
for (int i = start; i < end; i += 4)
{
data[i + 3] = A;
data[i + 2] = R;
data[i + 1] = G;
data[i + 0] = B;
}
}
public static void ChangeAllColorTo(byte[] data, Color c)
{
byte R = c.R;

View file

@ -10,6 +10,7 @@ namespace PKHeX.Drawing
public static bool ShowEncounterBall { get; set; } = true;
public static SpriteBackgroundType ShowEncounterColor { get; set; } = SpriteBackgroundType.FullBackground;
public static SpriteBackgroundType ShowEncounterColorPKM { get; set; }
public static bool ShowExperiencePercent { get; set; }
public static byte ShowEncounterOpacityStripe { get; set; }
public static byte ShowEncounterOpacityBackground { get; set; }
@ -200,6 +201,7 @@ namespace PKHeX.Drawing
ShowEncounterThicknessStripe = sprite.ShowEncounterThicknessStripe;
ShowEncounterOpacityBackground = sprite.ShowEncounterOpacityBackground;
ShowEncounterOpacityStripe = sprite.ShowEncounterOpacityStripe;
ShowExperiencePercent = sprite.ShowExperiencePercent;
}
}
@ -220,6 +222,7 @@ namespace PKHeX.Drawing
int ShowEncounterThicknessStripe { get; set; }
byte ShowEncounterOpacityBackground { get; set; }
byte ShowEncounterOpacityStripe { get; set; }
bool ShowExperiencePercent { get; set; }
}
/// <summary>

View file

@ -177,6 +177,9 @@ namespace PKHeX.Drawing
sprite = ImageUtil.LayerImage(sprite, Resources.starter, 0, 0);
}
if (SpriteBuilder.ShowExperiencePercent)
sprite = ApplyExperience(pk, sprite);
return sprite;
}
@ -197,6 +200,20 @@ namespace PKHeX.Drawing
}
}
private static Image ApplyExperience(PKM pk, Image img)
{
const int bpp = 4;
int start = bpp * SpriteWidth * (SpriteHeight - 1);
var level = pk.CurrentLevel;
if (level == 100)
return ImageUtil.WritePixels(img, Color.Lime, start, start + (SpriteWidth * bpp));
var pct = Experience.GetEXPToLevelUpPercentage(level, pk.EXP, pk.PersonalInfo.EXPGrowth);
if (pct is 0)
return ImageUtil.WritePixels(img, Color.Yellow, start, start + (SpriteWidth * bpp));
return ImageUtil.WritePixels(img, Color.DodgerBlue, start, start + (int)(SpriteWidth * pct * bpp));
}
private const int MaxSlotCount = 30; // slots in a box
private static int SpriteWidth => Spriter.Width;
private static int SpriteHeight => Spriter.Height;

View file

@ -372,6 +372,9 @@ namespace PKHeX.WinForms
[LocalizedDescription("Opacity for the Encounter Type stripe layer.")]
public byte ShowEncounterOpacityStripe { get; set; } = 0x5F; // 0xFF opaque
[LocalizedDescription("Show a thin stripe to indicate the percent of level-up progress")]
public bool ShowExperiencePercent { get; set; }
[LocalizedDescription("Amount of pixels thick to show when displaying the encounter type color stripe.")]
public int ShowEncounterThicknessStripe { get; set; } = 4; // pixels
}