public static void PreparePopup(ChassisDef chassisDef, MechBayPanel mechbay, MechBayChassisInfoWidget widget, MechBayChassisUnitElement unitElement) { mechBay = mechbay; ChassisHandler.unitElement = unitElement; infoWidget = widget; chassis = chassisDef; mech = ChassisToMech[chassis.Description.Id]; }
private static void ScrapChassis(int num, ChassisDef p1, MechBayChassisInfoWidget widget, MechBayPanel mechBay) { for (int i = 0; i < num; i++) { UnityGameInstance.BattleTechGame.Simulation.ScrapInactiveMech(p1.Description.Id, true); } mechBay.RefreshData(false); mechBay.SelectChassis(null); }
private static void ScrapParts(int num, ChassisDef mech, MechBayChassisInfoWidget widget, MechBayPanel mechBay) { for (int i = 0; i < num; i++) { UnityGameInstance.BattleTechGame.Simulation.ScrapMechPart(mech.Description.Id, 1, UnityGameInstance.BattleTechGame.Simulation.Constants.Story.DefaultMechPartMax, true); } widget.SetData(mechBay, null); mechBay.RefreshData(false); mechBay.SelectChassis(null); }
public static void Postfix(MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis, GameObject ___readyBtnObj, GameObject ___partsCountObj) { if (___selectedChassis == null) { return; } if (___selectedChassis.MechPartCount > 0) { ___readyBtnObj.SetActive(true); ___partsCountObj.SetActive(false); } }
public static void Postfix(MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis, ref int __state) { var sim = UnityGameInstance.BattleTechGame.Simulation; if (Main.Settings.DependsOnArgoUpgrade && !sim.PurchasedArgoUpgrades.Contains(Main.Settings.ArgoUpgrade)) { return; } if (___selectedChassis != null) { ___selectedChassis.MechPartMax = __state; } }
public static void Postfix(MechBayChassisInfoWidget __instance, GameObject ___rootInfoObj, MechBayChassisUnitElement ___chassisElement) { try { var label = ___rootInfoObj.GetComponentsInChildren <TextMeshProUGUI>().FirstOrDefault(x => x.name == "txt_mechType"); var dm = UnityGameInstance.BattleTechGame.DataManager; var date = dm.MechDefs .Where(x => x.Value.Description.Id == ___chassisElement.ChassisDef.Description.Id.Replace("chassisdef", "mechdef")) .Select(x => x.Value.MinAppearanceDate).FirstOrDefault(); // regex because newline var matches = Regex.Match(label.text, @"(.+-\s.+)\s(.+)"); var mechString = matches.Groups[1]; var mechWeight = matches.Groups[2]; var labelText = $"{mechString} ({date.Value:MMM yyyy})\n{mechWeight}"; label.SetText(labelText); } catch // silent drop { } }
public static bool Prefix(MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis, MechBayPanel ___mechBay) { if (___selectedChassis == null) { return(true); } int bay = ___mechBay.Sim.GetFirstFreeMechBay(); string id = ___selectedChassis.Description.Id.Replace("chassisdef", "mechdef"); MechDef d = ___mechBay.Sim.DataManager.MechDefs.Get(id); if (___selectedChassis.MechPartCount > 0) // this is actually a part that gets assembled { int p = SimpleMechAssembly_Main.GetNumPartsForAssembly(___mechBay.Sim, d); if (p < ___mechBay.Sim.Constants.Story.DefaultMechPartMax) { GenericPopupBuilder.Create("Mech Assembly", "Yang: I do not have enough parts to assemble a mech out of it.").AddButton("Cancel", null, true, null) .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render(); return(false); } //SimpleMechAssembly_Main.QueryMechAssemblyPopup(___mechBay.Sim, d, ___mechBay); ___mechBay.Sim.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_AssembleMechEntry(___mechBay.Sim, d, ___mechBay), true); return(false); } if (___selectedChassis.MechPartCount < ___selectedChassis.MechPartMax) { return(true); } if (SimpleMechAssembly_Main.Settings.OmniMechTag == null || !___selectedChassis.ChassisTags.Contains(SimpleMechAssembly_Main.Settings.OmniMechTag)) { return(true); } if (bay < 0) { return(true); } SimpleMechAssembly_Main.UnStorageOmniMechPopup(___mechBay.Sim, d, ___mechBay); return(false); }
public static bool SetHardpoints(MechBayChassisInfoWidget __instance, LocalizableText ___jumpjetHardpointText, LocalizableText ___ballisticHardpointText, ChassisDef ___selectedChassis) { try { var hardpoints = __instance.GetComponent <UIModuleHPHandler>(); if (hardpoints == null) { hardpoints = __instance.gameObject.AddComponent <UIModuleHPHandler>(); hardpoints.Init(__instance, ___ballisticHardpointText.gameObject, ___jumpjetHardpointText.gameObject, new Vector2(320, -25)); } var usage = ___selectedChassis.GetHardpoints(); hardpoints.SetDataTotal(usage); hardpoints.SetJJ(___selectedChassis.GetJJMaxByChassisDef()); } catch (Exception e) { Control.LogError(e); } return(false); }
public static bool OnReadyClicked(ChassisDef ___selectedChassis, MechBayPanel ___mechBay , MechBayChassisUnitElement ___chassisElement, MechBayChassisInfoWidget __instance) { if (___selectedChassis == null) { return(false); } var mech = ChassisHandler.GetMech(___selectedChassis.Description.Id); var name = new Text(mech.Description.UIName).ToString(); if (___selectedChassis.MechPartMax == 0) { int value = Mathf.RoundToInt((float)___selectedChassis.Description.Cost * ___mechBay.Sim.Constants.Finances.MechScrapModifier); if (Control.Settings.AllowScrapToParts) { int max = ___mechBay.Sim.Constants.Story.DefaultMechPartMax; int n1 = Mathf.Clamp(Mathf.RoundToInt(max * Control.Settings.MinScrapParts), 1, max); int n2 = Mathf.Clamp(Mathf.RoundToInt(max * Control.Settings.MaxScrapParts), 1, max); GenericPopupBuilder.Create($"Scrap {name}?", $"Do you want scrap this chassis and sale spare parts for <color=#F79B26FF>{SimGameState.GetCBillString(value)}</color> or scrap and keep parts ({n1}-{n2} parts)") .AddButton("Cancel", null, true, null) .AddButton("Keep Parts", () => SplitToParts(___selectedChassis, n1, n2, ___mechBay), true, null) .AddButton("Sale", () => ScrapChassis(1, ___selectedChassis, __instance, ___mechBay), true, null) .CancelOnEscape() .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true) .Render(); } else { GenericPopupBuilder.Create($"Scrap {name}?", $"Are you sure you want to scrap this 'Mech Chassis? It will be removed permanently from your inventory.\n\nSCRAP VALUE: < color =#F79B26FF>{SimGameState.GetCBillString(value)}</color>") .AddButton("Cancel", null, true, null) .AddButton("scrap", () => ScrapChassis(1, ___selectedChassis, __instance, ___mechBay), true, null) .CancelOnEscape() .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true) .Render(); } } else { int num = ___selectedChassis.MechPartCount; int value = Mathf.RoundToInt((float)___selectedChassis.Description.Cost * ___mechBay.Sim.Constants.Finances.MechScrapModifier) / ___selectedChassis.MechPartMax; if (num == 1) { GenericPopupBuilder.Create($"Scrap {name} part?", $"Are you sure you want to scrap this 'Mech part? It will be removed permanently from your inventory.\n\nSCRAP VALUE: <color=#F79B26FF>{SimGameState.GetCBillString(value)}</color>") .AddButton("Cancel", null, true, null) .AddButton("Scrap", () => ScrapParts(1, ___selectedChassis, __instance, ___mechBay), true, null) .CancelOnEscape().AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render(); } else { var popup = LazySingletonBehavior <UIManager> .Instance.GetOrCreatePopupModule <SG_Stores_MultiPurchasePopup>(string.Empty); var shopdef = new ShopDefItem(mech.Description.Id, ShopItemType.MechPart, 1, num, true, false, value); popup.SetData(___mechBay.Sim, shopdef, name + " parts", num, value, (n) => ScrapParts(n, ___selectedChassis, __instance, ___mechBay)); } } return(false); }
public static bool OnReadyClicked(ChassisDef ___selectedChassis, MechBayPanel ___mechBay , MechBayChassisUnitElement ___chassisElement, MechBayChassisInfoWidget __instance) { if (!Control.Settings.AssemblyVariants) { return(true); } if (___selectedChassis == null) { return(false); } if (___mechBay.Sim.GetFirstFreeMechBay() < 0) { GenericPopupBuilder.Create("Cannot Ready 'Mech", "There are no available slots in the 'Mech Bay. You must move an active 'Mech into storage before readying this chassis.").AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render(); return(false); } ChassisHandler.PreparePopup(___selectedChassis, ___mechBay, __instance, ___chassisElement); if (___selectedChassis.MechPartCount == 0) { int num2 = Mathf.CeilToInt((float)___mechBay.Sim.Constants.Story.MechReadyTime / (float)___mechBay.Sim.MechTechSkill); GenericPopupBuilder.Create("Ready 'Mech?", $"It will take {num2} day(s) to ready this BattleMech chassis for combat.") .AddButton("Cancel", null, true, null) .AddButton("Ready", ChassisHandler.OnChassisReady, true, null) .AddFader( new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants .PopupBackfill), 0f, true) .CancelOnEscape() .Render(); return(false); } if (___selectedChassis.MechPartCount >= ___selectedChassis.MechPartMax) { GenericPopupBuilder.Create("Assembly 'Mech?", $"It will take {___selectedChassis.MechPartMax} parts from storage.") .AddButton("Cancel", null, true, null) .AddButton("Ready", ChassisHandler.OnPartsAssembly, true, null) .AddFader( new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants .PopupBackfill), 0f, true) .CancelOnEscape() .Render(); return(false); } if (!Control.Settings.AssemblyVariants) { return(true); } ChassisHandler.StartDialog(); return(false); }
public static void AddVariantsToDescriptions( MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis, TextMeshProUGUI ___mechDetails, HBSTooltip ___chassisStorageTooltip, GameObject ___readyBtnObj, GameObject ___partsCountObj, TextMeshProUGUI ___partsCountText) { if (___selectedChassis == null) { return; } if (!Control.Settings.AssemblyVariants) { return; } var list = ChassisHandler.GetCompatible(___selectedChassis.Description.Id); if (___selectedChassis.MechPartCount != 0) { int min = ChassisHandler.GetInfo(___selectedChassis.Description.Id).MinParts; if (___selectedChassis.MechPartCount >= ___selectedChassis.MechPartMax) { ___readyBtnObj.SetActive(true); ___partsCountObj.SetActive(false); ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject("Enough parts to assemble: Press Ready to move to a Bay")); } else { if (list == null || ___selectedChassis.MechPartCount < min || list.Sum(i => ChassisHandler.GetCount(i.Description.Id)) < ___selectedChassis.MechPartMax) { ___readyBtnObj.SetActive(false); ___partsCountObj.SetActive(true); ___partsCountText.SetText($"{___selectedChassis.MechPartCount} / {___selectedChassis.MechPartMax}"); ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject($"Chassis still needs at least {min} base and total {___selectedChassis.MechPartMax} compatible parts to be completed")); } else { ___readyBtnObj.SetActive(true); ___partsCountObj.SetActive(false); ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject("Chassis can by assembled using other parts: Press Ready to move to a Bay")); } } } else { ___readyBtnObj.SetActive(true); ___partsCountObj.SetActive(false); ___chassisStorageTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject("Chassis in storage: Press Ready to move to a Bay")); } string add = ""; if (list == null) { add = $"\n<color=#FFFF00>Special mech: cannot be assembled using other variants</color>"; } else if (list.Count > 1) { add = $"\n<color=#32CD32>Compatible with owned variants:"; if (list.Count > Control.Settings.MaxVariantsInDescription + 1) { int showed = 0; foreach (var mechDef in list) { if (mechDef.ChassisID == ___selectedChassis.Description.Id) { continue; } add += "\n" + new Text(mechDef.Description.UIName).ToString(); showed += 1; if (showed == Control.Settings.MaxVariantsInDescription - 1) { break; } } add += $"\n and {Control.Settings.MaxVariantsInDescription - showed} other variants</color>"; } else { foreach (var mechDef in list) { if (mechDef.ChassisID == ___selectedChassis.Description.Id) { continue; } add += "\n" + new Text(mechDef.Description.UIName).ToString(); } add += "</color>"; } } ___mechDetails.SetText(___mechDetails.text + add); }
public static bool Prefix(MechBayChassisInfoWidget __instance, ChassisDef ___selectedChassis, MechBayPanel ___mechBay) { if (___selectedChassis == null) { return(true); } int bay = ___mechBay.Sim.GetFirstFreeMechBay(); MechDef d = ___selectedChassis.GetMainMechDef(___mechBay.Sim.DataManager); if (___selectedChassis.MechPartCount > 0) // this is actually a part that gets assembled { int p = SimpleMechAssembly_Main.GetNumPartsForAssembly(___mechBay.Sim, d); if (p < ___mechBay.Sim.Constants.Story.DefaultMechPartMax) { GenericPopupBuilder.Create($"{d.GetMechOmniVehicle()} Assembly", SimpleMechAssembly_Main.GetAssembleNotEnoughPartsText(___mechBay.Sim, d)).AddButton("Cancel", null, true, null) .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render(); return(false); } ___mechBay.Sim.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_AssembleMechEntry(___mechBay.Sim, d, delegate { ___mechBay.RefreshData(false); }), true); return(false); } if (___selectedChassis.MechPartCount < ___selectedChassis.MechPartMax) { return(true); } if (___selectedChassis.IsVehicle()) { bay = CUIntegration.GetFirstFreeMechBay(___mechBay.Sim, d); if (bay < 0) { GenericPopupBuilder.Create("Cannot Ready Vehicle", "There are no available slots in the Vehicle Bay. You must move an active Vehicle into storage before readying this chassis.") .AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render(); } else { GenericPopupBuilder.Create("Ready Vehicle?", $"It will take {Mathf.CeilToInt(___mechBay.Sim.Constants.Story.MechReadyTime / (float)___mechBay.Sim.MechTechSkill)} day(s) to ready this Vehicle for combat.") .AddButton("Cancel", null, true, null).AddButton("Ready", delegate { if (___mechBay.Sim.ScrapInactiveMech(___selectedChassis.Description.Id, false)) { SimpleMechAssembly_Main.ReadyMech(___mechBay.Sim, new MechDef(d, ___mechBay.Sim.GenerateSimGameUID(), true), bay, true); ___mechBay.RefreshData(false); ___mechBay.ViewBays(); } }).AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).CancelOnEscape().Render(); } return(false); } if (!___selectedChassis.IsOmni()) { return(true); } if (bay < 0) { return(true); } ___mechBay.Sim.InterruptQueue.AddInterrupt(new SimpleMechAssembly_Main.SimpleMechAssembly_InterruptManager_UnStorageOmniEntry(___mechBay.Sim, d, delegate { ___mechBay.RefreshData(false); })); return(false); }