mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-30 07:50:32 +00:00
Track slot modified count on sort/delete/mod
Sorting will always show multiples of boxcount since it repositions empty slots
This commit is contained in:
parent
72ec264f4c
commit
d3dd4fb2a5
8 changed files with 30 additions and 22 deletions
|
@ -16,11 +16,10 @@ namespace PKHeX.Core
|
|||
protected Func<PKM, bool> CriteriaSimple { private get; set; }
|
||||
protected Func<PKM, SaveFile, bool> CriteriaSAV { private get; set; }
|
||||
|
||||
public virtual bool Execute(SaveFile SAV, BoxManipParam param)
|
||||
public virtual int 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;
|
||||
return SAV.ClearBoxes(param.Start, param.Stop, Method);
|
||||
}
|
||||
|
||||
protected BoxManipClear() { }
|
||||
|
@ -56,7 +55,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
private readonly HashSet<T> HashSet = new HashSet<T>();
|
||||
|
||||
public override bool Execute(SaveFile SAV, BoxManipParam param)
|
||||
public override int Execute(SaveFile SAV, BoxManipParam param)
|
||||
{
|
||||
HashSet.Clear();
|
||||
return base.Execute(SAV, param);
|
||||
|
|
|
@ -15,11 +15,10 @@ namespace PKHeX.Core
|
|||
private readonly Action<PKM> Action;
|
||||
private readonly Action<PKM, SaveFile> ActionComplex;
|
||||
|
||||
public bool Execute(SaveFile SAV, BoxManipParam param)
|
||||
public int Execute(SaveFile SAV, BoxManipParam param)
|
||||
{
|
||||
var method = Action ?? (px => ActionComplex(px, SAV));
|
||||
SAV.ModifyBoxes(method, param.Start, param.Stop);
|
||||
return true;
|
||||
return SAV.ModifyBoxes(method, param.Start, param.Stop);
|
||||
}
|
||||
|
||||
private BoxManipModify(BoxManipType type, Action<PKM> action, Func<SaveFile, bool> usable = null)
|
||||
|
|
|
@ -15,11 +15,10 @@ namespace PKHeX.Core
|
|||
private readonly Func<IEnumerable<PKM>, IEnumerable<PKM>> SorterSimple;
|
||||
private readonly Func<IEnumerable<PKM>, SaveFile, IEnumerable<PKM>> SorterComplex;
|
||||
|
||||
public bool Execute(SaveFile SAV, BoxManipParam param)
|
||||
public int 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;
|
||||
return SAV.SortBoxes(param.Start, param.Stop, Method, param.Reverse);
|
||||
}
|
||||
|
||||
private BoxManipSort(BoxManipType type, Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter, Func<SaveFile, bool> usable = null)
|
||||
|
|
|
@ -31,10 +31,10 @@
|
|||
return false;
|
||||
|
||||
var result = manip.Execute(SAV, param);
|
||||
if (!result)
|
||||
if (result <= 0)
|
||||
return false;
|
||||
var success = manip.GetSuccess(allBoxes);
|
||||
FinishBoxManipulation(success, allBoxes);
|
||||
FinishBoxManipulation(success, allBoxes, result);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,6 @@
|
|||
/// </summary>
|
||||
/// <param name="message">Optional message to show if applicable.</param>
|
||||
/// <param name="all">Indicates if all boxes were manipulated, or just one box.</param>
|
||||
protected abstract void FinishBoxManipulation(string message, bool all);
|
||||
protected abstract void FinishBoxManipulation(string message, bool all, int count);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ namespace PKHeX.Core
|
|||
string GetFail(bool all);
|
||||
string GetSuccess(bool all);
|
||||
|
||||
bool Execute(SaveFile SAV, BoxManipParam param);
|
||||
int Execute(SaveFile SAV, BoxManipParam param);
|
||||
}
|
||||
}
|
|
@ -684,7 +684,7 @@ namespace PKHeX.Core
|
|||
.Any(slot => WithinRange(slot, BoxStart*BoxSlotCount, (BoxEnd + 1)*BoxSlotCount));
|
||||
}
|
||||
|
||||
public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>, IEnumerable<PKM>> sortMethod = null, bool reverse = false)
|
||||
public int SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>, IEnumerable<PKM>> sortMethod = null, bool reverse = false)
|
||||
{
|
||||
var BD = BoxData;
|
||||
int start = BoxSlotCount * BoxStart;
|
||||
|
@ -701,7 +701,7 @@ namespace PKHeX.Core
|
|||
var result = Sorted.ToArray();
|
||||
var boxclone = new PKM[BD.Count];
|
||||
BD.CopyTo(boxclone, 0);
|
||||
result.CopyTo(boxclone, skip, start);
|
||||
int count = result.CopyTo(boxclone, skip, start);
|
||||
|
||||
SlotPointerUtil.UpdateRepointFrom(boxclone, BD, 0, SlotPointers);
|
||||
|
||||
|
@ -710,14 +710,16 @@ namespace PKHeX.Core
|
|||
pk.StorageFlags = StorageSlotFlag.None;
|
||||
|
||||
BoxData = boxclone;
|
||||
return count;
|
||||
}
|
||||
|
||||
public void ClearBoxes(int BoxStart = 0, int BoxEnd = -1, Func<PKM, bool> deleteCriteria = null)
|
||||
public int ClearBoxes(int BoxStart = 0, int BoxEnd = -1, Func<PKM, bool> deleteCriteria = null)
|
||||
{
|
||||
if (BoxEnd < 0)
|
||||
BoxEnd = BoxCount - 1;
|
||||
|
||||
var blank = BlankPKM.EncryptedBoxData;
|
||||
int deleted = 0;
|
||||
for (int i = BoxStart; i <= BoxEnd; i++)
|
||||
{
|
||||
for (int p = 0; p < BoxSlotCount; p++)
|
||||
|
@ -725,6 +727,8 @@ namespace PKHeX.Core
|
|||
if (IsSlotOverwriteProtected(i, p))
|
||||
continue;
|
||||
var ofs = GetBoxSlotOffset(i, p);
|
||||
if (!IsPKMPresent(ofs))
|
||||
continue;
|
||||
if (deleteCriteria != null)
|
||||
{
|
||||
var pk = GetStoredSlot(ofs);
|
||||
|
@ -733,27 +737,34 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
SetData(blank, ofs);
|
||||
++deleted;
|
||||
}
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void ModifyBoxes(Action<PKM> action, int BoxStart = 0, int BoxEnd = -1)
|
||||
public int ModifyBoxes(Action<PKM> action, int BoxStart = 0, int BoxEnd = -1)
|
||||
{
|
||||
if (BoxEnd < 0)
|
||||
BoxEnd = BoxCount - 1;
|
||||
var BD = BoxData;
|
||||
int modified = 0;
|
||||
for (int b = BoxStart; b <= BoxEnd; b++)
|
||||
{
|
||||
for (int s = 0; s < BoxSlotCount; s++)
|
||||
{
|
||||
var index = (b * BoxSlotCount) + s;
|
||||
if (BD[index].Species == 0)
|
||||
continue;
|
||||
if (IsSlotOverwriteProtected(b, s))
|
||||
continue;
|
||||
var index = (b * BoxSlotCount) + s;
|
||||
action(BD[index]);
|
||||
++modified;
|
||||
}
|
||||
}
|
||||
|
||||
BoxData = BD;
|
||||
return modified;
|
||||
}
|
||||
|
||||
public byte[] PCBinary => BoxData.SelectMany(pk => pk.EncryptedBoxData).ToArray();
|
||||
|
|
|
@ -131,7 +131,7 @@ namespace PKHeX.WinForms.Controls
|
|||
Editor = editor;
|
||||
}
|
||||
|
||||
protected override void FinishBoxManipulation(string message, bool all) => Editor.FinishBoxManipulation(message, all);
|
||||
protected override void FinishBoxManipulation(string message, bool all, int count) => Editor.FinishBoxManipulation(message, all, count);
|
||||
|
||||
protected override bool CanManipulateRegion(int start, int end, string prompt, string fail)
|
||||
{
|
||||
|
|
|
@ -409,12 +409,12 @@ namespace PKHeX.WinForms.Controls
|
|||
SortMenu.Show(pt);
|
||||
}
|
||||
|
||||
public void FinishBoxManipulation(string message, bool all)
|
||||
public void FinishBoxManipulation(string message, bool all, int count)
|
||||
{
|
||||
SetPKMBoxes();
|
||||
UpdateBoxViewers(all);
|
||||
if (message != null)
|
||||
WinFormsUtil.Alert(message);
|
||||
WinFormsUtil.Alert(message + $" ({count})");
|
||||
else
|
||||
SystemSounds.Asterisk.Play();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue