Separate box manipulator to ui-less class

clear separation of functionality
This commit is contained in:
Kurt 2018-09-02 11:31:34 -07:00
parent cc20bb38d7
commit f57e7bf686
17 changed files with 518 additions and 294 deletions

View file

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
{
public sealed class BoxManipClear : IBoxManip
{
public BoxManipType Type { get; }
public Func<SaveFile, bool> Usable { get; set; }
public string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxClearAll : MessageStrings.MsgSaveBoxClearCurrent;
public string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxClearAllFailBattle : MessageStrings.MsgSaveBoxClearCurrentFailBattle;
public string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxClearAllSuccess : MessageStrings.MsgSaveBoxClearCurrentSuccess;
private readonly Func<PKM, bool> CriteriaSimple;
private readonly Func<PKM, SaveFile, bool> CriteriaSAV;
public bool Execute(SaveFile SAV, BoxManipParam param)
{
bool Method(PKM p) => param.Reverse ^ (CriteriaSAV?.Invoke(p, SAV) ?? CriteriaSimple?.Invoke(p) ?? true);
SAV.ClearBoxes(param.Start, param.Stop, Method);
return true;
}
private BoxManipClear(BoxManipType type, Func<PKM, bool> criteria, Func<SaveFile, bool> usable = null)
{
Type = type;
CriteriaSimple = criteria;
Usable = usable;
}
private BoxManipClear(BoxManipType type, Func<PKM, SaveFile, bool> criteria, Func<SaveFile, bool> usable = null)
{
Type = type;
CriteriaSAV = criteria;
Usable = usable;
}
public static readonly IReadOnlyList<BoxManipClear> Common = new List<BoxManipClear>
{
new BoxManipClear(BoxManipType.DeleteAll, _ => true),
new BoxManipClear(BoxManipType.DeleteEggs, pk => pk.IsEgg, s => s.Generation >= 2),
new BoxManipClear(BoxManipType.DeletePastGen, (pk, sav) => pk.GenNumber != sav.Generation, s => s.Generation >= 4),
new BoxManipClear(BoxManipType.DeleteForeign, (pk, sav) => !sav.IsOriginalHandler(pk, pk.Format > 2)),
new BoxManipClear(BoxManipType.DeleteUntrained, pk => pk.EVTotal == 0),
new BoxManipClear(BoxManipType.DeleteItemless, pk => pk.HeldItem == 0),
new BoxManipClear(BoxManipType.DeleteIllegal, pk => !new LegalityAnalysis(pk).Valid),
};
}
}

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
{
public sealed class BoxManipModify : IBoxManip
{
public BoxManipType Type { get; }
public Func<SaveFile, bool> Usable { get; set; }
public string GetPrompt(bool all) => null;
public string GetFail(bool all) => null;
public string GetSuccess(bool all) => null;
private readonly Action<PKM> Action;
private readonly Action<PKM, SaveFile> ActionComplex;
public bool Execute(SaveFile SAV, BoxManipParam param)
{
var method = Action ?? (px => ActionComplex(px, SAV));
SAV.ModifyBoxes(method, param.Start, param.Stop);
return true;
}
private BoxManipModify(BoxManipType type, Action<PKM> action, Func<SaveFile, bool> usable = null)
{
Type = type;
Action = action;
Usable = usable;
}
private BoxManipModify(BoxManipType type, Action<PKM, SaveFile> action, Func<SaveFile, bool> usable = null)
{
Type = type;
ActionComplex = action;
Usable = usable;
}
public static readonly IReadOnlyList<BoxManipModify> Common = new List<BoxManipModify>
{
new BoxManipModify(BoxManipType.ModifyHatchEggs, pk => pk.ForceHatchPKM(), s => s.Generation >= 2),
new BoxManipModify(BoxManipType.ModifyMaxFriendship, pk => pk.MaximizeFriendship()),
new BoxManipModify(BoxManipType.ModifyMaxLevel, pk => pk.MaximizeLevel()),
new BoxManipModify(BoxManipType.ModifyResetMoves, pk => pk.SetMoves(pk.GetMoveSet()), s => s.Generation >= 3),
new BoxManipModify(BoxManipType.ModifyRandomMoves, pk => pk.SetMoves(pk.GetMoveSet(true))),
new BoxManipModify(BoxManipType.ModifyHyperTrain,pk => pk.SetSuggestedHyperTrainingData(), s => s.Generation >= 7),
new BoxManipModify(BoxManipType.ModifyRemoveNicknames, pk => pk.SetDefaultNickname()),
new BoxManipModify(BoxManipType.ModifyRemoveItem, pk => pk.HeldItem = 0, s => s.Generation >= 2),
};
}
}

View file

@ -0,0 +1,9 @@
namespace PKHeX.Core
{
public struct BoxManipParam
{
public int Start { get; set; }
public int Stop { get; set; }
public bool Reverse { get; set; }
}
}

