2023-02-05 08:42:37 +00:00
|
|
|
using System;
|
2019-08-21 02:50:28 +00:00
|
|
|
using System.Drawing;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using PKHeX.Core;
|
2021-11-27 23:48:08 +00:00
|
|
|
using PKHeX.Drawing.PokeSprite;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.WinForms.Controls;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Utility logic for drawing individual Slot views that represent underlying <see cref="PKM"/> data.
|
|
|
|
/// </summary>
|
|
|
|
public static class SlotUtil
|
2019-08-21 02:50:28 +00:00
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
/// <summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// Gets the background image for a slot based on the provided <see cref="type"/>.
|
2019-09-03 02:30:58 +00:00
|
|
|
/// </summary>
|
2023-12-04 04:13:20 +00:00
|
|
|
public static Bitmap GetTouchTypeBackground(SlotTouchType type) => type switch
|
2019-08-21 02:50:28 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
SlotTouchType.None => SpriteUtil.Spriter.Transparent,
|
|
|
|
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),
|
|
|
|
};
|
2019-08-21 02:50:28 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the type of action that should be performed for a Drag & Drop request.
|
|
|
|
/// </summary>
|
|
|
|
public static DropModifier GetDropModifier() => Control.ModifierKeys switch
|
|
|
|
{
|
|
|
|
Keys.Shift => DropModifier.Clone,
|
|
|
|
Keys.Alt => DropModifier.Overwrite,
|
|
|
|
_ => DropModifier.None,
|
|
|
|
};
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static readonly Color GoodDataColor = Color.Transparent;
|
|
|
|
public static readonly Color BadDataColor = Color.Red;
|
2022-03-26 22:51:12 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Refreshes a <see cref="PictureBox"/> with the appropriate display content.
|
|
|
|
/// </summary>
|
|
|
|
public static void UpdateSlot(PictureBox pb, ISlotInfo c, PKM p, SaveFile s, bool flagIllegal, SlotTouchType t = SlotTouchType.None)
|
|
|
|
{
|
|
|
|
pb.BackgroundImage = GetTouchTypeBackground(t);
|
|
|
|
if (p.Species == 0) // Nothing in slot
|
|
|
|
{
|
|
|
|
pb.Image = null;
|
|
|
|
pb.BackColor = GoodDataColor;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!p.Valid) // Invalid
|
2019-09-03 02:30:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
// Bad Egg present in slot.
|
|
|
|
pb.Image = null;
|
|
|
|
pb.BackColor = BadDataColor;
|
|
|
|
return;
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var img = c switch
|
|
|
|
{
|
|
|
|
SlotInfoBox b => p.Sprite(s, b.Box, b.Slot, flagIllegal),
|
|
|
|
SlotInfoParty ps => p.Sprite(s, -1, ps.Slot, flagIllegal),
|
|
|
|
_ => p.Sprite(s, -1, -1, flagIllegal),
|
|
|
|
};
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
pb.BackColor = Color.Transparent;
|
|
|
|
pb.Image = img;
|
2023-02-05 08:42:37 +00:00
|
|
|
pb.AccessibleDescription = ShowdownParsing.GetLocalizedPreviewText(p, Main.CurrentLanguage);
|
2019-08-21 02:50:28 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|