mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-27 20:34:19 -05: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:
@@ -16,11 +16,10 @@ public class BoxManipClear : IBoxManip
|
||||
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 @@ public sealed class BoxManipClearDuplicate<T> : BoxManipClear
|
||||
{
|
||||
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 @@ public sealed class BoxManipModify : IBoxManip
|
||||
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 @@ public sealed class BoxManipSort : IBoxManip
|
||||
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 @@ public bool Execute(IBoxManip manip, int box, bool allBoxes, bool reverse = fals
|
||||
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 @@ public bool Execute(BoxManipType type, int box, bool allBoxes, bool reverse = fa
|
||||
/// </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 @@ public interface IBoxManip
|
||||
string GetFail(bool all);
|
||||
string GetSuccess(bool all);
|
||||
|
||||
bool Execute(SaveFile SAV, BoxManipParam param);
|
||||
int Execute(SaveFile SAV, BoxManipParam param);
|
||||
}
|
||||
}
|
||||
@@ -684,7 +684,7 @@ public bool IsAnySlotLockedInBox(int BoxStart, int BoxEnd)
|
||||
.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 @@ public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>,
|
||||
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 @@ public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>,
|
||||
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 @@ public void ClearBoxes(int BoxStart = 0, int BoxEnd = -1, Func<PKM, bool> delete
|
||||
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 @@ public void ClearBoxes(int BoxStart = 0, int BoxEnd = -1, Func<PKM, bool> delete
|
||||
}
|
||||
|
||||
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 @@ public BoxManipulatorWF(SAVEditor editor)
|
||||
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 @@ private void ClickBoxSort(object sender, MouseEventArgs e)
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user