View file

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
namespace PKHeX.Core
{
public sealed class BoxManipSort : IBoxManip
{
public BoxManipType Type { get; }
public Func<SaveFile, bool> Usable { get; set; }
public string GetPrompt(bool all) => all ? MessageStrings.MsgSaveBoxSortAll : MessageStrings.MsgSaveBoxSortCurrent;
public string GetFail(bool all) => all ? MessageStrings.MsgSaveBoxSortAllFailBattle: MessageStrings.MsgSaveBoxSortCurrentFailBattle;
public string GetSuccess(bool all) => all ? MessageStrings.MsgSaveBoxSortAllSuccess : MessageStrings.MsgSaveBoxSortCurrentSuccess;
private readonly Func<IEnumerable<PKM>, IEnumerable<PKM>> SorterSimple;
private readonly Func<IEnumerable<PKM>, SaveFile, IEnumerable<PKM>> SorterComplex;
public bool Execute(SaveFile SAV, BoxManipParam param)
{
IEnumerable<PKM> Method(IEnumerable<PKM> p) => SorterSimple != null ? SorterSimple(p) : SorterComplex(p, SAV);
SAV.SortBoxes(param.Start, param.Stop, Method, param.Reverse);
return true;
}
private BoxManipSort(BoxManipType type, Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter, Func<SaveFile, bool> usable = null)
{
Type = type;
SorterSimple = sorter;
Usable = usable;
}
private BoxManipSort(BoxManipType type, Func<IEnumerable<PKM>, SaveFile, IEnumerable<PKM>> sorter, Func<SaveFile, bool> usable = null)
{
Type = type;
SorterComplex = sorter;
Usable = usable;
}
public static readonly IReadOnlyList<BoxManipSort> Common = new List<BoxManipSort>
{
new BoxManipSort(BoxManipType.SortSpecies, PKMSorting.OrderBySpecies),
new BoxManipSort(BoxManipType.SortSpeciesReverse, PKMSorting.OrderByDescendingSpecies),
new BoxManipSort(BoxManipType.SortLevel, PKMSorting.OrderByLevel),
new BoxManipSort(BoxManipType.SortLevelReverse, PKMSorting.OrderByDescendingLevel),
new BoxManipSort(BoxManipType.SortDate, PKMSorting.OrderByDateObtained, s => s.Generation >= 4),
new BoxManipSort(BoxManipType.SortName, list => list.OrderBySpeciesName(GameInfo.Strings.Species)),
new BoxManipSort(BoxManipType.SortShiny, list => list.OrderByCustom(pk => !pk.IsShiny)),
new BoxManipSort(BoxManipType.SortRandom, list => list.OrderByCustom(_ => Util.Rand32())),
};
public static readonly IReadOnlyList<BoxManipSort> Advanced = new List<BoxManipSort>
{
new BoxManipSort(BoxManipType.SortUsage, PKMSorting.OrderByUsage, s => s.Generation >= 3),
new BoxManipSort(BoxManipType.SortPotential, list => list.OrderByCustom(pk => (pk.MaxIV * 6) - pk.IVTotal)),
new BoxManipSort(BoxManipType.SortTraining, list => list.OrderByCustom(pk => (pk.MaxEV * 6) - pk.EVTotal)),
new BoxManipSort(BoxManipType.SortOwner, (list, sav) => list.OrderByOwnership(sav)),
new BoxManipSort(BoxManipType.SortType, list => list.OrderByCustom(pk => pk.PersonalInfo.Type1, pk => pk.PersonalInfo.Type2)),
new BoxManipSort(BoxManipType.SortVersion, list => list.OrderByCustom(pk => pk.GenNumber, pk => pk.Version), s => s.Generation >= 3),
new BoxManipSort(BoxManipType.SortBST, list => list.OrderByCustom(pk => pk.PersonalInfo.BST)),
new BoxManipSort(BoxManipType.SortLegal, list => list.OrderByCustom(pk => !new LegalityAnalysis(pk).Valid)),
};
}
}

View file

@ -0,0 +1,40 @@
namespace PKHeX.Core
{
public enum BoxManipType
{
DeleteAll,
DeleteEggs,
DeletePastGen,
DeleteForeign,
DeleteUntrained,
DeleteItemless,
DeleteIllegal,
SortSpecies,
SortSpeciesReverse,
SortLevel,
SortLevelReverse,
SortDate,
SortName,
SortShiny,
SortRandom,
SortUsage,
SortPotential,
SortTraining,
SortOwner,
SortType,
SortVersion,
SortBST,
SortLegal,
ModifyHatchEggs,
ModifyMaxFriendship,
ModifyMaxLevel,
ModifyResetMoves,
ModifyRandomMoves,
ModifyHyperTrain,
ModifyRemoveNicknames,
ModifyRemoveItem,
}
}

View file

@ -0,0 +1,40 @@
namespace PKHeX.Core
{
public abstract class BoxManipulator
{
protected abstract SaveFile SAV { get; }
public bool Execute(IBoxManip manip, int box, bool allBoxes, bool reverse = false)
{
bool usable = manip.Usable?.Invoke(SAV) ?? true;
if (!usable)
return false;
// determine start/stop
int start = allBoxes ? 0 : box;
int stop = allBoxes ? SAV.BoxCount - 1 : box;
var prompt = manip.GetPrompt(allBoxes);
var fail = manip.GetFail(allBoxes);
if (!CanManipulateRegion(start, stop, prompt, fail))
return false;
var param = new BoxManipParam
{
Reverse = reverse,
Start = start,
Stop = stop,
};
var result = manip.Execute(SAV, param);
if (!result)
return false;
var success = manip.GetSuccess(allBoxes);
FinishBoxManipulation(success, allBoxes);
return true;
}
protected virtual bool CanManipulateRegion(int start, int end, string prompt, string fail) => !SAV.IsAnySlotLockedInBox(start, end);
protected abstract void FinishBoxManipulation(string message, bool all);
}
}

