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); } }
private static void SplitToParts(ChassisDef chassisDef, int min, int max, MechBayPanel mechBay) { int k = mechBay.Sim.NetworkRandom.Int(min, max + 1); UnityGameInstance.BattleTechGame.Simulation.ScrapInactiveMech(chassisDef.Description.Id, false); var mech = ChassisHandler.GetMech(chassisDef.Description.Id); for (int i = 0; i < k; i++) { mechBay.Sim.AddMechPart(mech.Description.Id); } mechBay.RefreshData(false); mechBay.SelectChassis(null); GenericPopupBuilder.Create($"Scraped {mech.Description.UIName}.", $"We manage to get <color=#20ff20>{k}</color> parts from {mech.Description.UIName} chassis") .AddButton("Ok", null, true, null) .CancelOnEscape().AddFader(new UIColorRef?(LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.PopupBackfill), 0f, true).Render(); }
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); }