2017-01-12 01:55:42 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using PKHeX.Core.Properties;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
|
|
|
|
public static class PKMUtil
|
|
|
|
|
{
|
|
|
|
|
public static Image getBallSprite(int ball)
|
|
|
|
|
{
|
|
|
|
|
string str = PKX.getBallString(ball);
|
|
|
|
|
return (Image)Resources.ResourceManager.GetObject(str) ?? Resources._ball4; // Poké Ball (default)
|
|
|
|
|
}
|
2017-03-08 16:46:25 +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
|
|
|
|
{
|
|
|
|
|
if (species == 0)
|
2017-01-12 06:28:35 +00:00
|
|
|
|
return Resources._0;
|
2017-01-12 01:55:42 +00:00
|
|
|
|
|
|
|
|
|
string file = PKX.getSpriteString(species, form, gender, generation);
|
|
|
|
|
|
|
|
|
|
// Redrawing logic
|
|
|
|
|
Image baseImage = (Image)Resources.ResourceManager.GetObject(file);
|
|
|
|
|
if (baseImage == null)
|
|
|
|
|
{
|
2017-01-12 06:28:35 +00:00
|
|
|
|
baseImage = (Image) Resources.ResourceManager.GetObject("_" + species);
|
|
|
|
|
baseImage = baseImage != null ? ImageUtil.LayerImage(baseImage, Resources.unknown, 0, 0, .5) : Resources.unknown;
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
if (isegg)
|
|
|
|
|
{
|
2017-02-05 07:42:55 +00:00
|
|
|
|
// Partially transparent species.
|
|
|
|
|
baseImage = ImageUtil.ChangeOpacity(baseImage, 0.33);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
// Add the egg layer over-top with full opacity.
|
2017-01-12 06:28:35 +00:00
|
|
|
|
baseImage = ImageUtil.LayerImage(baseImage, Resources.egg, 0, 0, 1);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
if (shiny)
|
|
|
|
|
{
|
|
|
|
|
// Add shiny star to top left of image.
|
2017-03-09 05:50:34 +00:00
|
|
|
|
var rare = isBoxBGRed ? Resources.rare_icon_alt : Resources.rare_icon;
|
|
|
|
|
baseImage = ImageUtil.LayerImage(baseImage, rare, 0, 0, 0.7);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
if (item > 0)
|
|
|
|
|
{
|
|
|
|
|
Image itemimg = (Image)Resources.ResourceManager.GetObject("item_" + item) ?? Resources.helditem;
|
|
|
|
|
if (generation >= 2 && generation <= 4 && 328 <= item && item <= 419) // gen2/3/4 TM
|
|
|
|
|
itemimg = Resources.item_tm;
|
|
|
|
|
|
|
|
|
|
// Redraw
|
2017-03-09 05:50:34 +00:00
|
|
|
|
int x = 22 + (15 - itemimg.Width)/2;
|
|
|
|
|
int y = 15 + (15 - itemimg.Height);
|
|
|
|
|
baseImage = ImageUtil.LayerImage(baseImage, itemimg, x, y, 1);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
return baseImage;
|
|
|
|
|
}
|
2017-01-12 06:28:35 +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;
|
|
|
|
|
}
|
|
|
|
|
public static Image getTypeSprite(int type)
|
|
|
|
|
{
|
|
|
|
|
return Resources.ResourceManager.GetObject("type_icon_" + type.ToString("00")) as Image;
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 06:28:35 +00:00
|
|
|
|
private static Image getSprite(MysteryGift gift)
|
|
|
|
|
{
|
|
|
|
|
if (gift.Empty)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
Image img;
|
|
|
|
|
if (gift.IsPokémon)
|
|
|
|
|
img = getSprite(gift.convertToPKM(Main.SAV));
|
|
|
|
|
else if (gift.IsItem)
|
|
|
|
|
img = (Image)(Resources.ResourceManager.GetObject("item_" + gift.Item) ?? Resources.unknown);
|
|
|
|
|
else
|
|
|
|
|
img = Resources.unknown;
|
|
|
|
|
|
|
|
|
|
if (gift.GiftUsed)
|
|
|
|
|
img = ImageUtil.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3);
|
|
|
|
|
return img;
|
|
|
|
|
}
|
2017-03-09 05:50:34 +00:00
|
|
|
|
private static Image getSprite(PKM pkm, bool isBoxBGRed = false)
|
2017-03-08 16:46:25 +00:00
|
|
|
|
{
|
|
|
|
|
return getSprite(pkm.Species, pkm.AltForm, pkm.Gender, pkm.SpriteItem, pkm.IsEgg, pkm.IsShiny, pkm.Format, isBoxBGRed);
|
|
|
|
|
}
|
2017-01-12 06:28:35 +00:00
|
|
|
|
private static Image getSprite(SaveFile SAV)
|
|
|
|
|
{
|
|
|
|
|
string file = "tr_00";
|
|
|
|
|
if (SAV.Generation == 6 && (SAV.ORAS || SAV.ORASDEMO))
|
|
|
|
|
file = "tr_" + SAV.MultiplayerSpriteID.ToString("00");
|
|
|
|
|
return Resources.ResourceManager.GetObject(file) as Image;
|
|
|
|
|
}
|
|
|
|
|
private static Image getWallpaper(SaveFile SAV, int box)
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
|
|
|
|
string s = BoxWallpaper.getWallpaper(SAV, box);
|
|
|
|
|
return (Bitmap)(Resources.ResourceManager.GetObject(s) ?? Resources.box_wp16xy);
|
|
|
|
|
}
|
2017-02-05 04:39:42 +00:00
|
|
|
|
private static Image getSprite(PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
|
|
|
|
|
{
|
|
|
|
|
if (!pkm.Valid)
|
|
|
|
|
return null;
|
|
|
|
|
|
2017-03-13 05:23:39 +00:00
|
|
|
|
bool inBox = slot >= 0 && slot < 30;
|
2017-03-09 05:50:34 +00:00
|
|
|
|
var sprite = pkm.Species != 0 ? pkm.Sprite(isBoxBGRed: inBox && BoxWallpaper.getWallpaperRed(SAV, box)) : null;
|
|
|
|
|
|
|
|
|
|
if (slot <= -1) // from tabs
|
|
|
|
|
return sprite;
|
|
|
|
|
|
|
|
|
|
if (flagIllegal)
|
2017-02-05 04:39:42 +00:00
|
|
|
|
{
|
2017-04-15 00:49:13 +00:00
|
|
|
|
if (slot < 30)
|
|
|
|
|
pkm.Box = box;
|
2017-02-05 04:39:42 +00:00
|
|
|
|
var la = new LegalityAnalysis(pkm);
|
|
|
|
|
if (la.Parsed && !la.Valid)
|
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.warn, 0, 14, 1);
|
|
|
|
|
}
|
2017-03-09 05:50:34 +00:00
|
|
|
|
if (inBox) // in box
|
|
|
|
|
{
|
|
|
|
|
if (SAV.getIsSlotLocked(box, slot))
|
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.locked, 26, 0, 1);
|
|
|
|
|
else if (SAV.getIsTeamSet(box, slot))
|
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.team, 21, 0, 1);
|
|
|
|
|
}
|
2017-02-05 04:39:42 +00:00
|
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
|
}
|
2017-01-12 06:28:35 +00:00
|
|
|
|
|
|
|
|
|
// Extension Methods
|
2017-02-05 04:39:42 +00:00
|
|
|
|
public static Image WallpaperImage(this SaveFile SAV, int box) => getWallpaper(SAV, box);
|
2017-01-12 06:28:35 +00:00
|
|
|
|
public static Image Sprite(this MysteryGift gift) => getSprite(gift);
|
|
|
|
|
public static Image Sprite(this SaveFile SAV) => getSprite(SAV);
|
2017-03-09 05:50:34 +00:00
|
|
|
|
public static Image Sprite(this PKM pkm, bool isBoxBGRed = false) => getSprite(pkm, isBoxBGRed);
|
2017-02-05 04:39:42 +00:00
|
|
|
|
public static Image Sprite(this PKM pkm, SaveFile SAV, int box, int slot, bool flagIllegal = false)
|
|
|
|
|
=> getSprite(pkm, SAV, box, slot, flagIllegal);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|