-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathKerbalComparer.cs
43 lines (39 loc) · 1.48 KB
/
KerbalComparer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Collections.Generic;
namespace KerbalHealth
{
/// <summary>
/// Class used for ordering vessels in Health Monitor
/// </summary>
public class KerbalComparer : Comparer<ProtoCrewMember>
{
readonly bool sortByLocation;
public KerbalComparer(bool sortByLocation) => this.sortByLocation = sortByLocation;
public static int CompareLocation(ProtoCrewMember x, ProtoCrewMember y)
{
if (x.rosterStatus != ProtoCrewMember.RosterStatus.Assigned)
return y.rosterStatus == ProtoCrewMember.RosterStatus.Assigned ? 1 : 0;
if (y.rosterStatus != ProtoCrewMember.RosterStatus.Assigned)
return -1;
Vessel xv = x.GetVessel(), yv = y.GetVessel();
if (HighLogic.LoadedSceneIsFlight)
{
if (xv.isActiveVessel)
return yv.isActiveVessel ? 0 : -1;
if (yv.isActiveVessel)
return 1;
}
if (xv.isEVA)
return yv.isEVA ? 0 : -1;
return yv.isEVA ? 1 : string.Compare(xv.vesselName, yv.vesselName, true);
}
public override int Compare(ProtoCrewMember x, ProtoCrewMember y)
{
if (sortByLocation)
{
int l = CompareLocation(x, y);
return (l != 0) ? l : string.Compare(x.name, y.name, true);
}
return string.Compare(x.name, y.name, true);
}
}
}