View file

@ -0,0 +1,16 @@
using System;
namespace PKHeX.Core
{
public interface IBoxManip
{
BoxManipType Type { get; }
Func<SaveFile, bool> Usable { get; set; }
string GetPrompt(bool all);
string GetFail(bool all);
string GetSuccess(bool all);
bool Execute(SaveFile SAV, BoxManipParam param);
}
}

View file

@ -240,24 +240,24 @@ Main.mnu_ModifyRandomMoves=Randomize Moves
Main.mnu_ModifyRemoveItem=Delete Held Item
Main.mnu_ModifyRemoveNicknames=Remove Nicknames
Main.mnu_ModifyResetMoves=Reset Moves
Main.mnu_SortBox=Sort Boxes
Main.mnu_SortBoxAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBoxAdvancedBST=Base Stat Total
Main.mnu_SortBoxAdvancedLegal=Legal
Main.mnu_SortBoxAdvancedOwner=Ownership
Main.mnu_SortBoxAdvancedPotential=IV Potential
Main.mnu_SortBoxAdvancedTraining=EV Training
Main.mnu_SortBoxAdvancedType=Type
Main.mnu_SortBoxAdvancedUsage=Usage
Main.mnu_SortBoxAdvancedVersion=Version
Main.mnu_SortBoxDate=Met Date
Main.mnu_SortBoxLevel=Level (Low to High)
Main.mnu_SortBoxLevelRev=Level (High to Low)
Main.mnu_SortBoxName=Species Name
Main.mnu_SortBoxRandom=Random
Main.mnu_SortBoxShiny=Shiny
Main.mnu_SortBoxSpecies=Pokédex No.
Main.mnu_SortBoxSpeciesRev=Pokédex No. (Reverse)
Main.mnu_Sort=Sort Boxes
Main.mnu_SortAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBST=Base Stat Total
Main.mnu_SortLegal=Legal
Main.mnu_SortOwner=Ownership
Main.mnu_SortPotential=IV Potential
Main.mnu_SortTraining=EV Training
Main.mnu_SortType=Type
Main.mnu_SortUsage=Usage
Main.mnu_SortVersion=Version
Main.mnu_SortDate=Met Date
Main.mnu_SortLevel=Level (Low to High)
Main.mnu_SortLevelReverse=Level (High to Low)
Main.mnu_SortName=Species Name
Main.mnu_SortRandom=Random
Main.mnu_SortShiny=Shiny
Main.mnu_SortSpecies=Pokédex No.
Main.mnu_SortSpeciesReverse=Pokédex No. (Reverse)
Main.mnuDelete=Löschen
Main.mnuLegality=Legality
Main.mnuLLegality=Legality

View file

@ -240,24 +240,24 @@ Main.mnu_ModifyRandomMoves=Randomize Moves
Main.mnu_ModifyRemoveItem=Delete Held Item
Main.mnu_ModifyRemoveNicknames=Remove Nicknames
Main.mnu_ModifyResetMoves=Reset Moves
Main.mnu_SortBox=Sort Boxes
Main.mnu_SortBoxAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBoxAdvancedBST=Base Stat Total
Main.mnu_SortBoxAdvancedLegal=Legal
Main.mnu_SortBoxAdvancedOwner=Ownership
Main.mnu_SortBoxAdvancedPotential=IV Potential
Main.mnu_SortBoxAdvancedTraining=EV Training
Main.mnu_SortBoxAdvancedType=Type
Main.mnu_SortBoxAdvancedUsage=Usage
Main.mnu_SortBoxAdvancedVersion=Version
Main.mnu_SortBoxDate=Met Date
Main.mnu_SortBoxLevel=Level (Low to High)
Main.mnu_SortBoxLevelRev=Level (High to Low)
Main.mnu_SortBoxName=Species Name
Main.mnu_SortBoxRandom=Random
Main.mnu_SortBoxShiny=Shiny
Main.mnu_SortBoxSpecies=Pokédex No.
Main.mnu_SortBoxSpeciesRev=Pokédex No. (Reverse)
Main.mnu_Sort=Sort Boxes
Main.mnu_SortAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBST=Base Stat Total
Main.mnu_SortLegal=Legal
Main.mnu_SortOwner=Ownership
Main.mnu_SortPotential=IV Potential
Main.mnu_SortTraining=EV Training
Main.mnu_SortType=Type
Main.mnu_SortUsage=Usage
Main.mnu_SortVersion=Version
Main.mnu_SortDate=Met Date
Main.mnu_SortLevel=Level (Low to High)
Main.mnu_SortLevelReverse=Level (High to Low)
Main.mnu_SortName=Species Name
Main.mnu_SortRandom=Random
Main.mnu_SortShiny=Shiny
Main.mnu_SortSpecies=Pokédex No.
Main.mnu_SortSpeciesReverse=Pokédex No. (Reverse)
Main.mnuDelete=Delete
Main.mnuLegality=Legality
Main.mnuLLegality=Legality

