mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 20:43:07 +00:00
b81a1e1e29
Increase abstraction for arbitrary slot get/set operations, and fracture SAV4 behavior for each game type. Adds: Undo/Redo of party slot changes Fixes: Fixed Gen5 daycare slot 2 reading, and EXP reading Fixes: Some slot color glitchiness Fixed: Box layout editor now hides the flag label if no flags are present Fixed: Gen7 box flags are now shown (unknown purpose lol) Changed: savefile objects are generally smaller (removed a few shared offset fields)
74 lines
No EOL
2.5 KiB
C#
74 lines
No EOL
2.5 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using PKHeX.Core;
|
|
using PKHeX.WinForms.Properties;
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
{
|
|
/// <summary>
|
|
/// Utility logic for drawing individual Slot views that represent underlying <see cref="PKM"/> data.
|
|
/// </summary>
|
|
public static class SlotUtil
|
|
{
|
|
/// <summary>
|
|
/// Gets the background image for a slot based on the provided <see cref="type"/>.
|
|
/// </summary>
|
|
public static Image GetTouchTypeBackground(SlotTouchType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
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:
|
|
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the type of action that should be performed for a Drag & Drop request.
|
|
/// </summary>
|
|
public static DropModifier GetDropModifier()
|
|
{
|
|
switch (Control.ModifierKeys)
|
|
{
|
|
case Keys.Shift: return DropModifier.Clone;
|
|
case Keys.Alt: return DropModifier.Overwrite;
|
|
default: return DropModifier.None;
|
|
}
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
}
|
|
} |