Update 'sorter' with more functionality

Nest item choices into separated groups (based on their overall
function).

Adds 3 more deletion options: eggs, untrained, or not-matching-savefile.
Adds 1 more modification option: Max Friendship of current handler
This commit is contained in:
Kurt 2018-04-30 17:32:23 -07:00
parent 57c625d089
commit bbcbdd80a1
3 changed files with 60 additions and 31 deletions

View file

@ -171,7 +171,7 @@ namespace PKHeX.Core
/// <param name="pk">Pokémon data</param> /// <param name="pk">Pokémon data</param>
/// <param name="checkGame">Toggle to check the game's version or not</param> /// <param name="checkGame">Toggle to check the game's version or not</param>
/// <returns>True if OT, false if not OT.</returns> /// <returns>True if OT, false if not OT.</returns>
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) if (pk.Format >= 6)
return pk.CurrentHandler != 1; return pk.CurrentHandler != 1;

View file

@ -13,7 +13,7 @@ using static PKHeX.Core.MessageStrings;
namespace PKHeX.WinForms.Controls namespace PKHeX.WinForms.Controls
{ {
public partial class SAVEditor : UserControl, ISortableDisplay public partial class SAVEditor : UserControl
{ {
public SaveFile SAV; public SaveFile SAV;
public readonly PictureBox[] SlotPictureBoxes; public readonly PictureBox[] SlotPictureBoxes;
@ -381,18 +381,18 @@ namespace PKHeX.WinForms.Controls
var pt = Tab_Box.PointToScreen(new Point(0, 0)); var pt = Tab_Box.PointToScreen(new Point(0, 0));
SortMenu.Show(pt); SortMenu.Show(pt);
} }
public void ClearAll() public void ClearAll(Func<PKM, bool> criteria)
{ {
if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxClearAll, MsgSaveBoxClearAllFailBattle)) if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxClearAll, MsgSaveBoxClearAllFailBattle))
return; return;
SAV.ClearBoxes(); SAV.ClearBoxes(deleteCriteria: criteria);
FinishBoxManipulation(MsgSaveBoxClearAllSuccess, true); FinishBoxManipulation(MsgSaveBoxClearAllSuccess, true);
} }
public void ClearCurrent() public void ClearCurrent(Func<PKM, bool> criteria)
{ {
if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxClearCurrent, MsgSaveBoxClearCurrentFailBattle)) if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxClearCurrent, MsgSaveBoxClearCurrentFailBattle))
return; return;
SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox); SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox, criteria);
FinishBoxManipulation(MsgSaveBoxClearCurrentSuccess, false); FinishBoxManipulation(MsgSaveBoxClearCurrentSuccess, false);
} }
public void SortAll(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter) public void SortAll(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)

View file

@ -12,29 +12,58 @@ namespace PKHeX.WinForms.Controls
public static ContextMenuStrip GetSortStrip(this SAVEditor sav) public static ContextMenuStrip GetSortStrip(this SAVEditor sav)
{ {
var sortMenu = new ContextMenuStrip(); var sortMenu = new ContextMenuStrip();
var options = new[] foreach (Level z in Enum.GetValues(typeof(Level)))
{ {
GetItem("mnu_ClearBox", "Clear", Clear, Resources.nocheck), var ctrl = new ToolStripMenuItem(z.ToString(), GetImage(z));
GetItem("mnu_SortBoxSpecies", "Sort: Pokédex No.", () => Sort(PKMSorting.OrderBySpecies), Resources.numlohi), sortMenu.Items.Add(ctrl);
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);
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<PKM, bool> criteria = null)
{ {
if (Control.ModifierKeys.HasFlag(Keys.Shift)) if (Control.ModifierKeys.HasFlag(Keys.Shift))
sav.ClearAll(); sav.ClearAll(criteria);
else else
sav.ClearCurrent(); sav.ClearCurrent(criteria);
} }
void Sort(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter) void Sort(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
@ -62,13 +91,13 @@ namespace PKHeX.WinForms.Controls
tsi.Click += (s, e) => action(); tsi.Click += (s, e) => action();
return tsi; return tsi;
} }
}
public interface ISortableDisplay private enum Level
{ {
void ClearAll(); Delete,
void ClearCurrent(); SortBox,
void SortAll(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter); SortBoxAdvanced,
void SortCurrent(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter); Modify,
}
} }
} }