View file

@ -240,24 +240,24 @@ Main.mnu_ModifyRandomMoves=Movimientos aleatorios
Main.mnu_ModifyRemoveItem=Eliminar objeto equipado
Main.mnu_ModifyRemoveNicknames=Eliminar motes
Main.mnu_ModifyResetMoves=Reiniciar movimientos
Main.mnu_SortBox=Ordenar cajas
Main.mnu_SortBoxAdvanced=Ordenar cajas (avanzado)
Main.mnu_SortBoxAdvancedBST=Total de estd. base
Main.mnu_SortBoxAdvancedLegal=Legal
Main.mnu_SortBoxAdvancedOwner=EO
Main.mnu_SortBoxAdvancedPotential=Potencial de IVs
Main.mnu_SortBoxAdvancedTraining=Entrenamiento de EVs
Main.mnu_SortBoxAdvancedType=Tipo
Main.mnu_SortBoxAdvancedUsage=Uso
Main.mnu_SortBoxAdvancedVersion=Versión
Main.mnu_SortBoxDate=Fecha de Encuentro
Main.mnu_SortBoxLevel=Nivel (bajo a alto)
Main.mnu_SortBoxLevelRev=Nivel (alto a bajo)
Main.mnu_SortBoxName=Nombre de especie
Main.mnu_SortBoxRandom=Aleatorio
Main.mnu_SortBoxShiny=Variocolor
Main.mnu_SortBoxSpecies=N.º Pokédex
Main.mnu_SortBoxSpeciesRev=N.º Pokédex (inverso)
Main.mnu_Sort=Ordenar cajas
Main.mnu_SortAdvanced=Ordenar cajas (avanzado)
Main.mnu_SortBST=Total de estd. base
Main.mnu_SortLegal=Legal
Main.mnu_SortOwner=EO
Main.mnu_SortPotential=Potencial de IVs
Main.mnu_SortTraining=Entrenamiento de EVs
Main.mnu_SortType=Tipo
Main.mnu_SortUsage=Uso
Main.mnu_SortVersion=Versión
Main.mnu_SortDate=Fecha de Encuentro
Main.mnu_SortLevel=Nivel (bajo a alto)
Main.mnu_SortLevelReverse=Nivel (alto a bajo)
Main.mnu_SortName=Nombre de especie
Main.mnu_SortRandom=Aleatorio
Main.mnu_SortShiny=Variocolor
Main.mnu_SortSpecies=N.º Pokédex
Main.mnu_SortSpeciesReverse=N.º Pokédex (inverso)
Main.mnuDelete=Borrar
Main.mnuLegality=Legalidad
Main.mnuLLegality=Legalidad

View file

@ -240,24 +240,24 @@ Main.mnu_ModifyRandomMoves=Randomize Moves
Main.mnu_ModifyRemoveItem=Delete Held Item
Main.mnu_ModifyRemoveNicknames=Remove Nicknames
Main.mnu_ModifyResetMoves=Reset Moves
Main.mnu_SortBox=Sort Boxes
Main.mnu_SortBoxAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBoxAdvancedBST=Base Stat Total
Main.mnu_SortBoxAdvancedLegal=Legal
Main.mnu_SortBoxAdvancedOwner=Ownership
Main.mnu_SortBoxAdvancedPotential=IV Potential
Main.mnu_SortBoxAdvancedTraining=EV Training
Main.mnu_SortBoxAdvancedType=Type
Main.mnu_SortBoxAdvancedUsage=Usage
Main.mnu_SortBoxAdvancedVersion=Version
Main.mnu_SortBoxDate=Met Date
Main.mnu_SortBoxLevel=Level (Low to High)
Main.mnu_SortBoxLevelRev=Level (High to Low)
Main.mnu_SortBoxName=Species Name
Main.mnu_SortBoxRandom=Random
Main.mnu_SortBoxShiny=Shiny
Main.mnu_SortBoxSpecies=Pokédex No.
Main.mnu_SortBoxSpeciesRev=Pokédex No. (Reverse)
Main.mnu_Sort=Sort Boxes
Main.mnu_SortAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBST=Base Stat Total
Main.mnu_SortLegal=Legal
Main.mnu_SortOwner=Ownership
Main.mnu_SortPotential=IV Potential
Main.mnu_SortTraining=EV Training
Main.mnu_SortType=Type
Main.mnu_SortUsage=Usage
Main.mnu_SortVersion=Version
Main.mnu_SortDate=Met Date
Main.mnu_SortLevel=Level (Low to High)
Main.mnu_SortLevelReverse=Level (High to Low)
Main.mnu_SortName=Species Name
Main.mnu_SortRandom=Random
Main.mnu_SortShiny=Shiny
Main.mnu_SortSpecies=Pokédex No.
Main.mnu_SortSpeciesReverse=Pokédex No. (Reverse)
Main.mnuDelete=Effacer
Main.mnuLegality=Legality
Main.mnuLLegality=Legality

