using System; using System.Drawing; using System.Windows.Forms; using PKHeX.Core; using PKHeX.Drawing.PokeSprite; namespace PKHeX.WinForms.Controls; /// /// Utility logic for drawing individual Slot views that represent underlying data. /// public static class SlotUtil { /// /// Gets the background image for a slot based on the provided . /// public static Bitmap? GetTouchTypeBackground(SlotTouchType type) => type switch { SlotTouchType.None => null, SlotTouchType.Get => SpriteUtil.Spriter.View, SlotTouchType.Set => SpriteUtil.Spriter.Set, SlotTouchType.Delete => SpriteUtil.Spriter.Delete, SlotTouchType.Swap => SpriteUtil.Spriter.Set, _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), }; /// /// Gets the type of action that should be performed for a Drag & Drop request. /// public static DropModifier GetDropModifier() => Control.ModifierKeys switch { Keys.Shift => DropModifier.Clone, Keys.Alt => DropModifier.Overwrite, _ => DropModifier.None, }; public static readonly Color GoodDataColor = Color.Transparent; public static Color BadDataColor => WinFormsUtil.ColorWarn; /// /// Refreshes a with the appropriate display content. /// public static void UpdateSlot(PictureBox pb, ISlotInfo info, PKM pk, SaveFile sav, SlotVisibilityType flags, SlotTouchType t = SlotTouchType.None) { pb.Image?.Dispose(); pb.BackgroundImage?.Dispose(); pb.BackgroundImage = GetTouchTypeBackground(t); if (pk.Species == 0) // Nothing in slot { pb.Image = null; pb.BackColor = GoodDataColor; pb.AccessibleDescription = null; return; } if (!pk.Valid) // Invalid { // Bad Egg present in slot. pb.Image = null; pb.BackColor = BadDataColor; pb.AccessibleDescription = null; return; } pb.Image = GetImage(info, pk, sav, flags); pb.BackColor = GoodDataColor; // Get an accessible description for the slot (for screen readers) var x = Main.Settings; var programLanguage = Language.GetLanguageValue(x.Startup.Language); var cfg = x.BattleTemplate; var settings = cfg.Hover.GetSettings(programLanguage, pk.Context); pb.AccessibleDescription = ShowdownParsing.GetLocalizedPreviewText(pk, settings); } private static Bitmap GetImage(ISlotInfo info, PKM pk, SaveFile sav, SlotVisibilityType flags) => info switch { SlotInfoBox b => pk.Sprite(sav, b.Box, b.Slot, flags, b.Type), SlotInfoParty ps => pk.Sprite(sav, -1, ps.Slot, flags, ps.Type), _ => pk.Sprite(sav, -1, -1, flags, info.Type), }; }