public static void SetColor(MechBayChassisUnitElement __instance, Image ___mechImage, TextMeshProUGUI ___partsText, TextMeshProUGUI ___partsLabelText, ChassisDef chassisDef, DataManager dataManager, int partsCount, int partsMax, int chassisQuantity) { try { if (partsCount != 0) { ___partsLabelText.SetText("Parts"); ___partsText.SetText($"{partsCount} / {partsMax}"); if (partsCount >= partsMax) { ___mechImage.color = Control.Settings.color_ready; } else { int min = ChassisHandler.GetInfo(chassisDef.Description.Id).MinParts; var list = ChassisHandler.GetCompatible(chassisDef.Description.Id); if (list == null) { ___mechImage.color = Control.Settings.color_exclude; } else if (list.Sum(i => ChassisHandler.GetCount(i.Description.Id)) >= partsMax && chassisDef.MechPartCount >= min) { ___mechImage.color = Control.Settings.color_variant; } else { ___mechImage.color = Control.Settings.color_notready; } } } else { ___mechImage.color = Control.Settings.color_stored; } var go = __instance.transform.Find("Representation/contents/storage_OverlayBars"); var mech = ChassisHandler.GetMech(chassisDef.Description.Id); if (Control.Settings.BGColors != null && Control.Settings.BGColors.Length > 0) { foreach (var color in Control.Settings.BGColors) { if (mech.MechTags.Contains(color.Tag)) { var tracker = go.GetComponent <UIColorRefTracker>(); tracker.SetUIColor(UIColor.Custom); tracker.OverrideWithColor(color.color); break; } } } } catch (Exception e) { Control.LogDebug("Error while get mechdef for " + chassisDef.Description.Id); } }
public static void Prefix(MechBayChassisUnitElement __instance) { var sim = UnityGameInstance.BattleTechGame.Simulation; if (Main.Settings.DependsOnArgoUpgrade && !sim.PurchasedArgoUpgrades.Contains(Main.Settings.ArgoUpgrade)) { return; } // if salvage mech icon is shift-clicked, force assembly checking on that chassis if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { Main.SalvageFromContract.Clear(); var chassisId = __instance.ChassisDef.Description.Id; Logger.LogDebug($"chassisId ({chassisId})"); var mechID = chassisId.Replace("chassisdef", "mechdef"); Main.TriggeredVariant = mechID; Logger.LogDebug($"mechID ({mechID})"); if (!Main.SalvageFromContract.ContainsKey(mechID)) { Main.SalvageFromContract.Add(mechID, 1); } else { Main.SalvageFromContract[mechID] = 1; } Main.SimulateContractSalvage(); Main.SalvageFromContract.Remove(mechID); } }
public static void Postfix(MechBayChassisUnitElement __instance, Image ___mechImage, ChassisDef chassisDef, DataManager dataManager, int partsCount, int partsMax, int chassisQuantity) { if (partsMax > 0) { if (chassisDef.IsVehicle()) { ___mechImage.color = SimpleMechAssembly_Main.Settings.storage_vehiclepart; } else { ___mechImage.color = SimpleMechAssembly_Main.Settings.storage_parts; } } else if (chassisDef.IsVehicle()) { ___mechImage.color = SimpleMechAssembly_Main.Settings.storage_vehicle; } else if (chassisDef.IsOmni()) { ___mechImage.color = SimpleMechAssembly_Main.Settings.storage_omni; } else { ___mechImage.color = SimpleMechAssembly_Main.Settings.storage_mech; } }
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]; }
public static ChassisCount MapChassisUnitElement(MechBayChassisUnitElement mbcue, SimGameState sgs) { int chassisQty = sgs.GetItemCount(mbcue.ChassisDef.Description.Id, typeof(MechDef), SimGameState.ItemCountType.UNDAMAGED_ONLY); Mod.Log.Info?.Write($"Part : {mbcue.ChassisDef.Description.Name} has chassisQty: {chassisQty} " + $"partsCount: {mbcue.PartsCount} partsMax: {mbcue.PartsMax}"); return(new ChassisCount() { ChassisDef = mbcue.ChassisDef, PartsCount = mbcue.PartsCount, PartsMax = mbcue.PartsMax, ChassisQty = chassisQty }); }
static void Prefix(MechBayChassisUnitElement chassisElement, MechBayPanel __instance) { Logger.Debug("we readying!"); var chassisDef = chassisElement.ChassisDef; var itemCount = chassisDef.MechPartCount; if (itemCount > 0) { int defaultMechPartMax = this.Constants.Story.DefaultMechPartMax; if (itemCount + 1 >= defaultMechPartMax) { for (int index = 0; index < defaultMechPartMax - 1; ++index) { this.RemoveItemStat(id, "MECHPART", false); } MechDef mechDef = new MechDef(this.DataManager.MechDefs.Get(id), this.GenerateSimGameUID(), this.Constants.Salvage.EquipMechOnSalvage); this.AddMech(0, mechDef, true, false, true, (string)null); this.interruptQueue.DisplayIfAvailable(); this.MessageCenter.PublishMessage((MessageCenterMessage) new SimGameMechAddedMessage(mechDef, true)); } Logger.Debug("hey this is where we put our code to do the buildout"); } }
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 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 ReadyVehicle(MechBayPanel __instance, MechBayChassisUnitElement chassisElement, ref MechBayChassisUnitElement ___selectedChassis, MechBayRowGroupWidget ___bayGroupWidget) { try { var chassisDef = chassisElement.ChassisDef; if (!chassisDef.IsVehicle()) { return(true); } var id = chassisElement.ChassisDef.Description.Id; var sim = __instance.Sim; int start = sim.VehicleShift(); int end = start + sim.GetMaxActiveMechs(); int baySlot = -1; for (int i = start; i < end; i++) { MechDef mech_in_slot = null; if (!sim.ActiveMechs.TryGetValue(i, out mech_in_slot)) { sim.ReadyingMechs.TryGetValue(i, out mech_in_slot); } if (mech_in_slot == null) { baySlot = i; break; } } if (baySlot < 0) { Control.Instance.LogDebug(DInfo.General, "No Free vehicle slots for {0}", id); return(false); } var mid = ChassisHandler.GetMDefFromCDef(id); var sim_id = sim.GenerateSimGameUID(); var stock = __instance.DataManager.MechDefs.Get(mid); var mech = new MechDef(chassisDef, sim_id, stock); mech.SetInventory(stock.Inventory); WorkOrderEntry_ReadyMech workOrderEntry_ReadyMech = new WorkOrderEntry_ReadyMech( string.Format("ReadyMech-{0}", sim_id), Strings.T("Readying 'Mech - {0}", new object[] { chassisDef.Description.Name }), sim.Constants.Story.MechReadyTime, baySlot, mech, Strings.T( sim.Constants.Story.MechReadiedWorkOrderCompletedText, new object[] { chassisDef.Description.Name })); sim.MechLabQueue.Add(workOrderEntry_ReadyMech); sim.ReadyingMechs[baySlot] = mech; sim.RoomManager.AddWorkQueueEntry(workOrderEntry_ReadyMech); sim.UpdateMechLabWorkQueue(false); sim.RemoveItemStat(id, typeof(MechDef), false); AudioEventManager.PlayAudioEvent("audioeventdef_simgame_vo_barks", "workqueue_readymech", WwiseManager.GlobalAudioObject, null); ___selectedChassis = null; __instance.RefreshData(true); __instance.ViewBays(); __instance.SelectMech(___bayGroupWidget.GetMechUnitForSlot(baySlot), true); } catch (Exception e) { Control.Instance.LogError(e); } return(false); }