View file

@ -240,24 +240,24 @@ Main.mnu_ModifyRandomMoves=Randomize Moves
Main.mnu_ModifyRemoveItem=Delete Held Item
Main.mnu_ModifyRemoveNicknames=Remove Nicknames
Main.mnu_ModifyResetMoves=Reset Moves
Main.mnu_SortBox=Sort Boxes
Main.mnu_SortBoxAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBoxAdvancedBST=Base Stat Total
Main.mnu_SortBoxAdvancedLegal=Legal
Main.mnu_SortBoxAdvancedOwner=Ownership
Main.mnu_SortBoxAdvancedPotential=IV Potential
Main.mnu_SortBoxAdvancedTraining=EV Training
Main.mnu_SortBoxAdvancedType=Type
Main.mnu_SortBoxAdvancedUsage=Usage
Main.mnu_SortBoxAdvancedVersion=Version
Main.mnu_SortBoxDate=Met Date
Main.mnu_SortBoxLevel=Level (Low to High)
Main.mnu_SortBoxLevelRev=Level (High to Low)
Main.mnu_SortBoxName=Species Name
Main.mnu_SortBoxRandom=Random
Main.mnu_SortBoxShiny=Shiny
Main.mnu_SortBoxSpecies=Pokédex No.
Main.mnu_SortBoxSpeciesRev=Pokédex No. (Reverse)
Main.mnu_Sort=Sort Boxes
Main.mnu_SortAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBST=Base Stat Total
Main.mnu_SortLegal=Legal
Main.mnu_SortOwner=Ownership
Main.mnu_SortPotential=IV Potential
Main.mnu_SortTraining=EV Training
Main.mnu_SortType=Type
Main.mnu_SortUsage=Usage
Main.mnu_SortVersion=Version
Main.mnu_SortDate=Met Date
Main.mnu_SortLevel=Level (Low to High)
Main.mnu_SortLevelReverse=Level (High to Low)
Main.mnu_SortName=Species Name
Main.mnu_SortRandom=Random
Main.mnu_SortShiny=Shiny
Main.mnu_SortSpecies=Pokédex No.
Main.mnu_SortSpeciesReverse=Pokédex No. (Reverse)
Main.mnuDelete=Elimina
Main.mnuLegality=Legality
Main.mnuLLegality=Legality

View file

@ -240,24 +240,24 @@ Main.mnu_ModifyRandomMoves=Randomize Moves
Main.mnu_ModifyRemoveItem=Delete Held Item
Main.mnu_ModifyRemoveNicknames=Remove Nicknames
Main.mnu_ModifyResetMoves=Reset Moves
Main.mnu_SortBox=Sort Boxes
Main.mnu_SortBoxAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBoxAdvancedBST=Base Stat Total
Main.mnu_SortBoxAdvancedLegal=Legal
Main.mnu_SortBoxAdvancedOwner=Ownership
Main.mnu_SortBoxAdvancedPotential=IV Potential
Main.mnu_SortBoxAdvancedTraining=EV Training
Main.mnu_SortBoxAdvancedType=Type
Main.mnu_SortBoxAdvancedUsage=Usage
Main.mnu_SortBoxAdvancedVersion=Version
Main.mnu_SortBoxDate=Met Date
Main.mnu_SortBoxLevel=Level (Low to High)
Main.mnu_SortBoxLevelRev=Level (High to Low)
Main.mnu_SortBoxName=Species Name
Main.mnu_SortBoxRandom=Random
Main.mnu_SortBoxShiny=Shiny
Main.mnu_SortBoxSpecies=Pokédex No.
Main.mnu_SortBoxSpeciesRev=Pokédex No. (Reverse)
Main.mnu_Sort=Sort Boxes
Main.mnu_SortAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBST=Base Stat Total
Main.mnu_SortLegal=Legal
Main.mnu_SortOwner=Ownership
Main.mnu_SortPotential=IV Potential
Main.mnu_SortTraining=EV Training
Main.mnu_SortType=Type
Main.mnu_SortUsage=Usage
Main.mnu_SortVersion=Version
Main.mnu_SortDate=Met Date
Main.mnu_SortLevel=Level (Low to High)
Main.mnu_SortLevelReverse=Level (High to Low)
Main.mnu_SortName=Species Name
Main.mnu_SortRandom=Random
Main.mnu_SortShiny=Shiny
Main.mnu_SortSpecies=Pokédex No.
Main.mnu_SortSpeciesReverse=Pokédex No. (Reverse)
Main.mnuDelete=消去
Main.mnuLegality=合法性
Main.mnuLLegality=合法性

View file

