mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-30 07:50:32 +00:00
Add pkmdb sorting rules for loaded database set
This commit is contained in:
parent
c126cd968a
commit
a939a2dbd6
3 changed files with 52 additions and 1 deletions
|
@ -5,7 +5,7 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Contains slot data and metadata indicating where the <see cref="PKM"/> originated from.
|
||||
/// </summary>
|
||||
public class SlotCache
|
||||
public class SlotCache : IComparable<SlotCache>
|
||||
{
|
||||
/// <summary>
|
||||
/// Information regarding how the <see cref="Entity"/> was obtained.
|
||||
|
@ -60,5 +60,40 @@ namespace PKHeX.Core
|
|||
var e = Entity;
|
||||
return e.Species != 0 && e.ChecksumValid && (e.Sanity == 0 || e is BK4);
|
||||
}
|
||||
|
||||
public int CompareTo(SlotCache? other)
|
||||
{
|
||||
if (other is null)
|
||||
return -1;
|
||||
return string.CompareOrdinal(Identify(), other.Identify());
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(this, obj))
|
||||
return true;
|
||||
return obj is SlotCache c && c.Identify() == Identify();
|
||||
}
|
||||
|
||||
public override int GetHashCode() => Identify().GetHashCode();
|
||||
public static bool operator ==(SlotCache left, SlotCache right) => left.Equals(right);
|
||||
public static bool operator !=(SlotCache left, SlotCache right) => !(left == right);
|
||||
public static bool operator <(SlotCache left, SlotCache right) => left.CompareTo(right) < 0;
|
||||
public static bool operator <=(SlotCache left, SlotCache right) => left.CompareTo(right) <= 0;
|
||||
public static bool operator >(SlotCache left, SlotCache right) => left.CompareTo(right) > 0;
|
||||
public static bool operator >=(SlotCache left, SlotCache right) => left.CompareTo(right) >= 0;
|
||||
|
||||
public int CompareToSpeciesForm(SlotCache other)
|
||||
{
|
||||
var s1 = Entity;
|
||||
var s2 = other.Entity;
|
||||
var c1 = s1.Species.CompareTo(s2.Species);
|
||||
if (c1 != 0)
|
||||
return c1;
|
||||
var c2 = s1.Form.CompareTo(s2.Form);
|
||||
if (c2 != 0)
|
||||
return c2;
|
||||
return CompareTo(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -229,10 +229,20 @@ namespace PKHeX.WinForms
|
|||
[LocalizedDescription("When loading content for the PKM Database, search subfolders within OtherBackupPaths.")]
|
||||
public bool SearchExtraSavesDeep { get; set; } = true;
|
||||
|
||||
[LocalizedDescription("When loading content for the PKM database, the list will be ordered by this option.")]
|
||||
public DatabaseSortMode InitialSortMode { get; set; }
|
||||
|
||||
[LocalizedDescription("Hides unavailable Species if the currently loaded save file cannot import them.")]
|
||||
public bool FilterUnavailableSpecies { get; set; } = true;
|
||||
}
|
||||
|
||||
public enum DatabaseSortMode
|
||||
{
|
||||
None,
|
||||
SpeciesForm,
|
||||
SlotIdentity,
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EncounterDatabaseSettings
|
||||
{
|
||||
|
|
|
@ -369,6 +369,12 @@ namespace PKHeX.WinForms
|
|||
result.RemoveAll(z => !(z.Entity is PK8 || ((PersonalInfoSWSH) PersonalTable.SWSH.GetFormEntry(z.Entity.Species, z.Entity.Form)).IsPresentInGame));
|
||||
}
|
||||
|
||||
var sort = Main.Settings.EntityDb.InitialSortMode;
|
||||
if (sort is DatabaseSortMode.SlotIdentity)
|
||||
result.Sort();
|
||||
else if (sort is DatabaseSortMode.SpeciesForm)
|
||||
result.Sort((first, second) => first.CompareToSpeciesForm(second));
|
||||
|
||||
// Finalize the Database
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue