public static int Compare(ListElementControllerCompare a, ListElementControllerCompare b) { // in general we can rely on the custom comparer for sorting, with a few exceptions handled below int num = BetterSorting.GetSortVal(a).CompareTo(BetterSorting.GetSortVal(b)); // upgrades don't have a sub-type to identify them, so a name comparison is necessary to sort them together if (num == 0 && a?.componentDef != null && b?.componentDef != null && a.componentDef.ComponentType == ComponentType.Upgrade) { Log($"comparing equipment by name..."); // normalize name and compare (ASC) num = b.componentDef.Description.UIName.Trim(trimChars).CompareTo(a.componentDef.Description.UIName.Trim(trimChars)); if (num == 0) { // rarity num = a.componentDef.Description.Rarity.CompareTo(b.componentDef.Description.Rarity); } } return(num); }
public static int Compare_NotListView(InventoryItemElement_NotListView a, InventoryItemElement_NotListView b) { return(BetterSorting.Compare(ListElementControllerCompare.Wrap(b.controller), ListElementControllerCompare.Wrap(a.controller))); }
public int Compare(ListElementController_BASE a, ListElementController_BASE b) { return(BetterSorting.Compare(ListElementControllerCompare.Wrap(b), ListElementControllerCompare.Wrap(a))); }
public static double GetSortVal(ListElementControllerCompare item) { try { double num = 0; bool in_mechLab = (item?.shopDefItem == null && item?.salvageDef == null); if (item?.chassisDef != null) { num = (int)item?.chassisDef.Tonnage; if ((item?.shopDefItem != null && item.shopDefItem.Type == ShopItemType.Mech) || (item?.salvageDef != null && item?.salvageDef.Type == SalvageDef.SalvageType.CHASSIS)) { Log("found mech."); num += 400000; } else if ((item?.shopDefItem != null && item.shopDefItem.Type == ShopItemType.MechPart) || (item?.salvageDef != null && item?.salvageDef.Type == SalvageDef.SalvageType.MECH_PART)) { Log("found mech part."); num += 350000; } } // weapons (10000 - ~60000) shop: 10000 - ~160000 if (item?.weaponDef != null) { WeaponDef wd = item.weaponDef; Log($"found weapon: {wd.Description.Id}"); // category (inverted, AC before LASER, etc.) num += (m_maxWeapCat - (int)wd.Category) * 10000; // sub-type (SRM,LRM...) num += (int)wd.WeaponSubType * 100; // tonnage num += wd.Tonnage; // quality num += wd.Description.UIName.Split('+').Length - 1; // in the store/salvage place rare items before all other weapons if (wd.Description.Rarity > 0 && !in_mechLab) { num += 100000; } } else if (item?.ammoBoxDef != null) { // ammo if (item.ammoBoxDef != null) { Log("found ammo."); num += 5000 + (int)item.ammoBoxDef.Ammo.Category; } } else if (item?.componentDef != null) { Log($"found upgrade/equipment: {item.componentDef.Description.Id}"); if (!in_mechLab) { // upgrades/equipment if (item.componentDef.ComponentType == ComponentType.Upgrade) { num += 250000; } // improved heatsink if (item.componentDef.ComponentType == ComponentType.HeatSink && item.componentDef.Description.Rarity > 0) { num += 225000; } } // component type num += (int)item.componentDef.ComponentType * 100; // sub type //num += (int)item.componentDef.ComponentSubType * 10; } // lostech if (item.IsLosTech() && !in_mechLab) { Log(" -adjusting for lostech"); num += 500000; } Log($" sort val:{num}"); return(num); } catch (Exception e) { Log($"Failed to get sortVal for {item.GetType().ToString()}: {e.ToString()}"); return(0); } }