public static void SetLoadout_LabelOverrides(LanceMechEquipmentList el) { var chassisDef = el.activeMech.Chassis; if (!chassisDef.Is <ChassisLocationNaming>(out var naming)) { return; } void SetLabel(LocalizableText label, ChassisLocations location) { var shortLabel = naming.Names .Where(x => x.Location == location) .Select(x => x.ShortLabel) .FirstOrDefault(); if (shortLabel != null) { var text = new Text(shortLabel); label.SetText(text); } } SetLoadout(el, SetLabel); }
// have to iterate ourselves, in case CustomUnits skips the vanilla iteration private static void SetLoadout(LanceMechEquipmentList list, Action <LocalizableText, ChassisLocations> setLabel) { setLabel(list.headLabel, ChassisLocations.Head); setLabel(list.leftArmLabel, ChassisLocations.LeftArm); setLabel(list.leftTorsoLabel, ChassisLocations.LeftTorso); setLabel(list.centerTorsoLabel, ChassisLocations.CenterTorso); setLabel(list.rightTorsoLabel, ChassisLocations.RightTorso); setLabel(list.rightArmLabel, ChassisLocations.RightArm); setLabel(list.leftLegLabel, ChassisLocations.LeftLeg); setLabel(list.rightLegLabel, ChassisLocations.RightLeg); }
public static void Postfix(LanceMechEquipmentList __instance) { try { CustomWidgetsFixLanceMechEquipment.SetLoadout_LabelOverrides(__instance); } catch (Exception e) { Control.Logger.Error.Log(e); } }
public static void SetLoadout_LabelDefaults(LanceMechEquipmentList el) { SetupWidgetSections(el); void SetLabel(LocalizableText label, ChassisLocations location) { var text = Mech.GetAbbreviatedChassisLocation(location); label.SetText(text); } SetLoadout(el, SetLabel); }
private static void SetupWidgetSections(LanceMechEquipmentList el) { var centerTorso = el.centerTorsoLabel.transform.parent.gameObject; var topLeft = new List <MechComponentRef>(); var topRight = new List <MechComponentRef>(); foreach (var componentRef in el.activeMech.Inventory) { if (componentRef.Flags <CCFlags>().HideFromEquip) { continue; } if (!componentRef.Is <CustomWidget>(out var widget)) { continue; } switch (widget.Location) { case CustomWidget.MechLabWidgetLocation.TopLeft: topLeft.Add(componentRef); break; case CustomWidget.MechLabWidgetLocation.TopRight: topRight.Add(componentRef); break; } } void Setup(MechLabSlotsSettings.WidgetSettings settings, List <MechComponentRef> list) { var widget = GetWidgetViaCenterTorso(settings, centerTorso); foreach (var mechComponentRef in list) { var gameObject = el.dataManager.PooledInstantiate( "uixPrfPanl_LC_MechLoadoutItem", BattleTechResourceType.UIModulePrefabs ); var component = gameObject.GetComponent <LanceMechEquipmentListItem>(); var bgColor = MechComponentRef.GetUIColor(mechComponentRef); if (mechComponentRef.DamageLevel == ComponentDamageLevel.Destroyed) { bgColor = UIColor.Disabled; } component.SetData( mechComponentRef.Def.Description.UIName, mechComponentRef.DamageLevel, UIColor.White, bgColor ); component.SetTooltipData(mechComponentRef.Def); gameObject.transform.SetParent(widget.transform, false); el.allComponents.Add(gameObject); } widget.SetActive(list.Count > 0); } Setup(MechLabSlotsFeature.settings.TopLeftWidget, topLeft); Setup(MechLabSlotsFeature.settings.TopRightWidget, topRight); }