@ -240,24 +240,24 @@ Main.mnu_ModifyRandomMoves=Randomize Moves
Main.mnu_ModifyRemoveItem=Delete Held Item
Main.mnu_ModifyRemoveNicknames=Remove Nicknames
Main.mnu_ModifyResetMoves=Reset Moves
Main.mnu_SortBox=Sort Boxes
Main.mnu_SortBoxAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBoxAdvancedBST=Base Stat Total
Main.mnu_SortBoxAdvancedLegal=Legal
Main.mnu_SortBoxAdvancedOwner=Ownership
Main.mnu_SortBoxAdvancedPotential=IV Potential
Main.mnu_SortBoxAdvancedTraining=EV Training
Main.mnu_SortBoxAdvancedType=Type
Main.mnu_SortBoxAdvancedUsage=Usage
Main.mnu_SortBoxAdvancedVersion=Version
Main.mnu_SortBoxDate=Met Date
Main.mnu_SortBoxLevel=Level (Low to High)
Main.mnu_SortBoxLevelRev=Level (High to Low)
Main.mnu_SortBoxName=Species Name
Main.mnu_SortBoxRandom=Random
Main.mnu_SortBoxShiny=Shiny
Main.mnu_SortBoxSpecies=Pokédex No.
Main.mnu_SortBoxSpeciesRev=Pokédex No. (Reverse)
Main.mnu_Sort=Sort Boxes
Main.mnu_SortAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBST=Base Stat Total
Main.mnu_SortLegal=Legal
Main.mnu_SortOwner=Ownership
Main.mnu_SortPotential=IV Potential
Main.mnu_SortTraining=EV Training
Main.mnu_SortType=Type
Main.mnu_SortUsage=Usage
Main.mnu_SortVersion=Version
Main.mnu_SortDate=Met Date
Main.mnu_SortLevel=Level (Low to High)
Main.mnu_SortLevelReverse=Level (High to Low)
Main.mnu_SortName=Species Name
Main.mnu_SortRandom=Random
Main.mnu_SortShiny=Shiny
Main.mnu_SortSpecies=Pokédex No.
Main.mnu_SortSpeciesReverse=Pokédex No. (Reverse)
Main.mnuDelete=삭제
Main.mnuLegality=Legality
Main.mnuLLegality=Legality

View file

@ -240,24 +240,24 @@ Main.mnu_ModifyRandomMoves=Randomize Moves
Main.mnu_ModifyRemoveItem=Delete Held Item
Main.mnu_ModifyRemoveNicknames=Remove Nicknames
Main.mnu_ModifyResetMoves=Reset Moves
Main.mnu_SortBox=Sort Boxes
Main.mnu_SortBoxAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBoxAdvancedBST=Base Stat Total
Main.mnu_SortBoxAdvancedLegal=Legal
Main.mnu_SortBoxAdvancedOwner=Ownership
Main.mnu_SortBoxAdvancedPotential=IV Potential
Main.mnu_SortBoxAdvancedTraining=EV Training
Main.mnu_SortBoxAdvancedType=Type
Main.mnu_SortBoxAdvancedUsage=Usage
Main.mnu_SortBoxAdvancedVersion=Version
Main.mnu_SortBoxDate=Met Date
Main.mnu_SortBoxLevel=Level (Low to High)
Main.mnu_SortBoxLevelRev=Level (High to Low)
Main.mnu_SortBoxName=Species Name
Main.mnu_SortBoxRandom=Random
Main.mnu_SortBoxShiny=Shiny
Main.mnu_SortBoxSpecies=Pokédex No.
Main.mnu_SortBoxSpeciesRev=Pokédex No. (Reverse)
Main.mnu_Sort=Sort Boxes
Main.mnu_SortAdvanced=Sort Boxes (Advanced)
Main.mnu_SortBST=Base Stat Total
Main.mnu_SortLegal=Legal
Main.mnu_SortOwner=Ownership
Main.mnu_SortPotential=IV Potential
Main.mnu_SortTraining=EV Training
Main.mnu_SortType=Type
Main.mnu_SortUsage=Usage
Main.mnu_SortVersion=Version
Main.mnu_SortDate=Met Date
Main.mnu_SortLevel=Level (Low to High)
Main.mnu_SortLevelReverse=Level (High to Low)
Main.mnu_SortName=Species Name
Main.mnu_SortRandom=Random
Main.mnu_SortShiny=Shiny
Main.mnu_SortSpecies=Pokédex No.
Main.mnu_SortSpeciesReverse=Pokédex No. (Reverse)
Main.mnuDelete=删除
Main.mnuLegality=合法性
Main.mnuLLegality=合法性

