From b16a2f9ad239c18b62673cb8fb533799d749296e Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 23 Jan 2018 22:37:55 -0800 Subject: [PATCH] Add box rearranging enables the left/right arrows on each box to allow switching with the adjacent box --- .../Controls/SAV Editor/BoxEditor.Designer.cs | 6 ++--- .../Controls/SAV Editor/BoxEditor.cs | 12 ++++++++-- .../Controls/SAV Editor/SlotChangeManager.cs | 16 +++++++++++++ .../Subforms/Save Editors/SAV_BoxList.cs | 24 +++++++++++++++++-- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.Designer.cs b/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.Designer.cs index a2ef4e2a4..7cfb97ede 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.Designer.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.Designer.cs @@ -574,8 +574,8 @@ private System.Windows.Forms.PictureBox bpkx3; private System.Windows.Forms.PictureBox bpkx2; private System.Windows.Forms.PictureBox bpkx1; - private System.Windows.Forms.Button B_BoxRight; - private System.Windows.Forms.Button B_BoxLeft; - private System.Windows.Forms.ComboBox CB_BoxSelect; + public System.Windows.Forms.Button B_BoxRight; + public System.Windows.Forms.Button B_BoxLeft; + public System.Windows.Forms.ComboBox CB_BoxSelect; } } diff --git a/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs index b0eef077d..548716b2c 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/BoxEditor.cs @@ -98,7 +98,7 @@ namespace PKHeX.WinForms.Controls pb.BackgroundImage = M.colorizedcolor; } - public void ResetBoxNames() + public void ResetBoxNames(int box = -1) { if (!SAV.HasBox) return; @@ -110,8 +110,10 @@ namespace PKHeX.WinForms.Controls catch { getBoxNamesDefault(); } } - if (SAV.CurrentBox < CB_BoxSelect.Items.Count) + if (box < 0 && SAV.CurrentBox < CB_BoxSelect.Items.Count) CurrentBox = SAV.CurrentBox; // restore selected box + else + CurrentBox = box; void getBoxNamesFromSave() { @@ -170,6 +172,12 @@ namespace PKHeX.WinForms.Controls } return false; } + public void ClearEvents() + { + B_BoxRight.Click -= ClickBoxRight; + B_BoxLeft.Click -= ClickBoxLeft; + CB_BoxSelect.SelectedIndexChanged -= GetBox; + } public int GetSlot(object sender) => SlotPictureBoxes.IndexOf(WinFormsUtil.GetUnderlyingControl(sender) as PictureBox); diff --git a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs index 26b9c2de5..c6f061a8f 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs @@ -403,6 +403,22 @@ namespace PKHeX.WinForms.Controls SE.SetParty(); } + // Utility + public void SwapBoxes(int index, int other) + { + if (index == other) + return; + SAV.SwapBox(index, other); + + foreach (var box in Boxes) + { + if (box.CurrentBox != index && box.CurrentBox != other) + continue; + box.ResetSlots(); + box.ResetBoxNames(box.CurrentBox); + } + } + public void Dispose() { SE?.Dispose(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs index c16c89731..82b1baf0b 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_BoxList.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Windows.Forms; + +using PKHeX.Core; using PKHeX.WinForms.Controls; namespace PKHeX.WinForms @@ -41,7 +43,7 @@ namespace PKHeX.WinForms }; } - private void AddControls(SAVEditor p, SlotChangeManager m, Core.SaveFile sav) + private void AddControls(SAVEditor p, SlotChangeManager m, SaveFile sav) { for (int i = 0; i < sav.BoxCount; i++) { @@ -50,10 +52,28 @@ namespace PKHeX.WinForms pb.ContextMenuStrip = p.SlotPictureBoxes[0].ContextMenuStrip; boxEditor.Setup(m); boxEditor.CurrentBox = i; - boxEditor.ControlsEnabled = false; + boxEditor.CB_BoxSelect.Enabled = false; Boxes.Add(boxEditor); FLP_Boxes.Controls.Add(Boxes[i]); } + + // Setup swapping + foreach (var box in Boxes) + { + box.ClearEvents(); + box.B_BoxLeft.Click += (s, e) => + { + int index = Boxes.FindIndex(z => z == ((Button)s).Parent); + int other = (index + Boxes.Count - 1) % Boxes.Count; + m.SwapBoxes(index, other); + }; + 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); + }; + } } private void SetWindowDimensions(int count)