private static readonly ChassisLocations[] Locations = MechDefSlots.Locations; // order of locations to fill up first #endregion internal void RefreshData(MechLabPanel mechLab) { var fillerImageCache = MechLabLocationWidgetSetDataPatch.FillerImageCache; if (fillerImageCache.Count < Locations.Length) { return; } var slots = new MechDefSlots(mechLab.activeMechDef); using (var reservedSlots = slots.GetReservedSlots().GetEnumerator()) { foreach (var location in Locations) { var fillerImages = fillerImageCache[location]; var widget = mechLab.GetLocationWidget((ArmorLocation)location); // by chance armorlocation = chassislocation for main locations var adapter = new MechLabLocationWidgetAdapter(widget); var used = adapter.usedSlots; for (var i = 0; i < adapter.maxSlots; i++) { var fillerImage = fillerImages[i]; if (i >= used && reservedSlots.MoveNext()) { var reservedSlot = reservedSlots.Current; if (reservedSlot == null) { throw new NullReferenceException(); } fillerImage.gameObject.SetActive(true); var uicolor = reservedSlot.ReservedSlotColor; var color = LazySingletonBehavior <UIManager> .Instance.UIColorRefs.GetUIColor(uicolor); fillerImage.color = slots.IsOverloaded ? DynamicSlotsSpaceMissingColor : color; } else { fillerImage.gameObject.SetActive(false); } } } } }
private static readonly ChassisLocations[] Locations = MechDefSlots.Locations; // order of locations to fill up first #endregion internal void RefreshData(MechLabPanel mechLab) { if (MechLabLocationWidget_SetData_Patch.Fillers.Count < Locations.Length) { return; } var slots = new MechDefSlots(mechLab.activeMechDef); using (var reservedSlots = slots.GetReservedSlots().GetEnumerator()) { foreach (var location in Locations) { var fillers = MechLabLocationWidget_SetData_Patch.Fillers[location]; var widget = mechLab.GetLocationWidget((ArmorLocation)location); // by chance armorlocation = chassislocation for main locations var adapter = new MechLabLocationWidgetAdapter(widget); var used = adapter.usedSlots; for (var i = 0; i < adapter.maxSlots; i++) { var filler = fillers[i]; if (i >= used && reservedSlots.MoveNext()) { var reservedSlot = reservedSlots.Current; if (reservedSlot == null) { throw new NullReferenceException(); } filler.Show(reservedSlot); } else { filler.Hide(); } } } } }
internal MechLabLocationWidgetPatchHelper(MechLabLocationWidget widget) { _adapter = new MechLabLocationWidgetAdapter(widget); }
// only allow one engine part per specific location public MechLabDropResult ValidateDrop(MechLabItemSlotElement dragItem, MechLabLocationWidget widget) { var newComponentRef = dragItem.ComponentRef; var newComponentDef = newComponentRef.Def; var heatSinkDef = newComponentDef.GetComponent <EngineHeatSink>(); var heatSinkKitDef = newComponentDef.GetComponent <EngineHeatSinkKit>(); // check if we can work with it if (heatSinkDef == null && heatSinkKitDef == null) { return(null); } var adapter = new MechLabLocationWidgetAdapter(widget); var localInventory = adapter.localInventory; var engineSlotElement = localInventory.FirstOrDefault(x => x?.ComponentRef?.Def?.GetComponent <EngineCoreDef>() != null); if (engineSlotElement == null) { if (heatSinkKitDef != null) { return(new MechLabDropErrorResult( $"Cannot add {newComponentDef.Description.Name}: No Engine found" )); } return(null); } var engineRef = engineSlotElement.ComponentRef.GetEngineCoreRef(); var engineDef = engineRef.CoreDef; var mechLab = adapter.mechLab; if (mechLab.IsSimGame) { if (dragItem.OriginalDropParentType != MechLabDropTargetType.InventoryList) { return(new MechLabDropErrorResult( $"Cannot add {newComponentDef.Description.Name}: Item has to be from inventory" )); } if (mechLab.originalMechDef.Inventory.Any(c => c.SimGameUID == engineRef.ComponentRef.SimGameUID)) { return(new MechLabDropErrorResult( $"Cannot add {newComponentDef.Description.Name}: Engine cannot be modified once installed, remove engine first" )); } } if (heatSinkKitDef != null) { if (engineRef.HeatSinkDef != newComponentDef.DataManager.GetDefaultEngineHeatSinkDef()) { return(new MechLabDropErrorResult( $"Cannot add {newComponentDef.Description.Name}: Reinstall engine to remove internal heat sinks" )); } if (engineRef.AdditionalHeatSinkCount > 0) { return(new MechLabDropErrorResult( $"Cannot add {newComponentDef.Description.Name}: Reinstall engine to remove additional heat sinks before converting" )); } engineRef.HeatSinkDef = mechLab.dataManager.GetEngineHeatSinkDef(heatSinkKitDef.HeatSinkDefId); } else { if (engineRef.AdditionalHeatSinkCount >= engineDef.MaxAdditionalHeatSinks) { return(null); } if (!Control.settings.AllowMixingHeatSinkTypes) { if (engineRef.HeatSinkDef.HSCategory != heatSinkDef.HSCategory) { return(new MechLabDropErrorResult( $"Cannot add {newComponentDef.Description.Name}: Mixing heat sink types is not allowed" )); } } engineRef.Query(heatSinkDef).AdditionalCount++; } EnginePersistence.SaveEngineState(engineRef, mechLab); mechLab.ValidateLoadout(false); EngineCoreRefHandler.Shared.ModifySlotElement(engineSlotElement); return(new MechLabDropRemoveDragItemResult()); }