diff --git a/PKHeX.Core/PKM/PKMSorting.cs b/PKHeX.Core/PKM/PKMSorting.cs index f81f499ec..6fc989bac 100644 --- a/PKHeX.Core/PKM/PKMSorting.cs +++ b/PKHeX.Core/PKM/PKMSorting.cs @@ -128,6 +128,19 @@ namespace PKHeX.Core .FinalSortBy(); } + /// + /// Sorts an list of objects in reverse. + /// + /// Source list to revese sort + /// Enumerable list that is sorted + public static IEnumerable ReverseSort(this IEnumerable list) + { + int i = 0; + return list.InitialSortBy() + .ThenByDescending(z => i++) + .FinalSortBy(); + } + /// /// Common pre-filtering of data. /// diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index bb6ff7a7a..22c07a067 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -588,7 +588,7 @@ namespace PKHeX.Core } public virtual bool IsSlotInBattleTeam(int box, int slot) => false; - public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func, IEnumerable> sortMethod = null) + public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func, IEnumerable> sortMethod = null, bool reverse = false) { var BD = BoxData; int start = BoxSlotCount * BoxStart; @@ -597,6 +597,8 @@ namespace PKHeX.Core Section = Section.Take(BoxSlotCount * (BoxEnd - BoxStart + 1)); var Sorted = (sortMethod ?? PKMSorting.OrderBySpecies)(Section); + if (reverse) + Sorted = Sorted.ReverseSort(); Sorted.CopyTo(BD, start); BoxData = BD; diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index 65c6fc8d7..972c8c96b 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -395,18 +395,18 @@ namespace PKHeX.WinForms.Controls SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox, criteria); FinishBoxManipulation(MsgSaveBoxClearCurrentSuccess, false); } - public void SortAll(Func, IEnumerable> sorter) + public void SortAll(Func, IEnumerable> sorter, bool reverse) { if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxSortAll, MsgSaveBoxSortAllFailBattle)) return; - SAV.SortBoxes(sortMethod: sorter); + SAV.SortBoxes(sortMethod: sorter, reverse: reverse); FinishBoxManipulation(MsgSaveBoxSortAllSuccess, true); } - public void SortCurrent(Func, IEnumerable> sorter) + public void SortCurrent(Func, IEnumerable> sorter, bool reverse) { if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxSortCurrent, MsgSaveBoxSortCurrentFailBattle)) return; - SAV.SortBoxes(Box.CurrentBox, Box.CurrentBox, sorter); + SAV.SortBoxes(Box.CurrentBox, Box.CurrentBox, sorter, reverse: reverse); FinishBoxManipulation(MsgSaveBoxSortCurrentSuccess, false); } public void ModifyAll(Action action) diff --git a/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs b/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs index f43259d0c..3e970e013 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs @@ -71,10 +71,11 @@ namespace PKHeX.WinForms.Controls void Sort(Func, IEnumerable> sorter) { + bool reverse = Control.ModifierKeys.HasFlag(Keys.Control); if (Control.ModifierKeys.HasFlag(Keys.Shift)) - sav.SortAll(sorter); + sav.SortAll(sorter, reverse); else - sav.SortCurrent(sorter); + sav.SortCurrent(sorter, reverse); } void Modify(Action action)