2019-08-21 02:50:28 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using PKHeX.WinForms.Properties;
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
public static Image GetTouchTypeBackground(SlotTouchType type)
|
2019-08-21 02:50:28 +00:00
|
|
|
|
{
|
2019-09-03 02:30:58 +00:00
|
|
|
|
switch (type)
|
2019-08-21 02:50:28 +00:00
|
|
|
|
{
|
|
|
|
|
case SlotTouchType.None: return Resources.slotTrans;
|
|
|
|
|
case SlotTouchType.Get: return Resources.slotView;
|
|
|
|
|
case SlotTouchType.Set: return Resources.slotSet;
|
|
|
|
|
case SlotTouchType.Delete: return Resources.slotDel;
|
|
|
|
|
case SlotTouchType.Swap: return Resources.slotSet;
|
|
|
|
|
default:
|
2019-09-03 02:30:58 +00:00
|
|
|
|
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>
|
2019-08-21 02:50:28 +00:00
|
|
|
|
public static DropModifier GetDropModifier()
|
|
|
|
|
{
|
|
|
|
|
switch (Control.ModifierKeys)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Shift: return DropModifier.Clone;
|
|
|
|
|
case Keys.Alt: return DropModifier.Overwrite;
|
|
|
|
|
default: return 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var img = c is SlotInfoBox b
|
|
|
|
|
? p.Sprite(s, b.Box, b.Slot, flagIllegal)
|
|
|
|
|
: c is SlotInfoParty ps
|
|
|
|
|
? p.Sprite(s, -1, ps.Slot, flagIllegal)
|
|
|
|
|
: p.Sprite(s, -1, -1, flagIllegal);
|
|
|
|
|
|
|
|
|
|
pb.BackColor = Color.Transparent;
|
|
|
|
|
pb.Image = img;
|
|
|
|
|
}
|
2019-08-21 02:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|