From 0c2d2ac049979e50ce2eb048aa90ed8a56d47b4c Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 18 Dec 2015 22:17:01 -0800 Subject: [PATCH] Add drag rearrangement of Wonder Cards --- SAV/SAV_Wondercard.cs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/SAV/SAV_Wondercard.cs b/SAV/SAV_Wondercard.cs index 9ce40f390..e69235ef6 100644 --- a/SAV/SAV_Wondercard.cs +++ b/SAV/SAV_Wondercard.cs @@ -402,6 +402,7 @@ namespace PKHeX if (e.Button != MouseButtons.Left || e.Clicks != 1) return; int index = Array.FindIndex(pba, p => p.Name == (sender as PictureBox).Name); + wc_slot = index; // Create Temp File to Drag Cursor.Current = Cursors.Hand; @@ -420,6 +421,7 @@ namespace PKHeX catch (ArgumentException x) { Util.Error("Drag & Drop Error:", x.ToString()); } File.Delete(newfile); + wc_slot = -1; } private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) { @@ -431,18 +433,32 @@ namespace PKHeX index = lastUnfilled; // Check for In-Dropped files (PKX,SAV,ETC) - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); - if (files.Length < 1 || new FileInfo(files[0]).Length != WC6.Size) - return; + if (wc_slot == -1) + { + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); - byte[] wcdata = File.ReadAllBytes(files[0]); - wcdata.CopyTo(sav, Main.SAV.WondercardData + WC6.Size * index); - populateWClist(); + if (files.Length < 1 || new FileInfo(files[0]).Length != WC6.Size) + return; + + byte[] wcdata = File.ReadAllBytes(files[0]); + wcdata.CopyTo(sav, Main.SAV.WondercardData + WC6.Size * index); + wcdata.CopyTo(wondercard_data, 0); + loadwcdata(); + setCardID(BitConverter.ToUInt16(wcdata, 0)); + } + else // Swap Data + { + // Check to see if they copied beyond blank slots. + if (index > Math.Max(wc_slot, lastUnfilled - 1)) + index = Math.Max(wc_slot, lastUnfilled - 1); + byte[] s1 = sav.Skip(Main.SAV.WondercardData + WC6.Size * index).Take(WC6.Size).ToArray(); + byte[] s2 = sav.Skip(Main.SAV.WondercardData + WC6.Size * wc_slot).Take(WC6.Size).ToArray(); + s1.CopyTo(sav, Main.SAV.WondercardData + WC6.Size * wc_slot); + s2.CopyTo(sav, Main.SAV.WondercardData + WC6.Size * index); + } setBackground(index, Properties.Resources.slotView); - Array.Copy(wcdata, wondercard_data, wcdata.Length); - loadwcdata(); - setCardID(BitConverter.ToUInt16(wcdata, 0)); + populateWClist(); } private void pbBoxSlot_DragEnter(object sender, DragEventArgs e) { @@ -451,5 +467,6 @@ namespace PKHeX else if (e.Data != null) // within e.Effect = DragDropEffects.Move; } + private int wc_slot = -1; } } \ No newline at end of file