diff --git a/PKHeX.Core/Editing/Saves/Slots/Info/ExternalSlotInfo.cs b/PKHeX.Core/Editing/Saves/Slots/Info/ExternalSlotInfo.cs
deleted file mode 100644
index bba5d2f9b..000000000
--- a/PKHeX.Core/Editing/Saves/Slots/Info/ExternalSlotInfo.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-
-namespace PKHeX.Core
-{
- ///
- /// originating from outside of a save file (e.g. a saved file on a hard drive).
- ///
- public sealed class ExternalSlotInfo : ISlotInfo
- {
- private readonly PKM Data;
- public ExternalSlotInfo(PKM pkm) => Data = pkm;
-
- public int Slot { get; } = -1;
- public bool Equals(ISlotInfo other) => false;
- public bool CanWriteTo(SaveFile SAV) => false;
- public WriteBlockedMessage CanWriteTo(SaveFile SAV, PKM pkm) => WriteBlockedMessage.InvalidDestination;
- public bool WriteTo(SaveFile sav, PKM pkm, PKMImportSetting setting = PKMImportSetting.UseDefault) => throw new InvalidOperationException();
-
- public PKM Read(SaveFile sav) => Data;
- }
-}
\ No newline at end of file
diff --git a/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs b/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs
index e94ee3be0..b75ccda13 100644
--- a/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs
+++ b/PKHeX.Core/Editing/Saves/Slots/SlotViewInfo.cs
@@ -8,5 +8,9 @@ public class SlotViewInfo
{
public ISlotInfo Slot;
public ISlotViewer View;
+
+ public PKM ReadCurrent() => Slot.Read(View.SAV);
+ public bool CanWriteTo() => Slot.CanWriteTo(View.SAV);
+ public WriteBlockedMessage CanWriteTo(PKM pkm) => Slot.CanWriteTo(View.SAV, pkm);
}
}
\ No newline at end of file
diff --git a/PKHeX.WinForms/Controls/SAV Editor/DragManager.cs b/PKHeX.WinForms/Controls/SAV Editor/DragManager.cs
index 60153221b..60f53945c 100644
--- a/PKHeX.WinForms/Controls/SAV Editor/DragManager.cs
+++ b/PKHeX.WinForms/Controls/SAV Editor/DragManager.cs
@@ -6,7 +6,7 @@ namespace PKHeX.WinForms.Controls
{
public class DragManager
{
- public SlotChangeInfo Info { get; private set; }
+ public SlotChangeInfo Info { get; private set; }
public event DragEventHandler RequestExternalDragDrop;
public void RequestDD(object sender, DragEventArgs e) => RequestExternalDragDrop?.Invoke(sender, e);
@@ -22,7 +22,7 @@ public void ResetCursor(Form sender)
public void Initialize()
{
- Info = new SlotChangeInfo();
+ Info = new SlotChangeInfo();
}
public void Reset() => Info.Reset();
@@ -31,16 +31,16 @@ public void Initialize()
public bool CanStartDrag => Info.LeftMouseIsDown && !Cursor.Position.Equals(MouseDownPosition);
}
- public class SlotChangeInfo
+ public class SlotChangeInfo
{
public bool LeftMouseIsDown { get; set; }
public bool DragDropInProgress { get; set; }
- public T Cursor { get; set; }
+ public TCursor Cursor { get; set; }
public string CurrentPath { get; set; }
- public ISlotInfo Source { get; set; }
- public ISlotInfo Destination { get; set; }
+ public SlotViewInfo Source { get; set; }
+ public SlotViewInfo Destination { get; set; }
public SlotChangeInfo()
{
@@ -55,5 +55,6 @@ public void Reset()
}
public bool SameLocation => Source?.Equals(Destination) ?? false;
+ public bool DragIsParty => Source?.Slot is SlotInfoParty || Destination?.Slot is SlotInfoParty;
}
}
\ No newline at end of file
diff --git a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs
index 3fa8948ee..d50949bcc 100644
--- a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs
+++ b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs
@@ -22,7 +22,6 @@ public sealed class SlotChangeManager : IDisposable
public readonly DragManager Drag = new DragManager();
public SaveDataEditor Env { get; set; }
- private SaveFile SAV => SE.SAV;
public readonly List Boxes = new List();
public readonly SlotHoverHandler Hover = new SlotHoverHandler();
@@ -57,6 +56,7 @@ public void MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
Drag.Info.LeftMouseIsDown = false;
+ Drag.Info.Source = null;
}
public void MouseDown(object sender, MouseEventArgs e)
@@ -78,7 +78,7 @@ public void QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
public void DragEnter(object sender, DragEventArgs e)
{
- if (e.AllowedEffect == (DragDropEffects.Copy | DragDropEffects.Link)) // external file
+ if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) // external file
e.Effect = DragDropEffects.Copy;
else if (e.Data != null) // within
e.Effect = DragDropEffects.Move;
@@ -87,6 +87,13 @@ public void DragEnter(object sender, DragEventArgs e)
Drag.SetCursor(((Control)sender).FindForm(), Drag.Info.Cursor);
}
+ private static SlotViewInfo GetSlotInfo(T pb) where T : Control
+ {
+ var view = WinFormsUtil.FindFirstControlOfType>(pb);
+ var src = view.GetSlotData(pb);
+ return new SlotViewInfo { Slot = src, View = view };
+ }
+
public void MouseMove(object sender, MouseEventArgs e)
{
if (!Drag.CanStartDrag)
@@ -96,9 +103,8 @@ public void MouseMove(object sender, MouseEventArgs e)
PictureBox pb = (PictureBox)sender;
if (pb.Image == null)
return;
- var view = WinFormsUtil.FindFirstControlOfType>(pb);
- var src = view.GetSlotData(pb);
- if (!src.CanWriteTo(SAV))
+ var src = GetSlotInfo(pb);
+ if (!src.CanWriteTo())
return;
bool encrypt = Control.ModifierKeys == Keys.Control;
HandleMovePKM(pb, encrypt);
@@ -107,9 +113,8 @@ public void MouseMove(object sender, MouseEventArgs e)
public void DragDrop(object sender, DragEventArgs e)
{
PictureBox pb = (PictureBox)sender;
- var view = WinFormsUtil.FindFirstControlOfType>(pb);
- var src = view.GetSlotData(pb);
- if (!src.CanWriteTo(SAV))
+ var info = GetSlotInfo(pb);
+ if (!info.CanWriteTo())
{
SystemSounds.Asterisk.Play();
e.Effect = DragDropEffects.Copy;
@@ -118,13 +123,10 @@ public void DragDrop(object sender, DragEventArgs e)
}
var mod = SlotUtil.GetDropModifier();
- Drag.Info.Destination = src;
+ Drag.Info.Destination = info;
HandleDropPKM(pb, e, mod);
}
- private static ISlotViewer GetViewParent(T pb) where T : Control
- => WinFormsUtil.FindFirstControlOfType>(pb);
-
private void HandleMovePKM(PictureBox pb, bool encrypt)
{
// Create a temporary PKM file to perform a drag drop operation.
@@ -133,13 +135,13 @@ private void HandleMovePKM(PictureBox pb, bool encrypt)
Drag.Info.DragDropInProgress = true;
// Prepare Data
- Drag.Info.Source = GetViewParent(pb).GetSlotData(pb);
- Drag.Info.Source.Read(SAV);
+ Drag.Info.Source = GetSlotInfo(pb);
// Make a new file name based off the PID
string newfile = CreateDragDropPKM(pb, encrypt, out bool external);
// drop finished, clean up
+ Drag.Info.Source = null;
Drag.Reset();
Drag.ResetCursor(pb.FindForm());
@@ -148,7 +150,7 @@ private void HandleMovePKM(PictureBox pb, bool encrypt)
// Keep it to 10 seconds; Discord upload only stores the file path until you click Upload.
int delay = external ? 10_000 : 0;
DeleteAsync(newfile, delay);
- if (Drag.Info.Source is SlotInfoParty || Drag.Info.Destination is SlotInfoParty)
+ if (Drag.Info.DragIsParty)
SE.SetParty();
}
@@ -162,7 +164,7 @@ private async void DeleteAsync(string path, int delay)
private string CreateDragDropPKM(PictureBox pb, bool encrypt, out bool external)
{
// Make File
- PKM pk = Drag.Info.Source.Read(SAV);
+ PKM pk = Drag.Info.Source.ReadCurrent();
string newfile = FileUtil.GetPKMTempFileName(pk, encrypt);
try
{
@@ -202,7 +204,7 @@ private bool TryMakeDragDropPKM(PictureBox pb, byte[] data, string newfile)
if (result == DragDropEffects.Copy) // viewed in tabs or cloned
{
if (Drag.Info.Destination == null) // apply 'view' highlight
- Env.Slots.Get(Drag.Info.Source);
+ Env.Slots.Get(Drag.Info.Source.Slot);
return false;
}
return true;
@@ -220,7 +222,6 @@ private void HandleDropPKM(PictureBox pb, DragEventArgs e, DropModifier mod)
e.Effect = mod == DropModifier.Clone ? DragDropEffects.Copy : DragDropEffects.Link;
// file
- Drag.Info.Destination = GetViewParent(pb).GetSlotData(pb);
if (Drag.Info.SameLocation)
{
e.Effect = DragDropEffects.Link;
@@ -231,7 +232,7 @@ private void HandleDropPKM(PictureBox pb, DragEventArgs e, DropModifier mod)
if (Drag.Info.Source == null) // external source
{
- bool badDest = !dest.CanWriteTo(SAV);
+ bool badDest = !dest.CanWriteTo();
if (!TryLoadFiles(files, e, badDest))
WinFormsUtil.Alert(MessageStrings.MsgSaveSlotBadData);
}
@@ -254,7 +255,7 @@ private bool TryLoadFiles(IReadOnlyList files, DragEventArgs e, bool bad
if (files.Count == 0)
return false;
- var sav = SAV;
+ var sav = Drag.Info.Destination.View.SAV;
var path = files[0];
var temp = FileUtil.GetSingleFromPath(path, sav);
if (temp == null)
@@ -294,15 +295,15 @@ private bool TryLoadFiles(IReadOnlyList files, DragEventArgs e, bool bad
}
}
- Env.Slots.Set(Drag.Info.Destination, pk);
+ Env.Slots.Set(Drag.Info.Destination.Slot, pk);
Debug.WriteLine(c);
return true;
}
private bool TrySetPKMDestination(PictureBox pb, DropModifier mod)
{
- PKM pk = Drag.Info.Source.Read(SAV);
- var msg = Drag.Info.Destination.CanWriteTo(SAV, pk);
+ PKM pk = Drag.Info.Source.ReadCurrent();
+ var msg = Drag.Info.Destination.CanWriteTo(pk);
if (msg != WriteBlockedMessage.None)
return false;
@@ -310,7 +311,7 @@ private bool TrySetPKMDestination(PictureBox pb, DropModifier mod)
TrySetPKMSource(pb, mod);
// Copy from temp to destination slot.
- Env.Slots.Set(Drag.Info.Destination, pk);
+ Env.Slots.Set(Drag.Info.Destination.Slot, pk);
Drag.ResetCursor(pb.FindForm());
return true;
}
@@ -322,17 +323,17 @@ private bool TrySetPKMSource(PictureBox sender, DropModifier mod)
if (sender.Image == null || mod == DropModifier.Overwrite)
{
- Env.Slots.Delete(Drag.Info.Source);
+ Env.Slots.Delete(Drag.Info.Source.Slot);
return true;
}
- var pk = Drag.Info.Destination.Read(SAV);
- Env.Slots.Set(Drag.Info.Source, pk);
+ var pk = Drag.Info.Destination.ReadCurrent();
+ Env.Slots.Set(Drag.Info.Source.Slot, pk);
return true;
}
// Utility
- public void SwapBoxes(int index, int other)
+ public void SwapBoxes(int index, int other, SaveFile SAV)
{
if (index == other)
return;
diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs
index 33b020dab..0ea5096cd 100644
--- a/PKHeX.WinForms/MainWindow/Main.cs
+++ b/PKHeX.WinForms/MainWindow/Main.cs
@@ -1127,7 +1127,6 @@ private void Dragout_MouseDown(object sender, MouseEventArgs e)
try
{
File.WriteAllBytes(newfile, data);
- C_SAV.M.Drag.Info.Source = new ExternalSlotInfo(pk);
var pb = (PictureBox)sender;
if (pb.Image != null)
diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs
index 0a4e2bb35..8ae282fee 100644
--- a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs
+++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs
@@ -74,13 +74,13 @@ private void AddControls(SAVEditor p, SlotChangeManager m, SaveFile sav)
{
int index = Boxes.FindIndex(z => z == ((Button)s).Parent);
int other = (index + Boxes.Count - 1) % Boxes.Count;
- m.SwapBoxes(index, other);
+ m.SwapBoxes(index, other, p.SAV);
};
box.B_BoxRight.Click += (s, e) =>
{
int index = Boxes.FindIndex(z => z == ((Button)s).Parent);
int other = (index + 1) % Boxes.Count;
- m.SwapBoxes(index, other);
+ m.SwapBoxes(index, other, p.SAV);
};
}
}