示例#1
0
        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);
            }
        }
示例#2
0
        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);
        }