PKHeX/PKHeX.Drawing.Misc/Util/MysteryGiftSpriteUtil.cs
Kurt fa9a809751
Encapsulate item pouch arrays/etc for finer control (#3860)
* Extract/encapsulate inventory legal arrays to interface+class

Hiding them behind methods allows these to be left as ReadOnlySpan<ushort> and thus never allocate on the heap.
Also refactors out some logic for checking if an item is legal.

End result feels more maintainable and is less bloaty (no more passing in a nullable func)

Batch editing
* Add HasType filter

```
=HasType=11
.HeldItem=Meadow Plate
```

slaps a meadow plate on any pkm with grass type
Use `=PersonalType1=11` for only primary grass types; only-secondary-type grass will not match it.
2023-04-16 12:58:07 -07:00

41 lines
1.3 KiB
C#

using System.Drawing;
using PKHeX.Core;
using PKHeX.Drawing.Misc.Properties;
using PKHeX.Drawing.PokeSprite;
namespace PKHeX.Drawing.Misc;
public static class MysteryGiftSpriteUtil
{
public static Image Sprite(this MysteryGift gift) => GetSprite(gift);
private static Image GetSprite(MysteryGift gift)
{
if (gift.Empty)
return SpriteUtil.Spriter.None;
var img = GetBaseImage(gift);
if (SpriteBuilder.ShowEncounterColor != SpriteBackgroundType.None)
img = SpriteUtil.ApplyEncounterColor(gift, img, SpriteBuilder.ShowEncounterColor);
if (gift.GiftUsed)
img = ImageUtil.ChangeOpacity(img, 0.3);
return img;
}
private static Image GetBaseImage(MysteryGift gift)
{
if (gift is { IsEgg: true, Species: (int)Species.Manaphy }) // Manaphy Egg
return SpriteUtil.GetMysteryGiftPreviewPoke(gift);
if (gift.IsEntity)
return SpriteUtil.GetMysteryGiftPreviewPoke(gift);
if (gift.IsItem)
{
var item = (ushort)gift.ItemID;
if (ItemStorage7USUM.GetCrystalHeld(item, out var value))
item = value;
return SpriteUtil.GetItemSprite(item) ?? Resources.Bag_Key;
}
return PokeSprite.Properties.Resources.b_unknown;
}
}