public static void InitMechLabHelper(MechDef newMechDef, MechLabPanel __instance) { if (newMechDef != null) { MechLabHelper.EnterMechLab(__instance); } }
public string PreValidateDrop(MechLabItemSlotElement item, LocationHelper location, MechLabHelper mechlab) { if (location.widget.loadout.Location != ChassisLocations.LeftArm && location.widget.loadout.Location != ChassisLocations.RightArm) { return(string.Empty); } if (mechlab.MechLab.activeMechDef.Chassis.Is <ArmActuatorSupport>(out var support)) { var max = support.GetLimit(location.widget.loadout.Location); if (max < Type) { return ($"Cannot install {item.ComponentRef.Def.Description.Name} mech support only up to {max} in {location.LocationName}"); } } foreach (var slot in location.LocalInventory) { if (slot.ComponentRef.Is <ArmActuator>(out var actuator)) { if (actuator.MaxSlot < Type) { return ($"Cannot install {item.ComponentRef.Def.Description.Name} because {slot.ComponentRef.Def.Description.Name} is already installed, remove it first"); } if (MaxSlot < actuator.Type) { return ($"Cannot install {item.ComponentRef.Def.Description.Name} because {actuator.Type} is already installed, remove it first"); } } } return(string.Empty); }
public HeatSinkDef HeatSinkDef => Def as HeatSinkDef; // TODO reintroduce GenericCustomComponent public string PreValidateDrop(MechLabItemSlotElement item, LocationHelper location, MechLabHelper mechlab) { if (Control.settings.AllowMixingHeatSinkTypes) { return(string.Empty); } var engine = mechlab.MechLab.activeMechDef.Inventory.FirstOrDefault(i => i.Def.Is <EngineCoreDef>()); // if engine exist - check its heatsink type if (engine != null) { var engineRef = engine.GetEngineCoreRef(); if (engineRef.HeatSinkDef.HSCategory != HSCategory) { return($"Cannot add {Def.Description.Name}: Mixing heat sink types is not allowed"); } } // else checking elaready installed heatsink else if (mechlab.MechLab.activeMechDef.Inventory.Any(i => i.Def.Is <EngineHeatSink>(out var hs) && hs.HSCategory != HSCategory)) { return($"Cannot add {Def.Description.Name}: Mixing heat sink types is not allowed"); } return(string.Empty); }
public void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget widget) { if (widget.loadout.Location != ChassisLocations.LeftArm && widget.loadout.Location != ChassisLocations.RightArm) { return; } var loc_helper = new LocationHelper(widget); var total_slot = ArmActuatorSlot.None; var mount_loc = widget.loadout.Location; var ml_helper = new MechLabHelper(mechLab); CustomComponents.Control.LogDebug(DType.ComponentInstall, $"- ArmActuator: {Def.Description.Id} {Type}"); void add_default(ArmActuatorSlot slot) { bool add_item(string id) { if (string.IsNullOrEmpty(id)) { return(false); } var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, mechLab.dataManager, mechLab.Sim); if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0) { DefaultHelper.AddMechLab(id, ComponentType.Upgrade, ml_helper, mount_loc); total_slot = total_slot | actuator.Type; return(true); } return(false); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- adding {slot} to {total_slot}"); if (total_slot.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- already present"); return; } if (add_item(ArmActuatorCC.GetDefaultActuator(mechLab.activeMechDef, mount_loc, slot))) { return; } add_item(ArmActuatorCC.GetDefaultActuator(null, mount_loc, slot)); } for (int i = loc_helper.LocalInventory.Count - 1; i >= 0; i--) { var slotitem = loc_helper.LocalInventory[i]; if (!slotitem.ComponentRef.Is <ArmActuator>()) { continue; } var actuator = slotitem.ComponentRef.GetComponent <ArmActuator>(); if (slotitem.ComponentRef.IsDefault() && !slotitem.ComponentRef.IsModuleFixed(ml_helper.MechLab.activeMechDef)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- removing {slotitem.ComponentRef.ComponentDefID} {actuator.Type}"); DefaultHelper.RemoveMechLab(slotitem.ComponentRef.ComponentDefID, slotitem.ComponentRef.ComponentDefType, ml_helper, mount_loc); } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- checking {slotitem.ComponentRef.ComponentDefID} {actuator.Type}"); total_slot = total_slot | actuator.Type; } } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- actuators {total_slot}"); add_default(ArmActuatorSlot.PartShoulder); add_default(ArmActuatorSlot.PartUpper); if (ArmActuatorCC.IsIgnoreFullActuators(mechLab.activeMechDef)) { if (total_slot.HasFlag(ArmActuatorSlot.PartHand) && !total_slot.HasFlag(ArmActuatorSlot.PartLower)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- Removing hand from {total_slot}"); var hand = loc_helper.LocalInventory.FirstOrDefault(i => i.ComponentRef.Is <ArmActuator>(out var actuator) && actuator.Type.HasFlag(ArmActuatorSlot.PartHand)); if (hand == null || hand.ComponentRef.IsFixed) { return; } var dragitem = mechLab.DragItem; widget.OnRemoveItem(hand, false); mechLab.ForceItemDrop(hand); ml_helper.SetDragItem(dragitem as MechLabItemSlotElement); } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- hand already removed from {total_slot}"); } } else { var limit = mechLab.activeMechDef.Chassis.Is <ArmActuatorSupport>(out var s) ? s.GetLimit(mount_loc) : ArmActuatorSlot.Hand; if (limit.HasFlag(ArmActuatorSlot.PartLower)) { add_default(ArmActuatorSlot.PartLower); } if (limit.HasFlag(ArmActuatorSlot.PartHand)) { add_default(ArmActuatorSlot.PartHand); } } }
public static void OnMechLabClose() { MechLabHelper.CloseMechLab(); }