2017-01-11 17:55:42 -08:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using PKHeX.Core;
|
2017-05-11 23:34:18 -05:00
|
|
|
|
using PKHeX.WinForms.Properties;
|
2017-01-11 17:55:42 -08:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
2018-07-20 21:32:33 -07:00
|
|
|
|
public static class SpriteUtil
|
2017-01-11 17:55:42 -08:00
|
|
|
|
{
|
2018-07-14 17:53:37 -07:00
|
|
|
|
public static ISpriteBuilder<Image> Spriter { get; set; } = new SpriteBuilder();
|
2017-07-16 14:05:29 -07:00
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
public static Image GetBallSprite(int ball)
|
2017-01-11 17:55:42 -08:00
|
|
|
|
{
|
2017-06-17 18:37:19 -07:00
|
|
|
|
string str = PKX.GetResourceStringBall(ball);
|
2017-01-11 17:55:42 -08:00
|
|
|
|
return (Image)Resources.ResourceManager.GetObject(str) ?? Resources._ball4; // Poké Ball (default)
|
|
|
|
|
}
|
2017-06-17 18:37:19 -07: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-11 17:55:42 -08:00
|
|
|
|
{
|
2018-07-14 17:53:37 -07:00
|
|
|
|
return Spriter.GetSprite(species, form, gender, item, isegg, shiny, generation, isBoxBGRed);
|
2017-01-11 17:55:42 -08:00
|
|
|
|
}
|
2017-06-17 18:37:19 -07:00
|
|
|
|
public static Image GetRibbonSprite(string name)
|
2017-01-11 17:55:42 -08:00
|
|
|
|
{
|
2017-01-11 22:28:35 -08:00
|
|
|
|
return Resources.ResourceManager.GetObject(name.Replace("CountG3", "G3").ToLower()) as Image;
|
|
|
|
|
}
|
2018-03-18 11:25:57 -07:00
|
|
|
|
public static Image GetTypeSprite(int type, int generation = PKX.Generation)
|
2017-01-11 22:28:35 -08:00
|
|
|
|
{
|
2018-03-18 11:25:57 -07:00
|
|
|
|
if (generation <= 2)
|
|
|
|
|
type = (int)((MoveType)type).GetMoveTypeGeneration(generation);
|
2017-09-29 22:58:25 -07:00
|
|
|
|
return Resources.ResourceManager.GetObject($"type_icon_{type:00}") as Image;
|
2017-01-11 17:55:42 -08:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-18 11:34:23 -08:00
|
|
|
|
private static Image GetSprite(MysteryGift gift)
|
2017-01-11 22:28:35 -08:00
|
|
|
|
{
|
|
|
|
|
if (gift.Empty)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
Image img;
|
2017-06-20 22:19:04 -07:00
|
|
|
|
if (gift.IsEgg && gift.Species == 490) // Manaphy Egg
|
|
|
|
|
img = (Image)(Resources.ResourceManager.GetObject("_490_e") ?? Resources.unknown);
|
|
|
|
|
else if (gift.IsPokémon)
|
2017-11-18 11:34:23 -08:00
|
|
|
|
img = GetSprite(gift.Species, gift.Form, gift.Gender, gift.HeldItem, gift.IsEgg, gift.IsShiny, gift.Format);
|
2017-01-11 22:28:35 -08:00
|
|
|
|
else if (gift.IsItem)
|
2017-09-30 20:57:32 -07:00
|
|
|
|
{
|
|
|
|
|
int item = gift.ItemID;
|
|
|
|
|
if (Legal.ZCrystalDictionary.TryGetValue(item, out int value))
|
|
|
|
|
item = value;
|
|
|
|
|
img = (Image)(Resources.ResourceManager.GetObject("item_" + item) ?? Resources.unknown);
|
|
|
|
|
}
|
2017-01-11 22:28:35 -08:00
|
|
|
|
else
|
|
|
|
|
img = Resources.unknown;
|
|
|
|
|
|
|
|
|
|
if (gift.GiftUsed)
|
|
|
|
|
img = ImageUtil.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3);
|
|
|
|
|
return img;
|
|
|
|
|
}
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private static Image GetSprite(PKM pkm, bool isBoxBGRed = false)
|
2017-03-09 01:46:25 +09:00
|
|
|
|
{
|
2017-06-17 18:37:19 -07:00
|
|
|
|
return GetSprite(pkm.Species, pkm.AltForm, pkm.Gender, pkm.SpriteItem, pkm.IsEgg, pkm.IsShiny, pkm.Format, isBoxBGRed);
|
2017-03-09 01:46:25 +09:00
|
|
|
|
}
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private static Image GetSprite(SaveFile SAV)
|
2017-01-11 22:28:35 -08:00
|
|
|
|
{
|
|
|
|
|
string file = "tr_00";
|
|
|
|
|
if (SAV.Generation == 6 && (SAV.ORAS || SAV.ORASDEMO))
|
2017-09-29 22:58:25 -07:00
|
|
|
|
file = $"tr_{SAV.MultiplayerSpriteID:00}";
|
2017-01-11 22:28:35 -08:00
|
|
|
|
return Resources.ResourceManager.GetObject(file) as Image;
|
|
|
|
|
}
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private static Image GetWallpaper(SaveFile SAV, int box)
|
2017-01-11 17:55:42 -08:00
|
|
|
|
{
|
2017-06-17 18:37:19 -07:00
|
|
|
|
string s = BoxWallpaper.GetWallpaper(SAV, box);
|
2017-01-11 17:55:42 -08:00
|
|
|
|
return (Bitmap)(Resources.ResourceManager.GetObject(s) ?? Resources.box_wp16xy);
|
|
|
|
|
}
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private static Image GetSprite(PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
|
2017-02-04 20:39:42 -08:00
|
|
|
|
{
|
|
|
|
|
if (!pkm.Valid)
|
|
|
|
|
return null;
|
|
|
|
|
|
2017-03-13 14:23:39 +09:00
|
|
|
|
bool inBox = slot >= 0 && slot < 30;
|
2017-06-17 18:37:19 -07:00
|
|
|
|
var sprite = pkm.Species != 0 ? pkm.Sprite(isBoxBGRed: inBox && BoxWallpaper.IsWallpaperRed(SAV, box)) : null;
|
2017-03-08 21:50:34 -08:00
|
|
|
|
|
|
|
|
|
if (slot <= -1) // from tabs
|
|
|
|
|
return sprite;
|
|
|
|
|
|
|
|
|
|
if (flagIllegal)
|
2017-02-04 20:39:42 -08:00
|
|
|
|
{
|
2018-05-21 18:28:54 -07:00
|
|
|
|
if (box >= 0)
|
2017-04-14 17:49:13 -07:00
|
|
|
|
pkm.Box = box;
|
2017-11-06 19:31:24 -08:00
|
|
|
|
var la = new LegalityAnalysis(pkm, SAV.Personal);
|
2018-05-22 18:57:39 -07:00
|
|
|
|
if (!la.Valid && pkm.Species != 0)
|
2018-07-14 18:43:46 -07:00
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.warn, 0, 14);
|
2017-02-04 20:39:42 -08:00
|
|
|
|
}
|
2017-03-08 21:50:34 -08:00
|
|
|
|
if (inBox) // in box
|
|
|
|
|
{
|
2017-06-17 18:37:19 -07:00
|
|
|
|
if (SAV.IsSlotLocked(box, slot))
|
2018-07-14 18:43:46 -07:00
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.locked, 26, 0);
|
2017-06-17 18:37:19 -07:00
|
|
|
|
else if (SAV.IsSlotInBattleTeam(box, slot))
|
2018-07-14 18:43:46 -07:00
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.team, 21, 0);
|
2017-03-08 21:50:34 -08:00
|
|
|
|
}
|
2017-02-04 20:39:42 -08:00
|
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
|
}
|
2017-01-11 22:28:35 -08:00
|
|
|
|
|
|
|
|
|
// Extension Methods
|
2017-06-17 18:37:19 -07:00
|
|
|
|
public static Image WallpaperImage(this SaveFile SAV, int box) => GetWallpaper(SAV, box);
|
2017-11-18 11:34:23 -08:00
|
|
|
|
public static Image Sprite(this MysteryGift gift) => GetSprite(gift);
|
2017-06-17 18:37:19 -07:00
|
|
|
|
public static Image Sprite(this SaveFile SAV) => GetSprite(SAV);
|
|
|
|
|
public static Image Sprite(this PKM pkm, bool isBoxBGRed = false) => GetSprite(pkm, isBoxBGRed);
|
2017-02-04 20:39:42 -08:00
|
|
|
|
public static Image Sprite(this PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
|
2017-06-17 18:37:19 -07:00
|
|
|
|
=> GetSprite(pkm, SAV, box, slot, flagIllegal);
|
2017-01-11 17:55:42 -08:00
|
|
|
|
}
|
|
|
|
|
}
|