2017-01-12 01:55:42 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using PKHeX.Core;
|
2017-05-12 04:34:18 +00:00
|
|
|
|
using PKHeX.WinForms.Properties;
|
2017-01-12 01:55:42 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
2018-07-21 04:32:33 +00:00
|
|
|
|
public static class SpriteUtil
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2018-07-15 00:53:37 +00:00
|
|
|
|
public static ISpriteBuilder<Image> Spriter { get; set; } = new SpriteBuilder();
|
2017-07-16 21:05:29 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static Image GetBallSprite(int ball)
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
string str = PKX.GetResourceStringBall(ball);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
return (Image)Resources.ResourceManager.GetObject(str) ?? Resources._ball4; // Poké Ball (default)
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static Image GetSprite(int species, int form, int gender, int item, bool isegg, bool shiny, int generation = -1, bool isBoxBGRed = false)
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2018-07-15 00:53:37 +00:00
|
|
|
|
return Spriter.GetSprite(species, form, gender, item, isegg, shiny, generation, isBoxBGRed);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static Image GetRibbonSprite(string name)
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2017-01-12 06:28:35 +00:00
|
|
|
|
return Resources.ResourceManager.GetObject(name.Replace("CountG3", "G3").ToLower()) as Image;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2018-07-29 23:39:15 +00:00
|
|
|
|
public static Image 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
|
|
|
|
|
return name.ToLower() + (max == value ? "2" : "");
|
|
|
|
|
|
|
|
|
|
// Count ribbons
|
|
|
|
|
string n = name.Replace("Count", "");
|
|
|
|
|
switch (value)
|
|
|
|
|
{
|
|
|
|
|
case 2: return (n + "Super").ToLower();
|
|
|
|
|
case 3: return (n + "Hyper").ToLower();
|
|
|
|
|
case 4: return (n + "Master").ToLower();
|
|
|
|
|
default:
|
|
|
|
|
return n.ToLower();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-18 18:25:57 +00:00
|
|
|
|
public static Image GetTypeSprite(int type, int generation = PKX.Generation)
|
2017-01-12 06:28:35 +00:00
|
|
|
|
{
|
2018-03-18 18:25:57 +00:00
|
|
|
|
if (generation <= 2)
|
|
|
|
|
type = (int)((MoveType)type).GetMoveTypeGeneration(generation);
|
2017-09-30 05:58:25 +00:00
|
|
|
|
return Resources.ResourceManager.GetObject($"type_icon_{type:00}") as Image;
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-18 19:34:23 +00:00
|
|
|
|
private static Image GetSprite(MysteryGift gift)
|
2017-01-12 06:28:35 +00:00
|
|
|
|
{
|
|
|
|
|
if (gift.Empty)
|
|
|
|
|
return null;
|
|
|
|
|
|
2018-07-27 02:34:27 +00:00
|
|
|
|
var img = GetBaseImage(gift);
|
|
|
|
|
if (gift.GiftUsed)
|
|
|
|
|
img = ImageUtil.ChangeOpacity(img, 0.3);
|
|
|
|
|
return img;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Image GetBaseImage(MysteryGift gift)
|
|
|
|
|
{
|
2017-06-21 05:19:04 +00:00
|
|
|
|
if (gift.IsEgg && gift.Species == 490) // Manaphy Egg
|
2018-09-03 19:36:46 +00:00
|
|
|
|
return Resources._490_e;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
if (gift.IsPokémon)
|
|
|
|
|
return GetSprite(gift.Species, gift.Form, gift.Gender, gift.HeldItem, gift.IsEgg, gift.IsShiny, gift.Format);
|
|
|
|
|
if (gift.IsItem)
|
2017-10-01 03:57:32 +00:00
|
|
|
|
{
|
|
|
|
|
int item = gift.ItemID;
|
|
|
|
|
if (Legal.ZCrystalDictionary.TryGetValue(item, out int value))
|
|
|
|
|
item = value;
|
2018-09-03 21:23:27 +00:00
|
|
|
|
return (Image)(Resources.ResourceManager.GetObject("item_" + item) ?? Resources.Bag_Key);
|
2017-10-01 03:57:32 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
return Resources.unknown;
|
2017-01-12 06:28:35 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static Image GetSprite(PKM pkm, bool isBoxBGRed = false)
|
2017-03-08 16:46:25 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetSprite(pkm.Species, pkm.AltForm, pkm.Gender, pkm.SpriteItem, pkm.IsEgg, pkm.IsShiny, pkm.Format, isBoxBGRed);
|
2017-03-08 16:46:25 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static Image GetSprite(SaveFile SAV)
|
2017-01-12 06:28:35 +00:00
|
|
|
|
{
|
|
|
|
|
string file = "tr_00";
|
|
|
|
|
if (SAV.Generation == 6 && (SAV.ORAS || SAV.ORASDEMO))
|
2017-09-30 05:58:25 +00:00
|
|
|
|
file = $"tr_{SAV.MultiplayerSpriteID:00}";
|
2017-01-12 06:28:35 +00:00
|
|
|
|
return Resources.ResourceManager.GetObject(file) as Image;
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static Image GetWallpaper(SaveFile SAV, int box)
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2018-08-16 04:15:06 +00:00
|
|
|
|
string s = BoxWallpaper.GetWallpaperResourceName(SAV, box);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
return (Bitmap)(Resources.ResourceManager.GetObject(s) ?? Resources.box_wp16xy);
|
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private static Image GetSprite(PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
|
2017-02-05 04:39:42 +00:00
|
|
|
|
{
|
|
|
|
|
if (!pkm.Valid)
|
|
|
|
|
return null;
|
|
|
|
|
|
2017-03-13 05:23:39 +00:00
|
|
|
|
bool inBox = slot >= 0 && slot < 30;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
var sprite = pkm.Species != 0 ? pkm.Sprite(isBoxBGRed: inBox && BoxWallpaper.IsWallpaperRed(SAV, box)) : null;
|
2017-03-09 05:50:34 +00:00
|
|
|
|
|
|
|
|
|
if (flagIllegal)
|
2017-02-05 04:39:42 +00:00
|
|
|
|
{
|
2018-05-22 01:28:54 +00:00
|
|
|
|
if (box >= 0)
|
2017-04-15 00:49:13 +00:00
|
|
|
|
pkm.Box = box;
|
2017-11-07 03:31:24 +00:00
|
|
|
|
var la = new LegalityAnalysis(pkm, SAV.Personal);
|
2018-05-23 01:57:39 +00:00
|
|
|
|
if (!la.Valid && pkm.Species != 0)
|
2018-07-15 01:43:46 +00:00
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.warn, 0, 14);
|
2017-02-05 04:39:42 +00:00
|
|
|
|
}
|
2017-03-09 05:50:34 +00:00
|
|
|
|
if (inBox) // in box
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (SAV.IsSlotLocked(box, slot))
|
2018-07-15 01:43:46 +00:00
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.locked, 26, 0);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
else if (SAV.IsSlotInBattleTeam(box, slot))
|
2018-07-15 01:43:46 +00:00
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.team, 21, 0);
|
2017-03-09 05:50:34 +00:00
|
|
|
|
}
|
2017-02-05 04:39:42 +00:00
|
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
|
}
|
2017-01-12 06:28:35 +00:00
|
|
|
|
|
2018-07-28 02:59:14 +00:00
|
|
|
|
public static void GetSpriteGlow(PKM pk, byte[] bgr, out byte[] pixels, out Image baseSprite, bool forceHollow = false)
|
|
|
|
|
{
|
|
|
|
|
bool egg = pk.IsEgg;
|
|
|
|
|
baseSprite = GetSprite(pk.Species, pk.AltForm, pk.Gender, 0, egg, false, pk.Format);
|
|
|
|
|
GetSpriteGlow(baseSprite, bgr, out pixels, forceHollow || egg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void GetSpriteGlow(Image baseSprite, byte[] bgr, out byte[] pixels, bool forceHollow = false)
|
|
|
|
|
{
|
|
|
|
|
pixels = ImageUtil.GetPixelData((Bitmap) baseSprite);
|
|
|
|
|
if (!forceHollow)
|
|
|
|
|
{
|
|
|
|
|
ImageUtil.GlowEdges(pixels, bgr, baseSprite.Width);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the image has any transparency, any derived background will bleed into it.
|
|
|
|
|
// Need to undo any transparency values if any present.
|
|
|
|
|
// Remove opaque pixels from original image, leaving only the glow effect pixels.
|
|
|
|
|
var original = (byte[]) pixels.Clone();
|
|
|
|
|
ImageUtil.SetAllUsedPixelsOpaque(pixels);
|
|
|
|
|
ImageUtil.GlowEdges(pixels, bgr, baseSprite.Width);
|
|
|
|
|
ImageUtil.RemovePixels(pixels, original);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 06:28:35 +00:00
|
|
|
|
// Extension Methods
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static Image WallpaperImage(this SaveFile SAV, int box) => GetWallpaper(SAV, box);
|
2017-11-18 19:34:23 +00:00
|
|
|
|
public static Image Sprite(this MysteryGift gift) => GetSprite(gift);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static Image Sprite(this SaveFile SAV) => GetSprite(SAV);
|
|
|
|
|
public static Image Sprite(this PKM pkm, bool isBoxBGRed = false) => GetSprite(pkm, isBoxBGRed);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2017-02-05 04:39:42 +00:00
|
|
|
|
public static Image Sprite(this PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
=> GetSprite(pkm, SAV, box, slot, flagIllegal);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|