diff --git a/PKHeX.Core/PKM/PKMSorting.cs b/PKHeX.Core/PKM/PKMSorting.cs index 77e925487..f81f499ec 100644 --- a/PKHeX.Core/PKM/PKMSorting.cs +++ b/PKHeX.Core/PKM/PKMSorting.cs @@ -171,7 +171,7 @@ private static IOrderedEnumerable OrderByTrainer(this IOrderedEnumerablePokémon data /// Toggle to check the game's version or not /// True if OT, false if not OT. - private static bool IsOriginalHandler(this ITrainerInfo trainer, PKM pk, bool checkGame) + public static bool IsOriginalHandler(this ITrainerInfo trainer, PKM pk, bool checkGame) { if (pk.Format >= 6) return pk.CurrentHandler != 1; diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index 6afbb6e22..65c6fc8d7 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -13,7 +13,7 @@ namespace PKHeX.WinForms.Controls { - public partial class SAVEditor : UserControl, ISortableDisplay + public partial class SAVEditor : UserControl { public SaveFile SAV; public readonly PictureBox[] SlotPictureBoxes; @@ -381,18 +381,18 @@ private void ClickBoxSort(object sender, MouseEventArgs e) var pt = Tab_Box.PointToScreen(new Point(0, 0)); SortMenu.Show(pt); } - public void ClearAll() + public void ClearAll(Func criteria) { if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxClearAll, MsgSaveBoxClearAllFailBattle)) return; - SAV.ClearBoxes(); + SAV.ClearBoxes(deleteCriteria: criteria); FinishBoxManipulation(MsgSaveBoxClearAllSuccess, true); } - public void ClearCurrent() + public void ClearCurrent(Func criteria) { if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxClearCurrent, MsgSaveBoxClearCurrentFailBattle)) return; - SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox); + SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox, criteria); FinishBoxManipulation(MsgSaveBoxClearCurrentSuccess, false); } public void SortAll(Func, IEnumerable> sorter) diff --git a/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs b/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs index f36962521..02b56b8ca 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/Sorter.cs @@ -12,29 +12,58 @@ public static class Sorter public static ContextMenuStrip GetSortStrip(this SAVEditor sav) { var sortMenu = new ContextMenuStrip(); - var options = new[] + foreach (Level z in Enum.GetValues(typeof(Level))) { - GetItem("mnu_ClearBox", "Clear", Clear, Resources.nocheck), - GetItem("mnu_SortBoxSpecies", "Sort: Pokédex No.", () => Sort(PKMSorting.OrderBySpecies), Resources.numlohi), - GetItem("mnu_SortBoxSpeciesRev", "Sort: Pokédex No. (Reverse)", () => Sort(PKMSorting.OrderByDescendingSpecies), Resources.numhilo), - GetItem("mnu_SortBoxLevel", "Sort: Level (Low to High)", () => Sort(PKMSorting.OrderByLevel), Resources.vallohi), - GetItem("mnu_SortBoxLevelRev", "Sort: Level (High to Low)", () => Sort(PKMSorting.OrderByDescendingLevel), Resources.valhilo), - GetItem("mnu_SortBoxDate", "Sort: Met Date", () => Sort(PKMSorting.OrderByDateObtained), Resources.date), - GetItem("mnu_SortBoxUsage", "Sort: Usage", () => Sort(PKMSorting.OrderByUsage), Resources.heart), - GetItem("mnu_SortBoxName", "Sort: Species Name", () => Sort(list => list.OrderBySpeciesName(GameInfo.Strings.Species)), Resources.alphaAZ), - GetItem("mnu_SortBoxOwner", "Sort: Ownership", () => Sort(list => list.OrderByOwnership(sav.SAV)), Resources.users), - GetItem("mnu_SortBoxLegal", "Sort: Legal", () => Sort(list => list.OrderByCustom(pk => !new LegalityAnalysis(pk).Valid)), Resources.export), - GetItem("mnu_SortBoxRandom", "Sort: Random", () => Sort(list => list.OrderByCustom(_ => Util.Rand32())), Resources.showdown), - GetItem("mnu_ModifyHatch", "Modify: Hatch Eggs", () => Modify(z => z.ForceHatchPKM()), Resources.wand), - }; - sortMenu.Items.AddRange(options); + var ctrl = new ToolStripMenuItem(z.ToString(), GetImage(z)); + sortMenu.Items.Add(ctrl); + } - void Clear() + Image GetImage(Level l) + { + switch (l) + { + case Level.Delete: return Resources.nocheck; + case Level.SortBox: return Resources.swapBox; + case Level.SortBoxAdvanced: return Resources.settings; + case Level.Modify: return Resources.wand; + default: return null; + } + } + + AddItem(Level.Delete, GetItem("All", "Clear", () => Clear(), Resources.nocheck)); + AddItem(Level.Delete, GetItem("Eggs", "Eggs", () => Clear(pk => pk.IsEgg), Resources.about)); + AddItem(Level.Delete, GetItem("Foreign", "Foreign", () => Clear(pk => !sav.SAV.IsOriginalHandler(pk, pk.Format > 2)), Resources.users)); + AddItem(Level.Delete, GetItem("Untrained", "Untrained", () => Clear(pk => pk.EVTotal == 0), Resources.gift)); + + AddItem(Level.SortBox, GetItem("Species", "Pokédex No.", () => Sort(PKMSorting.OrderBySpecies), Resources.numlohi)); + AddItem(Level.SortBox, GetItem("SpeciesRev", "Pokédex No. (Reverse)", () => Sort(PKMSorting.OrderByDescendingSpecies), Resources.numhilo)); + AddItem(Level.SortBox, GetItem("Level", "Level (Low to High)", () => Sort(PKMSorting.OrderByLevel), Resources.vallohi)); + AddItem(Level.SortBox, GetItem("LevelRev", "Level (High to Low)", () => Sort(PKMSorting.OrderByDescendingLevel), Resources.valhilo)); + AddItem(Level.SortBox, GetItem("Date", "Met Date", () => Sort(PKMSorting.OrderByDateObtained), Resources.date)); + AddItem(Level.SortBox, GetItem("Name", "Species Name", () => Sort(list => list.OrderBySpeciesName(GameInfo.Strings.Species)), Resources.alphaAZ)); + AddItem(Level.SortBox, GetItem("Random", "Random", () => Sort(list => list.OrderByCustom(_ => Util.Rand32())), Resources.showdown)); + + AddItem(Level.SortBoxAdvanced, GetItem("Usage", "Usage", () => Sort(PKMSorting.OrderByUsage), Resources.heart)); + AddItem(Level.SortBoxAdvanced, GetItem("Training", "Training", () => Sort(list => list.OrderByCustom(pk => pk.MaxEV * 6 - pk.EVTotal)), Resources.showdown)); + AddItem(Level.SortBoxAdvanced, GetItem("Owner", "Ownership", () => Sort(list => list.OrderByOwnership(sav.SAV)), Resources.users)); + AddItem(Level.SortBoxAdvanced, GetItem("Legal", "Legal", () => Sort(list => list.OrderByCustom(pk => !new LegalityAnalysis(pk).Valid)), Resources.export)); + + AddItem(Level.Modify, GetItem("HatchEggs", "Hatch Eggs", () => Modify(z => z.ForceHatchPKM()), Resources.about)); + AddItem(Level.Modify, GetItem("MaxFriendship", "Max Friendship", () => Modify(z => z.CurrentFriendship = byte.MaxValue), Resources.heart)); + + void AddItem(Level v, ToolStripItem t) + { + var item = (ToolStripMenuItem)sortMenu.Items[(int) v]; + t.Name = $"mnu_{v}{t.Name}"; + item.DropDownItems.Add(t); + } + + void Clear(Func criteria = null) { if (Control.ModifierKeys.HasFlag(Keys.Shift)) - sav.ClearAll(); + sav.ClearAll(criteria); else - sav.ClearCurrent(); + sav.ClearCurrent(criteria); } void Sort(Func, IEnumerable> sorter) @@ -62,13 +91,13 @@ private static ToolStripItem GetItem(string name, string text, Action action, Im tsi.Click += (s, e) => action(); return tsi; } - } - public interface ISortableDisplay - { - void ClearAll(); - void ClearCurrent(); - void SortAll(Func, IEnumerable> sorter); - void SortCurrent(Func, IEnumerable> sorter); + private enum Level + { + Delete, + SortBox, + SortBoxAdvanced, + Modify, + } } }