View file

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using PKHeX.Core;
@ -11,72 +10,84 @@ namespace PKHeX.WinForms.Controls
{
private readonly SAVEditor sav;
private readonly List<ItemVisibility> CustomItems = new List<ItemVisibility>();
private readonly BoxManipulator Manipulator;
public BoxMenuStrip(SAVEditor SAV)
{
Manipulator = new BoxManipulatorWF(SAV);
sav = SAV;
foreach (Level z in Enum.GetValues(typeof(Level)))
for (int i = 0; i < Levels.Length; i++)
{
var ctrl = new ToolStripMenuItem {Name = $"mnu_{z}", Text = z.ToString(), Image = GetImage(z)};
Items.Add(ctrl);
var level = Levels[i];
var sprite = TopLevelImages[i];
var name = LevelNames[i];
var parent = new ToolStripMenuItem {Name = $"mnu_{name}", Text = name, Image = sprite};
foreach (var item in level)
AddItem(SAV, parent, item);
Items.Add(parent);
}
AddItem(Level.Delete, GetItem("All", "Clear", () => Clear(), Resources.nocheck));
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), 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), 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), 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), 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), 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("ResetMoves", "Reset Moves", () => Modify(z => z.SetMoves(z.GetMoveSet())), Resources.date), s => s.Generation >= 3);
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), s => s.Generation >= 7);
AddItem(Level.Modify, GetItem("RemoveNicknames", "Remove Nicknames", () => Modify(z => z.SetDefaultNickname()), Resources.alphaAZ));
AddItem(Level.Modify, GetItem("RemoveItem", "Delete Held Item", () => Modify(z => z.HeldItem = 0), Resources.gift), s => s.Generation >= 2);
}
private enum Level
private void AddItem(ISaveFileProvider SAV, ToolStripDropDownItem parent, IBoxManip item)
{
Delete,
SortBox,
SortBoxAdvanced,
Modify,
var name = item.Type.ToString();
ManipTypeImage.TryGetValue(item.Type, out var img);
var tsi = new ToolStripMenuItem { Name = $"mnu_{name}", Text = name, Image = img };
tsi.Click += (s, e) => Manipulator.Execute(item, SAV.CurrentBox, All, Reverse);
parent.DropDownItems.Add(tsi);
CustomItems.Add(new ItemVisibility(tsi, item));
}
private static readonly Dictionary<BoxManipType, Image> ManipTypeImage = new Dictionary<BoxManipType, Image>
{
[BoxManipType.DeleteAll] = Resources.nocheck,
[BoxManipType.DeleteEggs] = Resources.about,
[BoxManipType.DeletePastGen] = Resources.bak,
[BoxManipType.DeleteForeign] = Resources.users,
[BoxManipType.DeleteUntrained] = Resources.gift,
[BoxManipType.DeleteItemless] = Resources.main,
[BoxManipType.DeleteIllegal] = Resources.export,
[BoxManipType.SortSpecies] = Resources.numlohi,
[BoxManipType.SortSpeciesReverse] = Resources.numhilo,
[BoxManipType.SortLevel] = Resources.vallohi,
[BoxManipType.SortLevelReverse] = Resources.valhilo,
[BoxManipType.SortDate] = Resources.date,
[BoxManipType.SortName] = Resources.alphaAZ,
[BoxManipType.SortShiny] = Resources.showdown,
[BoxManipType.SortRandom] = Resources.wand,
[BoxManipType.SortUsage] = Resources.heart,
[BoxManipType.SortPotential] = Resources.numhilo,
[BoxManipType.SortTraining] = Resources.showdown,
[BoxManipType.SortOwner] = Resources.users,
[BoxManipType.SortType] = Resources.main,
[BoxManipType.SortVersion] = Resources.numlohi,
[BoxManipType.SortBST] = Resources.vallohi,
[BoxManipType.SortLegal] = Resources.export,
[BoxManipType.ModifyHatchEggs] = Resources.about,
[BoxManipType.ModifyMaxFriendship] = Resources.heart,
[BoxManipType.ModifyMaxLevel] = Resources.showdown,
[BoxManipType.ModifyResetMoves] = Resources.date,
[BoxManipType.ModifyRandomMoves] = Resources.wand,
[BoxManipType.ModifyHyperTrain] = Resources.vallohi,
[BoxManipType.ModifyRemoveNicknames] = Resources.alphaAZ,
[BoxManipType.ModifyRemoveItem] = Resources.gift,
};
private sealed class ItemVisibility
{
private readonly ToolStripItem Item;
private readonly Func<SaveFile, bool> IsVisible;
private readonly IBoxManip Manip;
public ItemVisibility(ToolStripItem toolStripItem, Func<SaveFile, bool> visible)
public ItemVisibility(ToolStripItem toolStripItem, IBoxManip visible)
{
Item = toolStripItem;
IsVisible = visible;
Manip = visible;
}
public void SetVisibility(SaveFile s) => Item.Visible = IsVisible(s);
public void SetVisibility(SaveFile s) => Item.Visible = Manip.Usable?.Invoke(s) ?? true;
}
public void ToggleVisibility()
@ -85,58 +96,60 @@ namespace PKHeX.WinForms.Controls
s.SetVisibility(sav.SAV);
}
private static Image GetImage(Level l)
private static readonly string[] LevelNames =
{
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;
}
}
"Delete",
"Sort",
"SortAdvanced",
"Modify",
};
private static ToolStripItem GetItem(string name, string text, Action action, Image img)
private static readonly IReadOnlyList<IBoxManip>[] Levels =
{
var tsi = new ToolStripMenuItem { Name = name, Text = text, Image = img };
tsi.Click += (s, e) => action();
return tsi;
}
BoxManipClear.Common,
BoxManipSort.Common,
BoxManipSort.Advanced,
BoxManipModify.Common,
};
private void AddItem(Level v, ToolStripItem t, Func<SaveFile, bool> visible = null)
private static readonly Image[] TopLevelImages =
{
var item = (ToolStripMenuItem)Items[(int)v];
t.Name = item.Name + t.Name;
item.DropDownItems.Add(t);
CustomItems.Add(new ItemVisibility(t, visible ?? (_ => true)));
}
Resources.nocheck,
Resources.swapBox,
Resources.settings,
Resources.wand,
};
public void Clear() => ((ToolStripMenuItem)Items[0]).DropDownItems[0].PerformClick();
public void Sort() => ((ToolStripMenuItem)Items[1]).DropDownItems[0].PerformClick();
private static bool All => (ModifierKeys & Keys.Shift) != 0;
private static bool Reverse => (ModifierKeys & Keys.Control) != 0;
}
private void Clear(Func<PKM, bool> criteria = null)
/// <summary>
/// Implementation of a WinForms box manipulator (using MessageBox prompts)
/// </summary>
public sealed class BoxManipulatorWF : BoxManipulator
{
private readonly SAVEditor Editor;
protected override SaveFile SAV => Editor.SAV;
public BoxManipulatorWF(SAVEditor editor)
{
if (All)
sav.ClearAll(criteria);
else
sav.ClearCurrent(criteria);
Editor = editor;
}
private void Sort(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
{
if (All)
sav.SortAll(sorter, Reverse);
else
sav.SortCurrent(sorter, Reverse);
}
protected override void FinishBoxManipulation(string message, bool all) => Editor.FinishBoxManipulation(message, all);
private void Modify(Action<PKM> action)
protected override bool CanManipulateRegion(int start, int end, string prompt, string fail)
{
if (All)
sav.ModifyAll(action);
else
sav.ModifyCurrent(action);
if (prompt != null && WinFormsUtil.Prompt(MessageBoxButtons.YesNo, prompt) != DialogResult.Yes)
return false;
bool canModify = base.CanManipulateRegion(start, end, prompt, fail);
if (!canModify && fail != null)
WinFormsUtil.Alert(fail);
return canModify;
}
}
}

