From 15ce1acfdb00dead46c11adf8942ea9ff228476c Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 23 Apr 2018 19:11:55 -0700 Subject: [PATCH] update box manipulation closes #1911 , changes end to be inclusive rather than exclusive. abuse the optional to let it fill in the end caps. --- PKHeX.Core/Saves/SaveFile.cs | 12 ++++++------ PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index f6aa4417f..a4db3020a 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -593,8 +593,8 @@ public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func, var BD = BoxData; int start = BoxSlotCount * BoxStart; var Section = BD.Skip(start); - if (BoxEnd > BoxStart) - Section = Section.Take(BoxSlotCount * (BoxEnd - BoxStart)); + if (BoxEnd >= BoxStart) + Section = Section.Take(BoxSlotCount * (BoxEnd - BoxStart + 1)); var Sorted = (sortMethod ?? PKMSorting.OrderBySpecies)(Section); @@ -604,13 +604,13 @@ public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func, public void ClearBoxes(int BoxStart = 0, int BoxEnd = -1) { if (BoxEnd < 0) - BoxEnd = BoxCount; + BoxEnd = BoxCount - 1; var blank = BlankPKM.EncryptedBoxData; if (this is SAV3RSBox) Array.Resize(ref blank, blank.Length + 4); // 00000 TID/SID at end - for (int i = BoxStart; i < BoxEnd; i++) + for (int i = BoxStart; i <= BoxEnd; i++) { int offset = GetBoxOffset(i); for (int p = 0; p < BoxSlotCount; p++) @@ -620,9 +620,9 @@ public void ClearBoxes(int BoxStart = 0, int BoxEnd = -1) public void ModifyBoxes(Action action, int BoxStart = 0, int BoxEnd = -1) { if (BoxEnd < 0) - BoxEnd = BoxCount; + BoxEnd = BoxCount - 1; var BD = BoxData; - for (int b = BoxStart; b < BoxEnd; b++) + for (int b = BoxStart; b <= BoxEnd; b++) for (int s = 0; s < BoxSlotCount; s++) { if (IsSlotLocked(b, s)) diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index 115ff26d5..6afbb6e22 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -392,32 +392,32 @@ public void ClearCurrent() { if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxClearCurrent, MsgSaveBoxClearCurrentFailBattle)) return; - SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox + 1); + SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox); FinishBoxManipulation(MsgSaveBoxClearCurrentSuccess, false); } public void SortAll(Func, IEnumerable> sorter) { if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxSortAll, MsgSaveBoxSortAllFailBattle)) return; - SAV.SortBoxes(0, SAV.BoxCount - 1, sorter); + SAV.SortBoxes(sortMethod: sorter); FinishBoxManipulation(MsgSaveBoxSortAllSuccess, true); } public void SortCurrent(Func, IEnumerable> sorter) { if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxSortCurrent, MsgSaveBoxSortCurrentFailBattle)) return; - SAV.SortBoxes(Box.CurrentBox, Box.CurrentBox + 1, sorter); + SAV.SortBoxes(Box.CurrentBox, Box.CurrentBox, sorter); FinishBoxManipulation(MsgSaveBoxSortCurrentSuccess, false); } public void ModifyAll(Action action) { - SAV.ModifyBoxes(action, 0, SAV.BoxCount - 1); + SAV.ModifyBoxes(action); FinishBoxManipulation(null, true); SystemSounds.Asterisk.Play(); } public void ModifyCurrent(Action action) { - SAV.ModifyBoxes(action, Box.CurrentBox, Box.CurrentBox + 1); + SAV.ModifyBoxes(action, Box.CurrentBox, Box.CurrentBox); FinishBoxManipulation(null, true); SystemSounds.Asterisk.Play(); }