mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-17 05:48:44 +00:00
show/hide box options based on savefile
retain save provider add optional visibility toggle criteria (not present => always visible) now hides sort/mod/delete if the criteria is not applicable to the current format
This commit is contained in:
parent
700ce00d8e
commit
6c2a864dcc
3 changed files with 95 additions and 71 deletions
|
@ -7,103 +7,53 @@ using PKHeX.WinForms.Properties;
|
|||
|
||||
namespace PKHeX.WinForms.Controls
|
||||
{
|
||||
public static class Sorter
|
||||
public sealed class BoxMenuStrip : ContextMenuStrip
|
||||
{
|
||||
public static ContextMenuStrip GetSortStrip(this SAVEditor sav)
|
||||
private readonly SAVEditor sav;
|
||||
private readonly List<ItemVisibility> CustomItems = new List<ItemVisibility>();
|
||||
|
||||
public BoxMenuStrip(SAVEditor SAV)
|
||||
{
|
||||
var sortMenu = new ContextMenuStrip();
|
||||
sav = SAV;
|
||||
foreach (Level z in Enum.GetValues(typeof(Level)))
|
||||
{
|
||||
var ctrl = new ToolStripMenuItem {Name = $"mnu_{z}", Text = z.ToString(), Image = GetImage(z)};
|
||||
sortMenu.Items.Add(ctrl);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Items.Add(ctrl);
|
||||
}
|
||||
|
||||
AddItem(Level.Delete, GetItem("All", "Clear", () => Clear(), Resources.nocheck));
|
||||
AddItem(Level.Delete, GetItem("Eggs", "Eggs", () => Clear(pk => Control.ModifierKeys == Keys.Control != pk.IsEgg), Resources.about));
|
||||
AddItem(Level.Delete, GetItem("PastGen", "Past Generation", () => Clear(pk => pk.GenNumber != sav.SAV.Generation), Resources.bak));
|
||||
AddItem(Level.Delete, GetItem("Eggs", "Eggs", () => Clear(pk => ModifierKeys == Keys.Control != pk.IsEgg), Resources.about), s => s.Generation >= 2);
|
||||
AddItem(Level.Delete, GetItem("PastGen", "Past Generation", () => Clear(pk => pk.GenNumber != sav.SAV.Generation), Resources.bak), s => s.Generation >= 4);
|
||||
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.Delete, GetItem("Itemless", "No Held Item", () => Clear(pk => pk.HeldItem == 0), Resources.main));
|
||||
AddItem(Level.Delete, GetItem("Illegal", "Illegal", () => Clear(pk => Control.ModifierKeys == Keys.Control != !new LegalityAnalysis(pk).Valid), Resources.export));
|
||||
AddItem(Level.Delete, GetItem("Itemless", "No Held Item", () => Clear(pk => pk.HeldItem == 0), Resources.main), s => s.Generation >= 2);
|
||||
AddItem(Level.Delete, GetItem("Illegal", "Illegal", () => Clear(pk => ModifierKeys == Keys.Control != !new LegalityAnalysis(pk).Valid), Resources.export));
|
||||
|
||||
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("Date", "Met Date", () => Sort(PKMSorting.OrderByDateObtained), Resources.date), s => s.Generation >= 4);
|
||||
AddItem(Level.SortBox, GetItem("Name", "Species Name", () => Sort(list => list.OrderBySpeciesName(GameInfo.Strings.Species)), Resources.alphaAZ));
|
||||
AddItem(Level.SortBox, GetItem("Shiny", "Shiny", () => Sort(list => list.OrderByCustom(pk => !pk.IsShiny)), Resources.showdown));
|
||||
AddItem(Level.SortBox, GetItem("Random", "Random", () => Sort(list => list.OrderByCustom(_ => Util.Rand32())), Resources.wand));
|
||||
|
||||
AddItem(Level.SortBoxAdvanced, GetItem("Usage", "Usage", () => Sort(PKMSorting.OrderByUsage), Resources.heart));
|
||||
AddItem(Level.SortBoxAdvanced, GetItem("Usage", "Usage", () => Sort(PKMSorting.OrderByUsage), Resources.heart), s => s.Generation >= 3);
|
||||
AddItem(Level.SortBoxAdvanced, GetItem("Potential", "IV Potential", () => Sort(list => list.OrderByCustom(pk => pk.MaxIV * 6 - pk.IVTotal)), Resources.numhilo));
|
||||
AddItem(Level.SortBoxAdvanced, GetItem("Training", "EV 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("Type", "Type", () => Sort(list => list.OrderByCustom(pk => pk.PersonalInfo.Type1, pk => pk.PersonalInfo.Type2)), Resources.main));
|
||||
AddItem(Level.SortBoxAdvanced, GetItem("Version", "Version", () => Sort(list => list.OrderByCustom(pk => pk.GenNumber, pk => pk.Version)), Resources.numlohi));
|
||||
AddItem(Level.SortBoxAdvanced, GetItem("Version", "Version", () => Sort(list => list.OrderByCustom(pk => pk.GenNumber, pk => pk.Version)), Resources.numlohi), s => s.Generation >= 3);
|
||||
AddItem(Level.SortBoxAdvanced, GetItem("BST", "Base Stat Total", () => Sort(list => list.OrderByCustom(pk => pk.PersonalInfo.BST)), Resources.vallohi));
|
||||
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("HatchEggs", "Hatch Eggs", () => Modify(z => z.ForceHatchPKM()), Resources.about), s => s.Generation >= 2);
|
||||
AddItem(Level.Modify, GetItem("MaxFriendship", "Max Friendship", () => Modify(z => z.MaximizeFriendship()), Resources.heart));
|
||||
AddItem(Level.Modify, GetItem("MaxLevel", "Max Level", () => Modify(z => z.MaximizeLevel()), Resources.showdown));
|
||||
AddItem(Level.Modify, GetItem("Reset Moves", "Reset Moves", () => Modify(z => z.SetMoves(z.GetMoveSet())), Resources.date));
|
||||
AddItem(Level.Modify, GetItem("ResetMoves", "Reset Moves", () => Modify(z => z.SetMoves(z.GetMoveSet())), Resources.date));
|
||||
AddItem(Level.Modify, GetItem("RandomMoves", "Randomize Moves", () => Modify(z => z.SetMoves(z.GetMoveSet(true))), Resources.wand));
|
||||
AddItem(Level.Modify, GetItem("HyperTrain", "Hyper Train", () => Modify(z => z.SetSuggestedHyperTrainingData()), Resources.vallohi));
|
||||
AddItem(Level.Modify, GetItem("RemoveItem", "Delete Held Item", () => Modify(z => z.HeldItem = 0), Resources.gift));
|
||||
|
||||
void AddItem(Level v, ToolStripItem t)
|
||||
{
|
||||
var item = (ToolStripMenuItem)sortMenu.Items[(int) v];
|
||||
t.Name = $"{item.Name}{t.Name}";
|
||||
item.DropDownItems.Add(t);
|
||||
}
|
||||
|
||||
void Clear(Func<PKM, bool> criteria = null)
|
||||
{
|
||||
if (Control.ModifierKeys.HasFlag(Keys.Shift))
|
||||
sav.ClearAll(criteria);
|
||||
else
|
||||
sav.ClearCurrent(criteria);
|
||||
}
|
||||
|
||||
void Sort(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
|
||||
{
|
||||
bool reverse = Control.ModifierKeys.HasFlag(Keys.Control);
|
||||
if (Control.ModifierKeys.HasFlag(Keys.Shift))
|
||||
sav.SortAll(sorter, reverse);
|
||||
else
|
||||
sav.SortCurrent(sorter, reverse);
|
||||
}
|
||||
|
||||
void Modify(Action<PKM> action)
|
||||
{
|
||||
if (Control.ModifierKeys.HasFlag(Keys.Shift))
|
||||
sav.ModifyAll(action);
|
||||
else
|
||||
sav.ModifyCurrent(action);
|
||||
}
|
||||
|
||||
return sortMenu;
|
||||
}
|
||||
|
||||
private static ToolStripItem GetItem(string name, string text, Action action, Image img)
|
||||
{
|
||||
var tsi = new ToolStripMenuItem {Name = name, Text = text, Image = img};
|
||||
tsi.Click += (s, e) => action();
|
||||
return tsi;
|
||||
AddItem(Level.Modify, GetItem("HyperTrain", "Hyper Train", () => Modify(z => z.SetSuggestedHyperTrainingData()), Resources.vallohi), s => s.Generation >= 7);
|
||||
AddItem(Level.Modify, GetItem("RemoveItem", "Delete Held Item", () => Modify(z => z.HeldItem = 0), Resources.gift), s => s.Generation >= 2);
|
||||
}
|
||||
|
||||
private enum Level
|
||||
|
@ -113,5 +63,76 @@ namespace PKHeX.WinForms.Controls
|
|||
SortBoxAdvanced,
|
||||
Modify,
|
||||
}
|
||||
|
||||
private sealed class ItemVisibility
|
||||
{
|
||||
private readonly ToolStripItem Item;
|
||||
private readonly Func<SaveFile, bool> IsVisible;
|
||||
|
||||
public ItemVisibility(ToolStripItem toolStripItem, Func<SaveFile, bool> visible)
|
||||
{
|
||||
Item = toolStripItem;
|
||||
IsVisible = visible;
|
||||
}
|
||||
|
||||
public void SetVisibility(SaveFile s) => Item.Visible = IsVisible(s);
|
||||
}
|
||||
|
||||
public void ToggleVisibility()
|
||||
{
|
||||
foreach (var s in CustomItems)
|
||||
s.SetVisibility(sav.SAV);
|
||||
}
|
||||
|
||||
private static 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;
|
||||
}
|
||||
}
|
||||
|
||||
private static ToolStripItem GetItem(string name, string text, Action action, Image img)
|
||||
{
|
||||
var tsi = new ToolStripMenuItem { Name = name, Text = text, Image = img };
|
||||
tsi.Click += (s, e) => action();
|
||||
return tsi;
|
||||
}
|
||||
|
||||
private void AddItem(Level v, ToolStripItem t, Func<SaveFile, bool> visible = null)
|
||||
{
|
||||
var item = (ToolStripMenuItem)Items[(int)v];
|
||||
t.Name = item.Name + t.Name;
|
||||
item.DropDownItems.Add(t);
|
||||
CustomItems.Add(new ItemVisibility(t, visible ?? (_ => true)));
|
||||
}
|
||||
|
||||
private static bool All => (ModifierKeys & Keys.Shift) != 0;
|
||||
private static bool Reverse => (ModifierKeys & Keys.Control) != 0;
|
||||
private void Clear(Func<PKM, bool> criteria = null)
|
||||
{
|
||||
if (All)
|
||||
sav.ClearAll(criteria);
|
||||
else
|
||||
sav.ClearCurrent(criteria);
|
||||
}
|
||||
private void Sort(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
|
||||
{
|
||||
if (All)
|
||||
sav.SortAll(sorter, Reverse);
|
||||
else
|
||||
sav.SortCurrent(sorter, Reverse);
|
||||
}
|
||||
private void Modify(Action<PKM> action)
|
||||
{
|
||||
if (All)
|
||||
sav.ModifyAll(action);
|
||||
else
|
||||
sav.ModifyCurrent(action);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ namespace PKHeX.WinForms.Controls
|
|||
public readonly Stack<SlotChange> UndoStack = new Stack<SlotChange>();
|
||||
public readonly Stack<SlotChange> RedoStack = new Stack<SlotChange>();
|
||||
public readonly ContextMenuSAV menu = new ContextMenuSAV();
|
||||
public readonly ContextMenuStrip SortMenu;
|
||||
public readonly BoxMenuStrip SortMenu;
|
||||
|
||||
public bool HaX;
|
||||
public bool ModifyPKM;
|
||||
|
@ -92,7 +92,7 @@ namespace PKHeX.WinForms.Controls
|
|||
|
||||
GB_Daycare.Click += SwitchDaycare;
|
||||
FLP_SAVtools.Scroll += WinFormsUtil.PanelScroll;
|
||||
SortMenu = this.GetSortStrip();
|
||||
SortMenu = new BoxMenuStrip(this);
|
||||
|
||||
M.OtherSlots.Add(this);
|
||||
SL_Extra.ViewIndex = -2;
|
||||
|
@ -964,6 +964,7 @@ namespace PKHeX.WinForms.Controls
|
|||
Box.M = M;
|
||||
Box.ResetBoxNames(); // Display the Box Names
|
||||
M.SetColor(-1, -1, null);
|
||||
SortMenu.ToggleVisibility();
|
||||
}
|
||||
private bool ToggleViewBox(SaveFile sav)
|
||||
{
|
||||
|
|
|
@ -211,7 +211,9 @@
|
|||
<DependentUpon>SlotList.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\SAV Editor\SlotViewer.cs" />
|
||||
<Compile Include="Controls\SAV Editor\Sorter.cs" />
|
||||
<Compile Include="Controls\SAV Editor\BoxMenuStrip.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow\Main.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
Loading…
Add table
Reference in a new issue