View file

@ -401,83 +401,25 @@ namespace PKHeX.WinForms.Controls
if (!e.Button.HasFlag(MouseButtons.Right))
{
if (ModifierKeys.HasFlag(Keys.Alt))
((ToolStripMenuItem)SortMenu.Items[0]).DropDownItems[0].PerformClick(); // Clear
SortMenu.Clear();
else if (ModifierKeys.HasFlag(Keys.Control))
GetSorter()(PKMSorting.OrderBySpecies, false); // Sort
SortMenu.Sort();
return;
Action<Func<IEnumerable<PKM>, IEnumerable<PKM>>, bool> GetSorter() => ModifierKeys.HasFlag(Keys.Shift)
? SortAll
: (Action<Func<IEnumerable<PKM>, IEnumerable<PKM>>, bool>) SortCurrent;
}
var pt = Tab_Box.PointToScreen(new Point(0, 0));
SortMenu.Show(pt);
}
public void ClearAll(Func<PKM, bool> criteria)
{
if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxClearAll, MsgSaveBoxClearAllFailBattle))
return;
SAV.ClearBoxes(deleteCriteria: criteria);
FinishBoxManipulation(MsgSaveBoxClearAllSuccess, true);
}
public void ClearCurrent(Func<PKM, bool> criteria)
{
if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxClearCurrent, MsgSaveBoxClearCurrentFailBattle))
return;
SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox, criteria);
FinishBoxManipulation(MsgSaveBoxClearCurrentSuccess, false);
}
public void SortAll(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter, bool reverse)
{
if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxSortAll, MsgSaveBoxSortAllFailBattle))
return;
SAV.SortBoxes(sortMethod: sorter, reverse: reverse);
FinishBoxManipulation(MsgSaveBoxSortAllSuccess, true);
}
public void SortCurrent(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter, bool reverse)
{
if (!CanManipulateRegion(Box.CurrentBox, Box.CurrentBox, MsgSaveBoxSortCurrent, MsgSaveBoxSortCurrentFailBattle))
return;
SAV.SortBoxes(Box.CurrentBox, Box.CurrentBox, sorter, reverse: reverse);
FinishBoxManipulation(MsgSaveBoxSortCurrentSuccess, false);
}
public void ModifyAll(Action<PKM> action)
{
SAV.ModifyBoxes(action);
FinishBoxManipulation(null, true);
SystemSounds.Asterisk.Play();
}
public void ModifyCurrent(Action<PKM> action)
{
SAV.ModifyBoxes(action, Box.CurrentBox, Box.CurrentBox);
FinishBoxManipulation(null, true);
SystemSounds.Asterisk.Play();
}
private void FinishBoxManipulation(string message, bool all)
public void FinishBoxManipulation(string message, bool all)
{
SetPKMBoxes();
UpdateBoxViewers(all);
if (message != null)
WinFormsUtil.Alert(message);
else
SystemSounds.Asterisk.Play();
}
private bool CanManipulateRegion(int start, int end, string prompt, string fail)
{
if (prompt != null && WinFormsUtil.Prompt(MessageBoxButtons.YesNo, prompt) != DialogResult.Yes)
return false;
if (!SAV.IsAnySlotLockedInBox(start, end))
return true;
if (fail != null)
WinFormsUtil.Alert(fail);
return false;
}
#endregion
private void ClickBoxDouble(object sender, MouseEventArgs e)
{