mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00: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:
parent
8dcee4e0ee
commit
4c9177fcb3
4 changed files with 23 additions and 7 deletions
|
@ -128,6 +128,19 @@ namespace PKHeX.Core
|
|||
.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 @@ namespace PKHeX.Core
|
|||
}
|
||||
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 @@ namespace PKHeX.Core
|
|||
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 @@ namespace PKHeX.WinForms.Controls
|
|||
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 @@ namespace PKHeX.WinForms.Controls
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue