internal void RefreshData(MechLabPanel mechLab) { var builder = new MechDefBuilder(mechLab.activeMechDef); var fslList = new List <DynamicSlotBuilder>(); foreach (var location in MechDefBuilder.Locations) { // armorlocation = chassislocation for main locations var widget = mechLab.GetLocationWidget((ArmorLocation)location); ClearFillers(widget); var adapter = new MechLabLocationWidgetAdapter(widget); fslList.Add(new DynamicSlotBuilder(builder, location, adapter)); } //for (var reservedSlots = builder.Reserved; reservedSlots > 0; reservedSlots--) foreach (var reservedSlot in builder.GetReservedSlots()) { var fsl = fslList.Max(); if (fsl.currentFreeSlots <= 0) { // no more free slots to use up! break; } ShowFiller(fsl.adapter.instance, reservedSlot, fsl.currentFreeSlotIndex, fsl.currentFreeSlotFixed); fsl.currentFreeSlots--; } }
public static IEnumerable <MechLabItemSlotElement> Elements(this MechLabPanel mechLab) { return(MechDefSlots.Locations .Select(location => mechLab.GetLocationWidget((ArmorLocation)location)) .Select(widget => new MechLabLocationWidgetAdapter(widget)) .SelectMany(adapter => adapter.LocalInventory)); }
public void RefreshData(MechLabPanel panel) { foreach (var element in Elements(panel)) { AdjustSlotElement(element, panel); } }
// auto strip engine when put back to inventory internal static void InventoryWidgetOnAddItem(MechLabInventoryWidget widget, MechLabPanel panel, IMechLabDraggableItem item) { if (item.ItemType != MechLabDraggableItemType.MechComponentItem) { return; } var componentRef = item.ComponentRef; var engineRef = componentRef.GetEngineRef(); if (engineRef == null) { return; } //Control.mod.Logger.LogDebug("MechLabInventoryWidget.OnAddItem " + componentRef.Def.Description.Id + " UID=" + componentRef.SimGameUID); foreach (var componentDefID in engineRef.GetInternalComponents()) { //Control.mod.Logger.LogDebug("MechLabInventoryWidget.OnAddItem extracting componentDefID=" + componentDefID); var @ref = CreateMechComponentRef(componentDefID, panel.sim, panel.dataManager); var mechLabItemSlotElement = panel.CreateMechComponentItem(@ref, false, ChassisLocations.None, null); widget.OnAddItem(mechLabItemSlotElement, false); } //engineRef.ClearInternalComponents(); //SaveEngineState(engineRef, panel); widget.RefreshFilterToggles(); }
public static void Prefix(MechLabPanel __instance) { try { var mechDef = __instance.activeMechDef; var id = $"{mechDef.Description.Name}_{mechDef.Description.Id}"; var path = Path.Combine(Path.Combine(Control.mod.Directory, "Saves"), $"{id}.json"); Directory.CreateDirectory(Directory.GetParent(path).FullName); using (var writer = new StreamWriter(path)) { var p = new JSONParameters { EnableAnonymousTypes = true, SerializeToLowerCaseNames = false, UseFastGuid = false, KVStyleStringDictionary = false, SerializeNullValues = false }; var json = JSON.ToNiceJSON(mechDef, p); writer.Write(json); } } catch (Exception e) { Control.mod.Logger.LogError(e); } }
public static bool ItemsAvailableInInventory(this MechLabPanel mechLabPanel, List <InventoryItemElement_Simple> requiredItems, List <InventoryItemElement_NotListView> requestedInventory) { foreach (InventoryItemElement_Simple requiredItem in requiredItems) { bool match = false; foreach (InventoryItemElement_NotListView inventoryItem in requestedInventory) { if (inventoryItem.ComponentRef.ComponentDefID == requiredItem.ComponentRef.ComponentDefID) { Logger.Debug("[Extensions.InventoryHasAllItemsInStock] requestedInventory: " + inventoryItem.ComponentRef.ComponentDefID + " (Quantity: " + inventoryItem.controller.quantity + ")"); Logger.Debug("[Extensions.InventoryHasAllItemsInStock] requiredItems: " + requiredItem.ComponentRef.ComponentDefID + " (Quantity: " + requiredItem.Quantity + ")"); match = true; // Need to check the controller as a potential quantity change via store is NOT reflected properly in vanilla //if (inventoryItem.Quantity >= requiredItem.Quantity) if (inventoryItem.controller.quantity >= requiredItem.Quantity) { break; } else { return(false); } } } if (!match) { return(false); } } return(true); }
public static void ValidateAllMechDefTonnages(this MechLabPanel mechLabPanel, bool errorsOnly = true) { foreach (KeyValuePair <string, MechDef> mechDefs in mechLabPanel.Sim.DataManager.MechDefs) { string id = mechDefs.Key; MechDef mechDef = mechDefs.Value; float num = 0f; float tonnage = mechDef.Chassis.Tonnage; MechStatisticsRules.CalculateTonnage(mechDef, ref num, ref tonnage); if ((double)Mathf.Abs(num - mechDef.Chassis.Tonnage) < 0.0001) { if (!errorsOnly) { Logger.Debug("[MechLabPanelExtensions_ValidateAllMechDefTonnages] MechDef (" + mechDef.Name + "/" + id + "): Passed"); } } else if (num > mechDef.Chassis.Tonnage) { float diff = num - mechDef.Chassis.Tonnage; Logger.Debug("[MechLabPanelExtensions_ValidateAllMechDefTonnages] MechDef (" + mechDef.Name + "/" + id + "): OVERWEIGHT (+" + diff + " Tons)"); } //else if (num <= mechDef.Chassis.Tonnage - 0.5f) else if (num < mechDef.Chassis.Tonnage) { float diff = mechDef.Chassis.Tonnage - num; Logger.Debug("[MechLabPanelExtensions_ValidateAllMechDefTonnages] MechDef (" + mechDef.Name + "/" + id + "): UNDERWEIGHT (-" + diff + " Tons)"); } } }
static void Postfix(MechLabPanel __instance, MechLabDismountWidget ___dismountWidget, HBSDOTweenButton ___btn_mechViewerButton) { if (__instance.IsSimGame && !HasRun) { // dismountWidget.gameObject.SetActive(IsSimGame); => change it's rectTransform.sizeDelta.y to 180 if (___dismountWidget != null && ___dismountWidget.gameObject != null) { RectTransform rt = ___dismountWidget.gameObject.GetComponent <RectTransform>(); Vector3 newDeltas = rt.sizeDelta; newDeltas.y = 180; rt.sizeDelta = newDeltas; } // btn_mechViewerButton.gameObject.SetActive(IsSimGame); => change it's pos_x from 1274 to 690 if (___btn_mechViewerButton != null && ___btn_mechViewerButton.gameObject != null) { RectTransform rt = ___btn_mechViewerButton.gameObject.GetComponent <RectTransform>(); Vector3 newPos = rt.position; newPos.x -= 584; rt.position = newPos; } HasRun = true; } }
public void AdjustSlotElement(MechLabItemSlotElement instance, MechLabPanel panel) { var def = instance.ComponentRef.GetComponent <EngineHeatBlockDef>(); if (def == null) { return; } if (panel.activeMechDef == null || panel.activeMechDef.Chassis == null) { return; } var engine = panel.GetEngine(); if (engine == null) { return; } var adapter = new MechLabItemSlotElementAdapter(instance); adapter.bonusTextA.text = BonusValueEngineHeatDissipation(engine); adapter.bonusTextB.text = BonusValueEngineHeatSinkCounts(engine); }
public static bool Prefix( MechLabPanel ___mechLab, ref float ___currentTonnage, TextMeshProUGUI ___totalTonnage, UIColorRefTracker ___totalTonnageColor, TextMeshProUGUI ___remainingTonnage, UIColorRefTracker ___remainingTonnageColor) { try { var mechDef = ___mechLab.CreateMechDef(); if (mechDef == null) { return(false); } WeightsHandler.AdjustInfoWidget( mechDef, ___remainingTonnageColor, ___totalTonnageColor, ___totalTonnage, ___remainingTonnage, out ___currentTonnage ); return(false); } catch (Exception e) { Control.Logger.Error.Log(e); } return(true); }
public static bool Prefix(MechLabMechInfoWidget __instance, MechLabPanel ___mechLab) { return(_harmonyManager.PrefixLogExceptions(() => { if (!_inCalculateTonnage) { try { _inCalculateTonnage = true; _unusedHardpointMass = GetEmptyHardpointMass(___mechLab.CreateMechDef()); __instance.CalculateTonnage(); } finally { _inCalculateTonnage = false; } return false; } else { return true; } })); }
public static bool Prefix(MechLabPanel __instance, MechComponentDef def, ref bool __result, bool ___isDebugLab) { try { var tags = def.ComponentTags; if (__instance.IsSimGame) { __result = true; } else if (!___isDebugLab && tags.Contains(MechValidationRules.ComponentTag_Debug)) { __result = false; } else if (tags.Contains(MechValidationRules.Tag_Blacklisted)) { __result = false; } else if (tags.ContainsAny(TagManagerFeature.Shared.Settings.SkirmishWhitelistTagSet)) { __result = true; } else { __result = false; } return(false); } catch (Exception e) { Control.Logger.Error.Log(e); } return(true); }
static bool Prefix(MechLabPanel __instance, bool ___batchActionInProgress, MechLabItemSlotElement ___dragItem) { var hk = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); if (!hk) { return(true); } if (!__instance.Initialized) { return(false); } if (___dragItem != null) { return(false); } ___batchActionInProgress = true; __instance.headWidget.AdvancedStripping(__instance); __instance.centerTorsoWidget.AdvancedStripping(__instance); __instance.leftTorsoWidget.AdvancedStripping(__instance); __instance.rightTorsoWidget.AdvancedStripping(__instance); __instance.leftArmWidget.AdvancedStripping(__instance); __instance.rightArmWidget.AdvancedStripping(__instance); __instance.leftLegWidget.AdvancedStripping(__instance); __instance.rightLegWidget.AdvancedStripping(__instance); __instance.FlagAsModified(); __instance.ValidateLoadout(false); ___batchActionInProgress = false; return(false); }
internal static void Postfix( ref LocationLoadoutDef ___loadout, ref MechLabPanel ___mechLab, MechComponentDef newComponentDef, ref bool __result) { try { if (!__result) { return; } var chassisDef = ___mechLab?.activeMechDef?.Chassis; if (chassisDef == null) { return; } var location = ___loadout.Location; if (location == ChassisLocations.None) { return; } __result = OmniSlotsFeature.Shared.ValidateAddSimple(chassisDef, location, newComponentDef); } catch (Exception e) { Control.Logger.Error.Log(e); } }
public void AdjustSlotElement(MechLabItemSlotElement instance, MechLabPanel panel) { var weights = instance.ComponentRef?.Def?.GetComponent <Weights>(); if (weights == null) { return; } var mechDef = panel.activeMechDef; if (mechDef == null) { return; } var tonnageChanges = CalculateWeightChanges(mechDef, weights); var adapter = new MechLabItemSlotElementAdapter(instance); if (!Mathf.Approximately(tonnageChanges, 0)) { adapter.bonusTextA.text = $"{FloatToText(tonnageChanges)} ton"; } else if (adapter.bonusTextA.text.EndsWith("ton")) { adapter.bonusTextA.text = instance.ComponentRef.Def.BonusValueA; } }
internal static void LoadMech(MechLabPanel mechLabPanel) { var finder = new MechLabLayoutFinder(mechLabPanel); var mechRectTransform = finder.ObjMech.GetComponent <RectTransform>(); // Unity (?) does not handle layout propagation properly, so we need to force several layout passes here // also allows us to calculate stuff for auto zoom without waiting for regular layout passes LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform); LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform); LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform); mechRectTransform.anchorMin = new(mechRectTransform.anchorMin.x, 1); mechRectTransform.anchorMax = new(mechRectTransform.anchorMin.x, 1); mechRectTransform.pivot = new(mechRectTransform.pivot.x, 1); mechRectTransform.position = new(finder.ObjMech.position.x, finder.ObjActions.position.y, finder.ObjMech.position.z); { var confirmRectTransform = finder.ObjCancelConfirm.GetComponent <RectTransform>(); var mechSize = mechRectTransform.sizeDelta.y; var targetSize = mechRectTransform.localPosition.y - 40 // repair button height - confirmRectTransform.localPosition.y + confirmRectTransform.sizeDelta.y; // save button bottom var scale = Mathf.Min(1, targetSize / mechSize); mechRectTransform.localScale = new(scale, scale, 1); Control.Logger.Debug?.Log($"AutoZoom scale={scale} mechSize={mechSize} targetSize={targetSize}"); } }
public static void InitMechLabHelper(MechDef newMechDef, MechLabPanel __instance) { if (newMechDef != null) { MechLabHelper.EnterMechLab(__instance); } }
public void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget w) { if (Links != null && Links.Length > 0) { RemoveLinked(item, mechLab); } }
public static List <InventoryItemElement_NotListView> PullItemsFromInventory(this MechLabPanel mechLabPanel, List <InventoryItemElement_Simple> requiredItems, List <InventoryItemElement_NotListView> requestedInventory) { MechLabInventoryWidget inventoryWidget = (MechLabInventoryWidget)AccessTools.Field(typeof(MechLabPanel), "inventoryWidget").GetValue(mechLabPanel); List <InventoryItemElement_NotListView> collectedItems = new List <InventoryItemElement_NotListView>(); // Reverse iterate to be able to directly remove without exception // BEWARE: Throws exception if the inventory gets completely emptied during this process (very unlikely but possible) for (int i = requestedInventory.Count - 1; i >= 0; i--) { foreach (InventoryItemElement_Simple requiredItem in requiredItems) { if (requestedInventory[i].ComponentRef.ComponentDefID == requiredItem.ComponentRef.ComponentDefID) { //if (requestedInventory[i].Quantity >= requiredItem.Quantity) if (requestedInventory[i].controller.quantity >= requiredItem.Quantity) { for (int j = 0; j < requiredItem.Quantity; j++) { // Collect before removal just makes sense... :-) collectedItems.Add(requestedInventory[i]); inventoryWidget.RemoveItem(requestedInventory[i]); } } } } } return(collectedItems); }
public static bool Prefix(MechLabPanel __instance) { if (!Core.Settings.RepairRearm) { return(true); } if (!__instance.Initialized || !__instance.IsSimGame) { return(false); } if (Traverse.Create(__instance).Field("dragItem").GetValue <MechLabItemSlotElement>() != null) { return(false); } __instance.headWidget.RepairAll(true, true); __instance.centerTorsoWidget.RepairAll(true, true); __instance.leftTorsoWidget.RepairAll(true, true); __instance.rightTorsoWidget.RepairAll(true, true); __instance.leftArmWidget.RepairAll(true, true); __instance.rightArmWidget.RepairAll(true, true); __instance.leftLegWidget.RepairAll(true, true); __instance.rightLegWidget.RepairAll(true, true); RepairArmor(__instance); __instance.ValidateLoadout(false); return(false); }
private static void ChangeWorkOrderSimGameUID(MechLabPanel panel, string oldSimGameUID, string newSimGameUID) { if (!panel.IsSimGame || panel.baseWorkOrder == null) { return; } foreach (var entry in panel.baseWorkOrder.SubEntries) { Traverse traverse; if (entry is WorkOrderEntry_InstallComponent install) { traverse = Traverse.Create(install); } else if (entry is WorkOrderEntry_RepairComponent repair) { traverse = Traverse.Create(repair); } else { continue; } traverse = traverse.Property("ComponentSimGameUID"); var componentSimGameUID = traverse.GetValue <string>(); if (componentSimGameUID != oldSimGameUID) { continue; } traverse.SetValue(newSimGameUID); } }
internal static void SetJumpJetHardpointCount(MechLabMechInfoWidget widget, MechLabPanel mechLab, MechLabHardpointElement[] hardpoints) { if (mechLab == null || mechLab.activeMechDef == null || mechLab.activeMechInventory == null) { return; } if (mechLab.activeMechDef.Chassis == null) { return; } var current = mechLab.headWidget.currentJumpjetCount + mechLab.centerTorsoWidget.currentJumpjetCount + mechLab.leftTorsoWidget.currentJumpjetCount + mechLab.rightTorsoWidget.currentJumpjetCount + mechLab.leftArmWidget.currentJumpjetCount + mechLab.rightArmWidget.currentJumpjetCount + mechLab.leftLegWidget.currentJumpjetCount + mechLab.rightLegWidget.currentJumpjetCount; var stats = new MechDefMovementStatistics(mechLab.activeMechDef); widget.totalJumpjets = stats.JumpJetCount; if (hardpoints == null || hardpoints[4] == null) { return; } hardpoints[4].SetData(WeaponCategoryEnumeration.GetAMS(), $"{current} / {widget.totalJumpjets}"); }
internal static void FixMechLabLayouts(MechLabPanel panel) { var finder = new MechLabLayoutFinder(panel); FixCustomCapacitiesRelatedLayouts(finder); FixMechLabLocationWidgetLayouts(finder); }
internal static void Postfix( MechLabMechInfoWidget __instance, ref MechLabPanel ___mechLab, ref MechLabHardpointElement[] ___hardpoints) { try { var mechDef = ___mechLab.activeMechDef; if (mechDef == null) { return; } var inventory = mechDef.Inventory.Select(x => x.Def); var hardpoints = MechDefBuilder.Locations.SelectMany(x => mechDef.Chassis.GetLocationDef(x).Hardpoints).ToArray(); var calc = new HardpointOmniUsageCalculator(inventory, hardpoints); //Control.mod.Logger.Log(calc); __instance.totalBallisticHardpoints = calc.Ballistic.TheoreticalMax; __instance.totalEnergyHardpoints = calc.Energy.TheoreticalMax; __instance.totalMissileHardpoints = calc.Missile.TheoreticalMax; __instance.totalSmallHardpoints = calc.Small.TheoreticalMax; ___hardpoints[0].SetData(WeaponCategory.Ballistic, calc.Ballistic.HardpointTotalString); ___hardpoints[1].SetData(WeaponCategory.Energy, calc.Energy.HardpointTotalString); ___hardpoints[2].SetData(WeaponCategory.Missile, calc.Missile.HardpointTotalString); ___hardpoints[3].SetData(WeaponCategory.AntiPersonnel, calc.Small.HardpointTotalString); } catch (Exception e) { Control.mod.Logger.LogError(e); } }
public void RefreshData(MechLabPanel mechLab) { foreach (var element in mechLab.Elements()) { RefreshSlotElement(element, mechLab); } }
public static bool Prefix(IMechLabDraggableItem item, ref bool __result, MechLabPanel ___mechLab, ref MechComponentRef __state) { try { Control.LogDebug(DType.ComponentInstall, $"OnItemGrab.Prefix {item.ComponentRef.ComponentDefID}"); foreach (var grab_handler in item.ComponentRef.Def.GetComponents <IOnItemGrab>()) { if (item.ComponentRef.Flags <CCFlags>().NoRemove) { __result = false; return(false); } if (!grab_handler.OnItemGrab(item, ___mechLab, out var error)) { if (!string.IsNullOrEmpty(error)) { ___mechLab.ShowDropErrorMessage(new Text(error)); } __result = false; return(false); } } } catch (Exception e) { Control.LogError(e); } return(true); }
public void AdjustSlotElement(MechLabItemSlotElement element, MechLabPanel panel) { foreach (var cc in element.ComponentRef.Def.GetComponents <IAdjustSlotElement>()) { cc.AdjustSlotElement(element, panel); } }
internal static void MoveMechRoleInfo(MechLabPanel mechLabPanel) { var Representation = mechLabPanel.transform.GetChild("Representation"); var OBJ_mech = Representation.GetChild("OBJ_mech"); var layout_details = OBJ_mech .GetChild("Centerline") .GetChild("layout_details"); if (layout_details != null) { var go = layout_details.gameObject; MechLabFixWidgetLayouts.EnableLayout(go); go.GetComponent <LayoutElement>().ignoreLayout = true; var leftArm = OBJ_mech.GetChild("LeftArm"); var vlg = leftArm.GetComponent <VerticalLayoutGroup>(); vlg.padding = new RectOffset(0, 0, MechLabSlotsFeature.settings.MechLabArmTopPadding, 0); //layout_details.parent = leftArm; //layout_details.SetAsFirstSibling(); var leftArmWidget = leftArm.GetChild(0); layout_details.SetParent(leftArmWidget, false); var rect = go.GetComponent <RectTransform>(); rect.pivot = new Vector2(0, 0); rect.localPosition = new Vector3(0, 0); } }
private static IEnumerable <MechLabItemSlotElement> Elements(MechLabPanel panel) { return(MechDefBuilder.Locations .Select(location => panel.GetLocationWidget((ArmorLocation)location)) .Select(widget => new MechLabLocationWidgetAdapter(widget)) .SelectMany(adapter => adapter.LocalInventory)); }
internal static bool StripEngine(MechLabPanel panel, IMechLabDraggableItem item) { if (item.ItemType != MechLabDraggableItemType.MechComponentItem) { return(false); } var componentRef = item.ComponentRef; var engineRef = componentRef.GetEngineRef(); if (engineRef == null) { return(false); } //Control.mod.Logger.LogDebug("MechLabInventoryWidget.OnAddItem " + componentRef.Def.Description.Id + " UID=" + componentRef.SimGameUID); foreach (var componentDefID in engineRef.GetInternalComponents()) { //Control.mod.Logger.LogDebug("MechLabInventoryWidget.OnAddItem extracting componentDefID=" + componentDefID); var @ref = CreateMechComponentRef(componentDefID, panel.sim, panel.dataManager); var mechLabItemSlotElement = panel.CreateMechComponentItem(@ref, false, item.MountedLocation, item.DropParent); mechLabItemSlotElement.gameObject.transform.localScale = Vector3.one; panel.OnAddItem(mechLabItemSlotElement, false); } engineRef.ClearInternalComponents(); SaveEngineState(engineRef, panel); return(true); }