2019-08-21 02:50:28 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
2019-09-29 16:47:06 +00:00
|
|
|
|
using PKHeX.Drawing;
|
2019-08-21 02:50:28 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Utility logic for drawing individual Slot views that represent underlying <see cref="PKM"/> data.
|
|
|
|
|
/// </summary>
|
2019-08-21 02:50:28 +00:00
|
|
|
|
public static class SlotUtil
|
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the background image for a slot based on the provided <see cref="type"/>.
|
|
|
|
|
/// </summary>
|
2021-01-02 01:08:49 +00:00
|
|
|
|
public static Image GetTouchTypeBackground(SlotTouchType type) => type switch
|
2019-08-21 02:50:28 +00:00
|
|
|
|
{
|
2021-01-02 01:08:49 +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
|
|
|
|
|
2019-09-03 02:30:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the type of action that should be performed for a Drag & Drop request.
|
|
|
|
|
/// </summary>
|
2021-01-02 01:08:49 +00:00
|
|
|
|
public static DropModifier GetDropModifier() => Control.ModifierKeys switch
|
2019-08-21 02:50:28 +00:00
|
|
|
|
{
|
2021-01-02 01:08:49 +00:00
|
|
|
|
Keys.Shift => DropModifier.Clone,
|
|
|
|
|
Keys.Alt => DropModifier.Overwrite,
|
|
|
|
|
_ => DropModifier.None
|
|
|
|
|
};
|
2019-09-03 02:30:58 +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 = Color.Transparent;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!p.Valid) // Invalid
|
|
|
|
|
{
|
|
|
|
|
// Bad Egg present in slot.
|
|
|
|
|
pb.Image = null;
|
|
|
|
|
pb.BackColor = Color.Red;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-14 23:16:55 +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
|
|
|
|
|
|
|
|
|
pb.BackColor = Color.Transparent;
|
|
|
|
|
pb.Image = img;
|
|
|
|
|
}
|
2019-08-21 02:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|