2017-01-12 01:55:42 +00:00
|
|
|
|
using System.Drawing;
|
2020-02-16 20:17:36 +00:00
|
|
|
|
using System.Linq;
|
2017-01-12 01:55:42 +00:00
|
|
|
|
using PKHeX.Core;
|
2019-09-29 16:47:06 +00:00
|
|
|
|
using PKHeX.Drawing.Properties;
|
2017-01-12 01:55:42 +00:00
|
|
|
|
|
2019-09-29 16:47:06 +00:00
|
|
|
|
namespace PKHeX.Drawing
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2018-07-21 04:32:33 +00:00
|
|
|
|
public static class SpriteUtil
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2020-12-22 07:37:07 +00:00
|
|
|
|
public static readonly SpriteBuilder5668 SB8 = new();
|
2020-04-13 16:52:25 +00:00
|
|
|
|
public static SpriteBuilder Spriter { get; set; } = SB8;
|
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
|
|
|
|
{
|
2019-10-04 01:23:40 +00:00
|
|
|
|
string resource = SpriteName.GetResourceStringBall(ball);
|
2019-10-08 02:10:38 +00:00
|
|
|
|
return (Bitmap?)Resources.ResourceManager.GetObject(resource) ?? Resources._ball4; // Poké Ball (default)
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2020-03-04 04:22:57 +00:00
|
|
|
|
public static Image GetSprite(int species, int form, int gender, uint formarg, int item, bool isegg, bool isShiny, int generation = -1, bool isBoxBGRed = false, bool isAltShiny = false)
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2020-03-04 04:22:57 +00:00
|
|
|
|
return Spriter.GetSprite(species, form, gender, formarg, item, isegg, isShiny, generation, isBoxBGRed, isAltShiny);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-10-08 02:10:38 +00:00
|
|
|
|
public static Image? GetRibbonSprite(string name)
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2021-06-24 16:16:36 +00:00
|
|
|
|
var resource = name.Replace("CountG3", "G3").ToLowerInvariant();
|
2019-10-08 02:10:38 +00:00
|
|
|
|
return (Bitmap?)Resources.ResourceManager.GetObject(resource);
|
2017-01-12 06:28:35 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-10-08 02:10:38 +00:00
|
|
|
|
public static Image? GetRibbonSprite(string name, int max, int value)
|
2018-07-29 23:39:15 +00:00
|
|
|
|
{
|
|
|
|
|
var resource = GetRibbonSpriteName(name, max, value);
|
2019-10-08 02:10:38 +00:00
|
|
|
|
return (Bitmap?)Resources.ResourceManager.GetObject(resource);
|
2018-07-29 23:39:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetRibbonSpriteName(string name, int max, int value)
|
|
|
|
|
{
|
|
|
|
|
if (max != 4) // Memory
|
2019-02-08 05:40:20 +00:00
|
|
|
|
{
|
2021-06-24 16:16:36 +00:00
|
|
|
|
var sprite = name.ToLowerInvariant();
|
2019-02-08 05:40:20 +00:00
|
|
|
|
if (max == value)
|
|
|
|
|
return sprite + "2";
|
|
|
|
|
return sprite;
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
|
|
|
|
// Count ribbons
|
2021-06-24 16:16:36 +00:00
|
|
|
|
string n = name.Replace("Count", string.Empty).ToLowerInvariant();
|
2019-09-29 16:47:06 +00:00
|
|
|
|
return value switch
|
2018-07-29 23:39:15 +00:00
|
|
|
|
{
|
2019-09-29 16:47:06 +00:00
|
|
|
|
2 => n + "super",
|
|
|
|
|
3 => n + "hyper",
|
|
|
|
|
4 => n + "master",
|
|
|
|
|
_ => n
|
|
|
|
|
};
|
2018-07-29 23:39:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 02:10:38 +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);
|
2019-10-08 02:10:38 +00:00
|
|
|
|
return (Bitmap?)Resources.ResourceManager.GetObject($"type_icon_{type:00}");
|
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)
|
2021-04-09 23:24:19 +00:00
|
|
|
|
return Spriter.None;
|
2017-01-12 06:28:35 +00:00
|
|
|
|
|
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)
|
|
|
|
|
{
|
2019-12-09 01:39:19 +00:00
|
|
|
|
if (gift.IsEgg && gift.Species == (int)Species.Manaphy) // Manaphy Egg
|
2021-04-09 23:24:19 +00:00
|
|
|
|
return Resources.b_490_e;
|
2018-07-27 02:34:27 +00:00
|
|
|
|
if (gift.IsPokémon)
|
2020-12-11 04:42:30 +00:00
|
|
|
|
return GetSprite(gift.Species, gift.Form, gift.Gender, 0, gift.HeldItem, gift.IsEgg, gift.IsShiny, gift.Generation);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
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;
|
2019-04-23 05:24:29 +00:00
|
|
|
|
return (Image)(Resources.ResourceManager.GetObject($"item_{item}") ?? Resources.Bag_Key);
|
2017-10-01 03:57:32 +00:00
|
|
|
|
}
|
2021-04-09 23:24:19 +00:00
|
|
|
|
return Resources.b_unknown;
|
2017-01-12 06:28:35 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-02-17 03:53:14 +00:00
|
|
|
|
private static Image GetSprite(PKM pk, bool isBoxBGRed = false)
|
2017-03-08 16:46:25 +00:00
|
|
|
|
{
|
2020-03-04 04:22:57 +00:00
|
|
|
|
var formarg = pk is IFormArgument f ? f.FormArgument : 0;
|
2020-06-19 23:51:15 +00:00
|
|
|
|
bool alt = pk.Format >= 8 && (pk.ShinyXor == 0 || pk.FatefulEncounter || pk.Version == (int)GameVersion.GO);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var img = GetSprite(pk.Species, pk.Form, pk.Gender, formarg, pk.SpriteItem, pk.IsEgg, pk.IsShiny, pk.Format, isBoxBGRed, alt);
|
2020-12-22 06:33:48 +00:00
|
|
|
|
if (pk is IShadowPKM {IsShadow: true})
|
2018-10-14 03:41:58 +00:00
|
|
|
|
{
|
2019-04-23 05:24:29 +00:00
|
|
|
|
const int Lugia = 249;
|
|
|
|
|
if (pk.Species == Lugia) // show XD shadow sprite
|
2020-06-03 17:38:00 +00:00
|
|
|
|
img = Spriter.GetSprite(Spriter.ShadowLugia, Lugia, pk.HeldItem, pk.IsEgg, pk.IsShiny, pk.Format, isBoxBGRed);
|
2019-04-23 05:24:29 +00:00
|
|
|
|
GetSpriteGlow(pk, 75, 0, 130, out var pixels, out var baseSprite, true);
|
2018-10-14 03:41:58 +00:00
|
|
|
|
var glowImg = ImageUtil.GetBitmap(pixels, baseSprite.Width, baseSprite.Height, baseSprite.PixelFormat);
|
2019-11-26 06:51:07 +00:00
|
|
|
|
return ImageUtil.LayerImage(glowImg, img, 0, 0);
|
2018-10-14 03:41:58 +00:00
|
|
|
|
}
|
2020-12-22 06:33:48 +00:00
|
|
|
|
if (pk is IGigantamax {CanGigantamax: true})
|
2019-11-16 01:34:18 +00:00
|
|
|
|
{
|
|
|
|
|
var gm = Resources.dyna;
|
2019-11-26 06:51:07 +00:00
|
|
|
|
return ImageUtil.LayerImage(img, gm, (img.Width - gm.Width) / 2, 0);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
}
|
2018-10-14 03:41:58 +00:00
|
|
|
|
return img;
|
2017-03-08 16:46:25 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-10-08 02:10:38 +00:00
|
|
|
|
private static Image? GetSprite(SaveFile sav)
|
2017-01-12 06:28:35 +00:00
|
|
|
|
{
|
2021-08-05 20:11:50 +00:00
|
|
|
|
if (sav is SAV6XY or SAV6AO)
|
|
|
|
|
{
|
|
|
|
|
string file = $"tr_{sav.MultiplayerSpriteID:00}";
|
|
|
|
|
return Resources.ResourceManager.GetObject(file) as Image ?? Resources.tr_00;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2017-01-12 06:28:35 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-02-17 03:53:14 +00:00
|
|
|
|
private static Image GetWallpaper(SaveFile sav, int box)
|
2017-01-12 01:55:42 +00:00
|
|
|
|
{
|
2019-02-17 03:53:14 +00:00
|
|
|
|
string s = BoxWallpaper.GetWallpaperResourceName(sav.Version, sav.GetBoxWallpaper(box));
|
2019-10-08 02:10:38 +00:00
|
|
|
|
return (Bitmap?)Resources.ResourceManager.GetObject(s) ?? Resources.box_wp16xy;
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-02-17 03:53:14 +00:00
|
|
|
|
private static Image GetSprite(PKM pk, SaveFile sav, int box, int slot, bool flagIllegal = false)
|
2017-02-05 04:39:42 +00:00
|
|
|
|
{
|
2019-02-17 03:53:14 +00:00
|
|
|
|
if (!pk.Valid)
|
2021-04-09 23:24:19 +00:00
|
|
|
|
return Spriter.None;
|
2017-02-05 04:39:42 +00:00
|
|
|
|
|
2019-04-23 05:24:29 +00:00
|
|
|
|
bool inBox = (uint)slot < MaxSlotCount;
|
|
|
|
|
bool empty = pk.Species == 0;
|
2021-04-09 23:24:19 +00:00
|
|
|
|
var sprite = empty ? Spriter.None : pk.Sprite(isBoxBGRed: inBox && BoxWallpaper.IsWallpaperRed(sav.Version, sav.GetBoxWallpaper(box)));
|
2017-03-09 05:50:34 +00:00
|
|
|
|
|
2019-04-23 05:24:29 +00:00
|
|
|
|
if (!empty && flagIllegal)
|
2017-02-05 04:39:42 +00:00
|
|
|
|
{
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
var la = new LegalityAnalysis(pk, sav.Personal, box != -1 ? SlotOrigin.Box : SlotOrigin.Party);
|
2019-04-23 05:24:29 +00:00
|
|
|
|
if (!la.Valid)
|
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.warn, 0, FlagIllegalShiftY);
|
2020-02-16 20:17:36 +00:00
|
|
|
|
else if (pk.Format >= 8 && pk.Moves.Any(Legal.DummiedMoves_SWSH.Contains))
|
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.hint, 0, FlagIllegalShiftY);
|
2017-02-05 04:39:42 +00:00
|
|
|
|
}
|
2017-03-09 05:50:34 +00:00
|
|
|
|
if (inBox) // in box
|
|
|
|
|
{
|
2019-02-17 03:53:14 +00:00
|
|
|
|
var flags = sav.GetSlotFlags(box, slot);
|
2018-12-10 07:18:37 +00:00
|
|
|
|
int team = flags.IsBattleTeam();
|
|
|
|
|
if (team >= 0)
|
2019-04-23 05:24:29 +00:00
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.team, SlotTeamShiftX, 0);
|
2020-02-02 02:56:23 +00:00
|
|
|
|
if (flags.HasFlagFast(StorageSlotFlag.Locked))
|
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.locked, SlotLockShiftX, 0);
|
2018-12-10 07:18:37 +00:00
|
|
|
|
int party = flags.IsParty();
|
|
|
|
|
if (party >= 0)
|
2019-04-23 05:24:29 +00:00
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, PartyMarks[party], PartyMarkShiftX, 0);
|
2018-12-10 07:18:37 +00:00
|
|
|
|
if (flags.HasFlagFast(StorageSlotFlag.Starter))
|
|
|
|
|
sprite = ImageUtil.LayerImage(sprite, Resources.starter, 0, 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
|
|
|
|
|
2019-04-23 05:24:29 +00:00
|
|
|
|
private const int MaxSlotCount = 30; // slots in a box
|
2019-11-16 01:34:18 +00:00
|
|
|
|
private static int SpriteWidth => Spriter.Width;
|
|
|
|
|
private static int SpriteHeight => Spriter.Height;
|
|
|
|
|
private static int PartyMarkShiftX => SpriteWidth - 16;
|
|
|
|
|
private static int SlotLockShiftX => SpriteWidth - 14;
|
|
|
|
|
private static int SlotTeamShiftX => SpriteWidth - 19;
|
|
|
|
|
private static int FlagIllegalShiftY => SpriteHeight - 16;
|
2019-04-23 05:24:29 +00:00
|
|
|
|
|
2019-04-30 00:21:19 +00:00
|
|
|
|
private static readonly Bitmap[] PartyMarks =
|
2018-12-10 07:18:37 +00:00
|
|
|
|
{
|
|
|
|
|
Resources.party1, Resources.party2, Resources.party3, Resources.party4, Resources.party5, Resources.party6,
|
|
|
|
|
};
|
|
|
|
|
|
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)
|
2019-04-23 05:24:29 +00:00
|
|
|
|
{
|
|
|
|
|
GetSpriteGlow(pk, bgr[0], bgr[1], bgr[2], out pixels, out baseSprite, forceHollow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void GetSpriteGlow(PKM pk, byte blue, byte green, byte red, out byte[] pixels, out Image baseSprite, bool forceHollow = false)
|
2018-07-28 02:59:14 +00:00
|
|
|
|
{
|
|
|
|
|
bool egg = pk.IsEgg;
|
2020-03-04 04:22:57 +00:00
|
|
|
|
var formarg = pk is IFormArgument f ? f.FormArgument : 0;
|
2020-12-11 04:42:30 +00:00
|
|
|
|
baseSprite = GetSprite(pk.Species, pk.Form, pk.Gender, formarg, 0, egg, false, pk.Format);
|
2019-04-23 05:24:29 +00:00
|
|
|
|
GetSpriteGlow(baseSprite, blue, green, red, out pixels, forceHollow || egg);
|
2018-07-28 02:59:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 05:24:29 +00:00
|
|
|
|
public static void GetSpriteGlow(Image baseSprite, byte blue, byte green, byte red, out byte[] pixels, bool forceHollow = false)
|
2018-07-28 02:59:14 +00:00
|
|
|
|
{
|
2019-04-23 05:24:29 +00:00
|
|
|
|
pixels = ImageUtil.GetPixelData((Bitmap)baseSprite);
|
2018-07-28 02:59:14 +00:00
|
|
|
|
if (!forceHollow)
|
|
|
|
|
{
|
2019-04-23 05:24:29 +00:00
|
|
|
|
ImageUtil.GlowEdges(pixels, blue, green, red, baseSprite.Width);
|
2018-07-28 02:59:14 +00:00
|
|
|
|
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.
|
2019-04-23 05:24:29 +00:00
|
|
|
|
var original = (byte[])pixels.Clone();
|
2018-07-28 02:59:14 +00:00
|
|
|
|
ImageUtil.SetAllUsedPixelsOpaque(pixels);
|
2019-04-23 05:24:29 +00:00
|
|
|
|
ImageUtil.GlowEdges(pixels, blue, green, red, baseSprite.Width);
|
2018-07-28 02:59:14 +00:00
|
|
|
|
ImageUtil.RemovePixels(pixels, original);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-29 16:47:06 +00:00
|
|
|
|
public static Image GetLegalIndicator(bool valid) => valid ? Resources.valid : Resources.warn;
|
|
|
|
|
|
2017-01-12 06:28:35 +00:00
|
|
|
|
// Extension Methods
|
2019-02-17 03:53:14 +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);
|
2019-10-08 02:10:38 +00:00
|
|
|
|
public static Image? Sprite(this SaveFile sav) => GetSprite(sav);
|
2019-02-17 03:53:14 +00:00
|
|
|
|
public static Image Sprite(this PKM pk, bool isBoxBGRed = false) => GetSprite(pk, isBoxBGRed);
|
2018-07-27 02:34:27 +00:00
|
|
|
|
|
2019-02-17 03:53:14 +00:00
|
|
|
|
public static Image Sprite(this PKM pk, SaveFile sav, int box, int slot, bool flagIllegal = false)
|
|
|
|
|
=> GetSprite(pk, sav, box, slot, flagIllegal);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
|
2021-04-09 23:24:19 +00:00
|
|
|
|
public static void Initialize(SaveFile sav) => Spriter.Initialize(sav);
|
2017-01-12 01:55:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|