mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-14 15:55:14 -05:00
Add sort force-reverse
hold control when triggering the sort sneaky linq to reverse a sort by: * re-doing the initial sort, then * reversing the sorted pkm data by using a throwaway increment * re-doing the final sort
This commit is contained in:
@@ -128,6 +128,19 @@ public static IEnumerable<PKM> OrderByCustom(this IEnumerable<PKM> list, params
|
||||
.FinalSortBy();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sorts an <see cref="Enumerable"/> list of <see cref="PKM"/> objects in reverse.
|
||||
/// </summary>
|
||||
/// <param name="list">Source list to revese sort</param>
|
||||
/// <returns>Enumerable list that is sorted</returns>
|
||||
public static IEnumerable<PKM> ReverseSort(this IEnumerable<PKM> list)
|
||||
{
|
||||
int i = 0;
|
||||
return list.InitialSortBy()
|
||||
.ThenByDescending(z => i++)
|
||||
.FinalSortBy();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Common pre-filtering of <see cref="PKM"/> data.
|
||||
/// </summary>
|
||||
|
||||
@@ -588,7 +588,7 @@ public bool IsAnySlotLockedInBox(int BoxStart, int BoxEnd)
|
||||
}
|
||||
public virtual bool IsSlotInBattleTeam(int box, int slot) => false;
|
||||
|
||||
public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>, IEnumerable<PKM>> sortMethod = null)
|
||||
public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>, IEnumerable<PKM>> sortMethod = null, bool reverse = false)
|
||||
{
|
||||
var BD = BoxData;
|
||||
int start = BoxSlotCount * BoxStart;
|
||||
@@ -597,6 +597,8 @@ public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>,
|
||||
Section = Section.Take(BoxSlotCount * (BoxEnd - BoxStart + 1));
|
||||
|
||||
var Sorted = (sortMethod ?? PKMSorting.OrderBySpecies)(Section);
|
||||
if (reverse)
|
||||
Sorted = Sorted.ReverseSort();
|
||||
|
||||
Sorted.CopyTo(BD, start);
|
||||
BoxData = BD;
|
||||
|
||||
@@ -395,18 +395,18 @@ public void ClearCurrent(Func<PKM, bool> criteria)
|
||||
SAV.ClearBoxes(Box.CurrentBox, Box.CurrentBox, criteria);
|
||||
FinishBoxManipulation(MsgSaveBoxClearCurrentSuccess, false);
|
||||
}
|
||||
public void SortAll(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
|
||||
public void SortAll(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter, bool reverse)
|
||||
{
|
||||
if (!CanManipulateRegion(0, SAV.BoxCount - 1, MsgSaveBoxSortAll, MsgSaveBoxSortAllFailBattle))
|
||||
return;
|
||||
SAV.SortBoxes(sortMethod: sorter);
|
||||
SAV.SortBoxes(sortMethod: sorter, reverse: reverse);
|
||||
FinishBoxManipulation(MsgSaveBoxSortAllSuccess, true);
|
||||
}
|
||||
public void SortCurrent(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
|
||||
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);
|
||||
SAV.SortBoxes(Box.CurrentBox, Box.CurrentBox, sorter, reverse: reverse);
|
||||
FinishBoxManipulation(MsgSaveBoxSortCurrentSuccess, false);
|
||||
}
|
||||
public void ModifyAll(Action<PKM> action)
|
||||
|
||||
@@ -71,10 +71,11 @@ void Clear(Func<PKM, bool> criteria = null)
|
||||
|
||||
void Sort(Func<IEnumerable<PKM>, IEnumerable<PKM>> sorter)
|
||||
{
|
||||
bool reverse = Control.ModifierKeys.HasFlag(Keys.Control);
|
||||
if (Control.ModifierKeys.HasFlag(Keys.Shift))
|
||||
sav.SortAll(sorter);
|
||||
sav.SortAll(sorter, reverse);
|
||||
else
|
||||
sav.SortCurrent(sorter);
|
||||
sav.SortCurrent(sorter, reverse);
|
||||
}
|
||||
|
||||
void Modify(Action<PKM> action)
|
||||
|
||||
Reference in New Issue
Block a user