Exemplo n.º 1
0
 //[Conditional("COLORICON")]
 public static void SetTColor(this UIColorRefTracker color_text, UIColorRefTracker color_icon, MechComponentDef cdef)
 {
     if (cdef.Is <ITColorComponent>(out var color))
     {
         if (color.SkipText)
         {
             color_text.SetUIColor(UIColor.White);
         }
         else
         {
             color_text.SetCustomColor(color.UIColor, color.RGBColor);
         }
         if (color_icon != null)
         {
             if (color.SkipIcon)
             {
                 color_icon.SetUIColor(UIColor.White);
             }
             else
             {
                 color_icon.SetCustomColor(color.UIColor, color.RGBColor);
             }
         }
     }
     else
     {
         color_text.SetUIColor(UIColor.White);
         if (color_icon != null)
         {
             color_icon.SetUIColor(UIColor.White);
         }
     }
 }
    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 void SetCustomColor(this UIColorRefTracker color_tracker, UIColor uicolor, Color color)
 {
     color_tracker.SetUIColor(uicolor);
     if (uicolor == UIColor.Custom)
     {
         color_tracker.OverrideWithColor(color);
     }
 }
        static bool Prefix(SGDifficultyIndicatorWidget __instance, List <UIColorRefTracker> ___pips, UIColor ___activeColor, ref int difficulty)
        {
            Traverse difficultySetter = Traverse.Create(__instance).Property("Difficulty");

            difficultySetter.SetValue(difficulty);
            __instance.Reset();
            float f = ((float)(difficulty) % 10) / 2f;

            if (!DCECore.settings.useDiffRungs)
            {
                f = Mathf.Min((float)difficulty / 2f, 5f);
            }
            else
            {
                if ((difficulty % 10) == 0 && difficulty != 0)
                {
                    f = 5f;
                }
            }

            int   index;
            Color color;
            bool  customColor = DCECore.settings.getRungColor(Math.Max((difficulty - 1) / 10, 0), out color);

            for (index = 0; index < Mathf.FloorToInt(f); ++index)
            {
                UIColorRefTracker pip = ___pips[index];
                pip.GetComponent <SVGImage>().fillAmount = 1f;

                if (customColor)
                {
                    pip.SetUIColor(UIColor.Custom);
                    pip.OverrideWithColor(color);
                }
                else
                {
                    pip.SetUIColor(___activeColor);
                }
            }
            if ((double)index >= (double)f)
            {
                return(false);
            }
            UIColorRefTracker pip1      = ___pips[index];
            SVGImage          component = pip1.GetComponent <SVGImage>();

            if (customColor)
            {
                pip1.SetUIColor(UIColor.Custom);
                pip1.OverrideWithColor(color);
            }
            else
            {
                pip1.SetUIColor(___activeColor);
            }
            component.fillAmount = f - (float)index;
            return(false);
        }
 public static void SetColor(this UIColorRefTracker color_tracker, MechComponentDef cdef)
 {
     if (cdef.Is <IColorComponent>(out var color))
     {
         color_tracker.SetCustomColor(color.UIColor, color.RGBColor);
     }
     else
     {
         color_tracker.SetUIColor(MechComponentDef.GetUIColor(cdef));
     }
 }
Exemplo n.º 6
0
 public static void Prefix(UIColorRefTracker __instance, Color newColor)
 {
     try
     {
         //Logger.Debug($"[UIColorRefTracker.OverrideWithColor_PREFIX] newColor: {newColor}");
         //Logger.Info($"[UIColorRefTracker.OverrideWithColor_PREFIX] Marking __instance.colorRef.UIColor as UIColor.Custom");
         __instance.colorRef.UIColor = UIColor.Custom;
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Exemplo n.º 7
0
 public static void Postfix(MechLabItemSlotElement __instance, UIColorRefTracker ___backgroundColor)
 {
     try
     {
         if (HasOverrideColor(__instance.ComponentRef.Def, out Color overrideColor))
         {
             ___backgroundColor.OverrideWithColor(overrideColor);
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Exemplo n.º 8
0
 public static void SetColor(this UIColorRefTracker color_tracker, MechComponentRef cref)
 {
     if (cref.Is <IColorComponent>(out var color))
     {
         color_tracker.SetUIColor(color.UIColor);
         if (color.UIColor == UIColor.Custom)
         {
             color_tracker.OverrideWithColor(color.RGBColor);
         }
     }
     else
     {
         color_tracker.SetUIColor(MechComponentRef.GetUIColor(cref));
     }
 }
 public static void SetColor(LanceMechEquipmentListItem __instance,
                             MechComponentDef MechDef, UIColorRefTracker ___backgroundColor, UIColorRefTracker ___itemTextColor)
 {
     try
     {
         ___backgroundColor.SetColor(MechDef);
         if (LanceMechEquipmentListItem_SetData.DamageLevel == ComponentDamageLevel.Functional)
         {
             ___itemTextColor.SetTColor(null, MechDef);
         }
     }
     catch (Exception e)
     {
         Control.LogError(e);
     }
 }
Exemplo n.º 10
0
        // endo-steel and ferros-fibrous calculations for mechlab info widget
        public static void Postfix(
            MechLabMechInfoWidget __instance,
            MechLabPanel ___mechLab,
            TextMeshProUGUI ___totalTonnage,
            UIColorRefTracker ___totalTonnageColor,
            TextMeshProUGUI ___remainingTonnage,
            UIColorRefTracker ___remainingTonnageColor)
        {
            try
            {
                if (___mechLab == null)
                {
                    return;
                }
                var mechDef = ___mechLab.activeMechDef;
                if (mechDef == null)
                {
                    return;
                }

                __instance.currentTonnage += CalculateTonnageFacade.AdditionalTonnage(mechDef);

                var current = __instance.currentTonnage;
                var max     = mechDef.Chassis.Tonnage;

                var left     = max - current;
                var uicolor  = left >= 0f ? UIColor.WhiteHalf : UIColor.Red;
                var uicolor2 = left >= 0f ? (left > 5f ? UIColor.White : UIColor.Gold) : UIColor.Red;
                ___totalTonnage.text = String.Format("{0:###0.##} / {1}", current, max);
                ___totalTonnageColor.SetUIColor(uicolor);
                if (left < 0f)
                {
                    left = Mathf.Abs(left);
                    ___remainingTonnage.text = String.Format("{0:###0.##} ton{1} overweight", left, left != 1f ? "s" : String.Empty);
                }
                else
                {
                    ___remainingTonnage.text = String.Format("{0:###0.##} ton{1} remaining", left, left != 1f ? "s" : String.Empty);
                }
                ___remainingTonnageColor.SetUIColor(uicolor2);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
Exemplo n.º 11
0
        static bool Prefix(SGDifficultyIndicatorWidget __instance, int difficulty,
                           List <UIColorRefTracker> ___pips, ref UIColor ___defaultColor, ref UIColor ___activeColor)
        {
            difficulty = __instance.Difficulty;
            __instance.Reset();
            int   num  = new System.Random().Next(0, 100) + 1;
            float num2 = 0f;

            if (num > 95 && difficulty >= 3)
            {
                num2 = (float)difficulty / 2f - 1f;
            }
            if (num <= 95 && num > 65 && difficulty >= 2)
            {
                num2 = (float)difficulty / 2f - 0.5f;
            }
            if (num <= 65 && num > 40 && difficulty <= 8)
            {
                num2 = (float)difficulty / 2f + 0.5f;
            }
            if (num <= 40 || difficulty < 2 || difficulty > 8)
            {
                num2 = (float)difficulty / 2f;
            }

            int i;

            for (i = 0; i < Mathf.FloorToInt(num2); i++)
            {
                UIColorRefTracker uicolorRefTracker = ___pips[i];
                uicolorRefTracker.GetComponent <SVGImage>().fillAmount = 1f;
                uicolorRefTracker.SetUIColor(___activeColor);
            }
            if ((float)i < num2)
            {
                UIColorRefTracker uicolorRefTracker2 = ___pips[i];
                SVGImage          component          = uicolorRefTracker2.GetComponent <SVGImage>();
                uicolorRefTracker2.SetUIColor(___activeColor);
                component.fillAmount = num2 - (float)i;
            }
            return(false);
        }
Exemplo n.º 12
0
        static void Postfix(SGCaptainsQuartersStatusScreen __instance)
        {
            try {
                SimGameState simState = (SimGameState)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "simState").GetValue(__instance);
                if (Fields.Deployment && (simState.DayRemainingInQuarter <= Fields.DeploymentRemainingDays))
                {
                    ReflectionHelper.InvokePrivateMethode(__instance, "AddListLineItem", new object[] { ReflectionHelper.GetPrivateField(__instance, "SectionOneExpensesList"), "Deployment Salary", SimGameState.GetCBillString(0 - Fields.DeploymentSalary) });
                    TextMeshProUGUI SectionOneExpensesField = (TextMeshProUGUI)ReflectionHelper.GetPrivateField(__instance, "SectionOneExpensesField");
                    int             newTotal = int.Parse(SectionOneExpensesField.text.Replace("¢", "").Replace(",", ""));
                    ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { SectionOneExpensesField, SimGameState.GetCBillString(newTotal - Fields.DeploymentSalary) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) });
                }
                Fields.InvertCBills = false;
                SGFinancialForecastWidget FinanceWidget = (SGFinancialForecastWidget)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "FinanceWidget").GetValue(__instance);
                FinanceWidget.RefreshData();
                TextMeshProUGUI EndOfQuarterFunds = (TextMeshProUGUI)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "EndOfQuarterFunds").GetValue(__instance);
                TextMeshProUGUI CurrentFunds      = (TextMeshProUGUI)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "CurrentFunds").GetValue(__instance);

                if (simState.GetExpenditures(false) <= 0)
                {
                    TextMeshProUGUI   QuarterOperatingExpenses = (TextMeshProUGUI)AccessTools.Field(typeof(SGCaptainsQuartersStatusScreen), "QuarterOperatingExpenses").GetValue(__instance);
                    UIColorRefTracker BR = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("BR"));
                    BR.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker BL = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("BL"));
                    BL.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker TL = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("TL"));
                    TL.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker TR = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("TR"));
                    TR.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker txt_opExpensesLabel = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("txt_opExpensesLabel"));
                    txt_opExpensesLabel.colorRef.UIColor = UIColor.Green;
                    UIColorRefTracker txt_opExpensesAmmount = QuarterOperatingExpenses.transform.parent.GetComponentsInChildren <UIColorRefTracker>().FirstOrDefault(x => x.name.Equals("txt_opExpensesAmmount"));
                    txt_opExpensesAmmount.colorRef.UIColor = UIColor.Green;
                }

                ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { EndOfQuarterFunds, SimGameState.GetCBillString(simState.Funds + simState.GetExpenditures(false)) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) });
                ReflectionHelper.InvokePrivateMethode(__instance, "SetField", new object[] { CurrentFunds, SimGameState.GetCBillString(simState.Funds) }, new Type[] { typeof(TextMeshProUGUI), typeof(string) });
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
Exemplo n.º 13
0
        static void Postfix(SGFinancialForecastWidget __instance)
        {
            try {
                SimGameState simState     = (SimGameState)AccessTools.Field(typeof(SGFinancialForecastWidget), "simState").GetValue(__instance);
                int          expenditures = simState.GetExpenditures(false);
                if (expenditures < 0)
                {
                    List <Image>             PipFills    = (List <Image>)AccessTools.Field(typeof(SGFinancialForecastWidget), "PipFills").GetValue(__instance);
                    List <UIColorRefTracker> PipColors   = (List <UIColorRefTracker>)AccessTools.Field(typeof(SGFinancialForecastWidget), "PipColors").GetValue(__instance);
                    List <DOTweenAnimation>  PipsToFlash = (List <DOTweenAnimation>)AccessTools.Field(typeof(SGFinancialForecastWidget), "PipsToFlash").GetValue(__instance);
                    for (int i = 0; i < PipFills.Count; i++)
                    {
                        PipFills[i].gameObject.SetActive(true);
                        PipColors[i].SetUIColor(UIColor.Green);
                    }
                    PipsToFlash.ForEach(delegate(DOTweenAnimation tween) {
                        tween.DOPause();
                    });
                    UIColorRefTracker UnderlineColor           = (UIColorRefTracker)AccessTools.Field(typeof(SGFinancialForecastWidget), "UnderlineColor").GetValue(__instance);
                    UIColorRefTracker ReportBGColor            = (UIColorRefTracker)AccessTools.Field(typeof(SGFinancialForecastWidget), "ReportBGColor").GetValue(__instance);
                    UIColorRefTracker SpendingValueColor       = (UIColorRefTracker)AccessTools.Field(typeof(SGFinancialForecastWidget), "SpendingValueColor").GetValue(__instance);
                    UIColorRefTracker FinancialTextColor       = (UIColorRefTracker)AccessTools.Field(typeof(SGFinancialForecastWidget), "FinancialTextColor").GetValue(__instance);
                    Image             BankrupcyIncomingOverlay = (Image)AccessTools.Field(typeof(SGFinancialForecastWidget), "BankrupcyIncomingOverlay").GetValue(__instance);

                    UnderlineColor.SetUIColor(UIColor.Green);
                    ReportBGColor.SetUIColor(UIColor.Green);
                    SpendingValueColor.SetUIColor(UIColor.Green);
                    FinancialTextColor.SetUIColor(UIColor.Green);

                    BankrupcyIncomingOverlay.gameObject.SetActive(false);
                }
                TextMeshProUGUI CurrSpendingValueText = (TextMeshProUGUI)AccessTools.Field(typeof(SGFinancialForecastWidget), "CurrSpendingValueText").GetValue(__instance);
                CurrSpendingValueText.text = string.Format("{0} / mo", SimGameState.GetCBillString(0 - expenditures));
            }
            catch (Exception e) {
                Logger.LogError(e);
            }
        }
Exemplo n.º 14
0
        //[Conditional("COLORICON")]
        public static void SetTColor(this UIColorRefTracker color_text, UIColorRefTracker color_icon, MechComponentRef cref)
        {
            Control.LogDebug(DType.Color, $"TextColor for {cref.ComponentDefID}");
            if (cref.Is <ITColorComponent>(out var color))
            {
                Control.LogDebug(DType.Color, $"-- color found set to {color.UIColor}/{color.RGBColor}");

                if (color.SkipText)
                {
                    color_text.SetUIColor(UIColor.White);
                }
                else
                {
                    color_text.SetCustomColor(color.UIColor, color.RGBColor);
                }
                if (color_icon != null)
                {
                    if (color.SkipIcon)
                    {
                        color_icon.SetUIColor(UIColor.White);
                    }
                    else
                    {
                        color_icon.SetCustomColor(color.UIColor, color.RGBColor);
                    }
                }
            }
            else
            {
                Control.LogDebug(DType.Color, $"-- no color set to white");
                color_text.SetUIColor(UIColor.White);
                if (color_icon != null)
                {
                    color_icon.SetUIColor(UIColor.White);
                }
            }
        }
        public static bool ChangeColor(MechLabItemSlotElement __instance, UIColorRefTracker ___backgroundColor,
                                       GameObject ___fixedEquipmentOverlay, IMechLabDropTarget ___dropParent)
        {
            ___backgroundColor.SetColor(__instance.ComponentRef);



            if (__instance.ComponentRef != null && __instance.ComponentRef.IsFixed)
            {
                var preinstalled = false;
                if (___dropParent is MechLabLocationWidget widget)
                {
                    var helper = new LocationHelper(widget);
                    preinstalled = __instance.ComponentRef.IsModuleFixed(helper.mechLab.activeMechDef);
                }


                if (!Control.Settings.UseDefaultFixedColor)
                {
                    ___fixedEquipmentOverlay.SetActive(true);
                    var color_tracker = ___fixedEquipmentOverlay.GetComponent <UIColorRefTracker>();
                    color_tracker.colorRef.UIColor = UIColor.Custom;
                    color_tracker.colorRef.color   = preinstalled ? Control.Settings.PreinstalledOverlayColor : Control.Settings.DefaultFlagOverlayColor;
                    color_tracker.RefreshUIColors();
                }
                else
                {
                    ___fixedEquipmentOverlay.SetActive(preinstalled);
                }
            }
            else
            {
                ___fixedEquipmentOverlay.SetActive(false);
            }

            return(false);
        }
Exemplo n.º 16
0
 //[Conditional("COLORICON")]
 public static void SetTColor(this IEnumerable <UIColorRefTracker> color_text, UIColorRefTracker color_icon, MechComponentRef cref)
 {
     if (cref.Is <ITColorComponent>(out var color))
     {
         if (color.SkipText)
         {
             color_text.SetCustomColor(UIColor.White, Color.white);
         }
         else
         {
             color_text.SetCustomColor(color.UIColor, color.RGBColor);
         }
         if (color_icon != null)
         {
             if (color.SkipIcon)
             {
                 color_icon.SetUIColor(UIColor.White);
             }
             else
             {
                 color_icon.SetCustomColor(color.UIColor, color.RGBColor);
             }
         }
     }
     else
     {
         foreach (var color_tracker in color_text)
         {
             color_tracker.SetUIColor(UIColor.White);
         }
         if (color_icon != null)
         {
             color_icon.SetUIColor(UIColor.White);
         }
     }
 }
Exemplo n.º 17
0
            public static void Postfix(MechLabMechInfoWidget __instance,
                                       MechLabPanel ___mechLab,
                                       LocalizableText ___totalTonnage,
                                       UIColorRefTracker ___totalTonnageColor,
                                       LocalizableText ___remainingTonnage,
                                       UIColorRefTracker ___remainingTonnageColor)
            {
                try
                {
                    if (___mechLab.activeMechDef != null)
                    {
                        if (___mechLab.activeMechDef.Chassis.ChassisTags.Contains("chassis_ferro"))
                        {
                            float maxTonnage = ___mechLab.activeMechDef.Chassis.Tonnage;

                            float armorTotal = ___mechLab.headWidget.currentArmor;
                            armorTotal += ___mechLab.centerTorsoWidget.currentArmor;
                            armorTotal += ___mechLab.centerTorsoWidget.currentRearArmor;
                            armorTotal += ___mechLab.leftTorsoWidget.currentArmor;
                            armorTotal += ___mechLab.leftTorsoWidget.currentRearArmor;
                            armorTotal += ___mechLab.rightTorsoWidget.currentArmor;
                            armorTotal += ___mechLab.rightTorsoWidget.currentRearArmor;
                            armorTotal += ___mechLab.leftArmWidget.currentArmor;
                            armorTotal += ___mechLab.rightArmWidget.currentArmor;
                            armorTotal += ___mechLab.leftLegWidget.currentArmor;
                            armorTotal += ___mechLab.rightLegWidget.currentArmor;

                            float nonFerroWeight = armorTotal / (UnityGameInstance.BattleTechGame.MechStatisticsConstants.ARMOR_PER_TENTH_TON * 10f);
                            float ferroWeight    = armorTotal / (UnityGameInstance.BattleTechGame.MechStatisticsConstants.ARMOR_PER_TENTH_TON * 11.2f);

                            __instance.currentTonnage += ferroWeight - nonFerroWeight;

                            float   tonnageFree = maxTonnage - __instance.currentTonnage;
                            UIColor uicolor     = (tonnageFree < 0f) ? UIColor.Red : UIColor.WhiteHalf;
                            UIColor uicolor2    = (tonnageFree < 0f) ? UIColor.Red : ((tonnageFree <= 5f) ? UIColor.Gold : UIColor.White);
                            ___totalTonnage.SetText("{0:0.##} / {1}", new object[]
                            {
                                __instance.currentTonnage,
                                maxTonnage
                            });
                            ___totalTonnageColor.SetUIColor(uicolor);
                            if (tonnageFree < 0f)
                            {
                                tonnageFree = Mathf.Abs(tonnageFree);
                                ___remainingTonnage.SetText("{0:0.##} ton{1} overweight", new object[]
                                {
                                    tonnageFree,
                                    (tonnageFree == 1f) ? "" : "s"
                                });
                            }
                            else
                            {
                                ___remainingTonnage.SetText("{0:0.##} ton{1} remaining", new object[]
                                {
                                    tonnageFree,
                                    (tonnageFree == 1f) ? "" : "s"
                                });
                            }
                            ___remainingTonnageColor.SetUIColor(uicolor2);
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }
Exemplo n.º 18
0
 public static void Postfix(LanceMechEquipmentListItem __instance, MechComponentDef MechDef, UIColorRefTracker ___backgroundColor)
 {
     try
     {
         if (HasOverrideColor(MechDef, out Color overrideColor)) // @ToDo: Respect damage level? See "LanceMechEquipmentList.SetLoadout()"
         {
             ___backgroundColor.OverrideWithColor(overrideColor);
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Exemplo n.º 19
0
        public static void Postfix(LanceLoadoutSlot __instance, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText,
                                   UIColorRefTracker ___initiativeColor, HBSTooltip ___initiativeTooltip, LanceConfiguratorPanel ___LC)
        {
            Mod.Log.Trace?.Write("LLS:RID:post - entered.");

            if (___initiativeObj == null || ___initiativeText == null || ___initiativeColor == null || ___initiativeTooltip == null)
            {
                return;
            }

            bool bothSelected = __instance.SelectedMech != null && __instance.SelectedPilot != null;

            if (!bothSelected)
            {
                ___initiativeText.SetText("-");
                ___initiativeColor.SetUIColor(UIColor.MedGray);
            }
            else
            {
                // --- MECH ---
                MechDef       selectedMechDef = __instance.SelectedMech.MechDef;
                List <string> details         = new List <string>();

                // Static initiative from tonnage
                int initPhase    = PhaseHelper.TonnageToPhase((int)Math.Ceiling(__instance.SelectedMech.MechDef.Chassis.Tonnage));
                int initLabelVal = (Mod.MaxPhase + 1) - initPhase;
                details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_BASE], new object[] { initLabelVal }).ToString());

                // Any bonuses from equipment
                int    componentBonus = UnitHelper.GetNormalizedComponentModifier(__instance.SelectedMech.MechDef);
                string componentColor = "FFFFFF";
                if (componentBonus > 0)
                {
                    componentColor = "00FF00";
                }
                if (componentBonus < 0)
                {
                    componentColor = "FF0000";
                }
                details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_COMPONENT], new object[] { componentColor, componentBonus }).ToString());
                Mod.Log.Debug?.Write($"Component bonus is: {componentBonus}");

                // --- LANCE ---
                int lanceBonus = 0;
                if (___LC != null)
                {
                    lanceBonus = ___LC.lanceInitiativeModifier;
                }
                string lanceColor = "FFFFFF";
                if (lanceBonus > 0)
                {
                    lanceColor = "00FF00";
                }
                if (lanceBonus < 0)
                {
                    lanceColor = "FF0000";
                }
                details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_LANCE], new object[] { lanceColor, lanceBonus }).ToString());

                // --- PILOT ---
                // TODO: Get pilot modifiers from abilities - coordinate with BD
                Pilot selectedPilot = __instance.SelectedPilot.Pilot;
                int   pilotBonus    = 0;
                foreach (Ability ability in selectedPilot.PassiveAbilities)
                {
                    foreach (EffectData effectData in ability.Def.EffectData)
                    {
                        if (effectData.effectType == EffectType.StatisticEffect && effectData.statisticData != null && effectData.statisticData.statName == "BaseInitiative")
                        {
                            int mod = Int32.Parse(effectData.statisticData.modValue) * -1;
                            if (effectData.statisticData.operation == StatCollection.StatOperation.Int_Add)
                            {
                                pilotBonus += mod;
                            }
                            else if (effectData.statisticData.operation == StatCollection.StatOperation.Int_Subtract)
                            {
                                pilotBonus -= mod;
                            }
                        }
                    }
                }

                string pilotColor = "FFFFFF";
                if (pilotBonus > 0)
                {
                    pilotColor = "00FF00";
                }
                if (pilotBonus < 0)
                {
                    pilotColor = "FF0000";
                }
                details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_PILOT], new object[] { pilotColor, pilotBonus }).ToString());

                // --- Badge ---
                int summaryInitLabel = initLabelVal + componentBonus + pilotBonus + lanceBonus;
                if (summaryInitLabel > Mod.MaxPhase)
                {
                    summaryInitLabel = Mod.MaxPhase;
                }
                else if (summaryInitLabel < Mod.MinPhase)
                {
                    summaryInitLabel = Mod.MinPhase;
                }
                ___initiativeText.SetText($"{summaryInitLabel}");
                ___initiativeText.color = Color.black;
                ___initiativeColor.SetUIColor(UIColor.White);

                // --- Tooltip ---
                string             tooltipTitle   = $"{selectedMechDef.Name}: {selectedPilot.Name}";
                string             detailsS       = String.Join("\n", details.ToArray());
                string             tooltipText    = new Text(Mod.Config.LocalizedText[ModConfig.LT_LC_TT_SUMMARY], new object[] { detailsS, summaryInitLabel }).ToString();
                BaseDescriptionDef initiativeData = new BaseDescriptionDef("LLS_MECH_TT", tooltipTitle, tooltipText, null);
                ___initiativeTooltip.enabled = true;
                ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData));
            }
        }
Exemplo n.º 20
0
        static void Postfix(SG_HiringHall_Screen __instance,
                            Pilot ___selectedPilot, LocalizableText ___MWInitialCostText, UIColorRefTracker ___MWCostColor,
                            HBSDOTweenButton ___HireButton)
        {
            Mod.Log.Debug?.Write("Updating UpdateMoneySpot");

            if (___selectedPilot != null)
            {
                Mod.Log.Debug?.Write(" -- pilot is selected");

                // Account for the salary
                CrewDetails details       = ModState.GetCrewDetails(___selectedPilot.pilotDef);
                int         modifiedBonus = (int)Mathf.RoundToInt(details.AdjustedBonus);
                string      bonus         = new Text(Mod.LocalizedText.Labels[ModText.LT_Crew_Bonus_Label],
                                                     new string[] { SimGameState.GetCBillString(Mathf.RoundToInt(modifiedBonus)) })
                                            .ToString();
                Mod.Log.Debug?.Write($"  -- bonus will be: {bonus}");

                ___MWInitialCostText.SetText(bonus);

                if (modifiedBonus > ModState.SimGameState.Funds)
                {
                    Mod.Log.Debug?.Write(" -- Disabling hire.");
                    ___MWCostColor.SetUIColor(UIColor.Red);
                    ___HireButton.SetState(ButtonState.Disabled);
                }
                else
                {
                    Mod.Log.Debug?.Write(" -- Enabling hire.");
                    ___MWCostColor.SetUIColor(UIColor.White);
                    ___HireButton.SetState(ButtonState.Enabled);
                }
            }
        }
Exemplo n.º 21
0
        public static void Postfix(LanceLoadoutSlot __instance, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText,
                                   UIColorRefTracker ___initiativeColor, HBSTooltip ___initiativeTooltip, LanceConfiguratorPanel ___LC)
        {
            if (___initiativeObj == null || ___initiativeText == null || ___initiativeColor == null || ___initiativeTooltip == null)
            {
                return;
            }

            //SkillBasedInit.Logger.Log($"LanceLoadoutSlot::RefreshInitiativeData::post - disabling text");
            bool bothSelected = __instance.SelectedMech != null && __instance.SelectedPilot != null;

            if (!bothSelected)
            {
                ___initiativeText.SetText("-");
                ___initiativeColor.SetUIColor(UIColor.MedGray);
            }
            else
            {
                int initValue = 0;

                // --- MECH ---
                MechDef       selectedMechDef = __instance.SelectedMech.MechDef;
                List <string> details         = new List <string>();

                // Static initiative from tonnage
                float tonnage    = __instance.SelectedMech.MechDef.Chassis.Tonnage;
                int   tonnageMod = UnitHelper.GetTonnageModifier(tonnage);
                initValue += tonnageMod;
                details.Add($"Tonnage Base: {tonnageMod}");

                // Any special modifiers by type - NA, Mech is the only type

                // Any modifiers that come from the chassis/mech/vehicle defs
                int componentsMod = UnitHelper.GetNormalizedComponentModifier(selectedMechDef);
                initValue += componentsMod;
                if (componentsMod > 0)
                {
                    details.Add($"<space=2em><color=#00FF00>{componentsMod:+0} components</color>");
                }
                else if (componentsMod < 0)
                {
                    details.Add($"<space=2em><color=#FF0000>{componentsMod:0} components</color>");
                }

                // Modifier from the engine
                int engineMod = UnitHelper.GetEngineModifier(selectedMechDef);
                initValue += engineMod;
                if (engineMod > 0)
                {
                    details.Add($"<space=2em><color=#00FF00>{engineMod:+0} engine</color>");
                }
                else if (engineMod < 0)
                {
                    details.Add($"<space=2em><color=#FF0000>{engineMod:0} engine</color>");
                }

                // --- PILOT ---
                Pilot selectedPilot = __instance.SelectedPilot.Pilot;

                int tacticsMod = PilotHelper.GetTacticsModifier(selectedPilot);
                details.Add($"<space=2em>{tacticsMod:+0} tactics");
                initValue += tacticsMod;

                int pilotTagsMod = PilotHelper.GetTagsModifier(selectedPilot);
                details.AddRange(PilotHelper.GetTagsModifierDetails(selectedPilot));
                initValue += pilotTagsMod;

                int[] randomnessBounds = PilotHelper.GetRandomnessBounds(selectedPilot);

                // --- LANCE ---
                if (___LC != null)
                {
                    initValue += ___LC.lanceInitiativeModifier;
                    if (___LC.lanceInitiativeModifier > 0)
                    {
                        details.Add($"<space=2em><color=#00FF00>{___LC.lanceInitiativeModifier:+0} lance</color>");
                    }
                    else if (___LC.lanceInitiativeModifier < 0)
                    {
                        details.Add($"<space=2em><color=#FF0000>{___LC.lanceInitiativeModifier:0} lance</color>");
                    }
                }

                // --- Badge ---
                ___initiativeText.SetText($"{initValue}");
                ___initiativeText.color = Color.black;
                ___initiativeColor.SetUIColor(UIColor.White);

                // --- Tooltip ---
                int maxInit = Math.Max(initValue - randomnessBounds[0], Mod.MinPhase);
                int minInit = Math.Max(initValue - randomnessBounds[1], Mod.MinPhase);
                details.Add($"Total:{initValue}");
                details.Add($"<space=2em><color=#FF0000>-{randomnessBounds[0]} to -{randomnessBounds[1]} randomness</color> (piloting)");
                details.Add($"<b>Expected Phase<b>: {maxInit} to {minInit}");

                string             tooltipTitle   = $"{selectedMechDef.Name}: {selectedPilot.Name}";
                string             tooltipText    = String.Join("\n", details.ToArray());
                BaseDescriptionDef initiativeData = new BaseDescriptionDef("LLS_MECH_TT", tooltipTitle, tooltipText, null);
                ___initiativeTooltip.enabled = true;
                ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData));
            }
        }
Exemplo n.º 22
0
 // TODO move to CC
 internal static void SetColorFromString(this UIColorRefTracker tracker, string value)
 {
     if (EnumHelper.TryParse <UIColor>(value, out var uiColor, true))
     {
         tracker.SetUIColor(uiColor);
     }
Exemplo n.º 23
0
        // return false so original function does not get called.
        public static bool Prefix(LanceLoadoutSlot __instance, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText,
                                  UIColorRefTracker ___initiativeColor, HBSTooltip ___initiativeTooltip, LanceConfiguratorPanel ___LC)
        {
            if (___initiativeObj == null || ___initiativeText == null || ___initiativeColor == null)
            {
                return(false);
            }
            if (__instance.SelectedMech == null || __instance.SelectedMech.MechDef == null || __instance.SelectedMech.MechDef.Chassis == null)
            {
                ___initiativeObj.SetActive(false);
                return(false);
            }
            if (__instance.SelectedPilot == null || __instance.SelectedPilot.Pilot == null || __instance.SelectedPilot.Pilot.pilotDef == null)
            {
                ___initiativeObj.SetActive(false);
                return(false);
            }
            ___initiativeObj.SetActive(true);

            int num  = 1;            // default to assault phase
            int num2 = 0;            // default to no modification by effects

            float f_walkSpeed = __instance.SelectedMech.MechDef.Chassis.MovementCapDef.MaxWalkDistance;

            if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseSpecialMinSpeed)
            {
                num = 5;                  //special phase
            }
            else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseLightMinSpeed)
            {
                num = 4;                  //light phase
            }
            else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseMediumMinSpeed)
            {
                num = 3;                  //medium phase
            }
            else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseHeavyMinSpeed)
            {
                num = 2;                  //heavy phase
            }
            // check if pilot mods initiative
            if (__instance.SelectedPilot.Pilot.pilotDef.AbilityDefs != null)
            {
                foreach (AbilityDef abilityDef in __instance.SelectedPilot.Pilot.pilotDef.AbilityDefs)
                {
                    foreach (EffectData effect in abilityDef.EffectData)
                    {
                        if (MechStatisticsRules.GetInitiativeModifierFromEffectData(effect, true, null) == 0)
                        {
                            num2 += MechStatisticsRules.GetInitiativeModifierFromEffectData(effect, false, null);
                        }
                    }
                }
            }
            // check if any of the mech's inventory changes initiative.
            if (__instance.SelectedMech.MechDef.Inventory != null)
            {
                foreach (MechComponentRef mechComponentRef in __instance.SelectedMech.MechDef.Inventory)
                {
                    if (mechComponentRef.Def != null && mechComponentRef.Def.statusEffects != null)
                    {
                        foreach (EffectData effect2 in mechComponentRef.Def.statusEffects)
                        {
                            if (MechStatisticsRules.GetInitiativeModifierFromEffectData(effect2, true, null) == 0)
                            {
                                num2 += MechStatisticsRules.GetInitiativeModifierFromEffectData(effect2, false, null);
                            }
                        }
                    }
                }
            }
            // is there a lance bonus?
            int num3 = 0;

            if (___LC != null)
            {
                num3 = ___LC.lanceInitiativeModifier;
            }
            num2 += num3;

            // make sure initiative is within the valid range.
            int num4 = Mathf.Clamp(num + num2, 1, 5);

            //set our text.
            ___initiativeText.SetText($"{num4}");
            if (___initiativeTooltip != null)
            {
                // build the tooltip.  Going to use the mech's name and tell where its speed puts it, initiative-wise.
                string tooltipTitle = $"{__instance.SelectedMech.MechDef.Name}";
                string tooltipText  = "A max walking speed of " + $"{f_walkSpeed}" + "m per turn means this mech moves in initiative phase " + $"{num}" + ".";

                // if there are effects, tell the player what they've changed initiative to.
                if (num2 != 0)
                {
                    tooltipText += " Effects have modified this to phase " + $"{num4}" + ".";
                }
                BaseDescriptionDef initiativeData = new BaseDescriptionDef("MB_MIW_MECH_TT", tooltipTitle, tooltipText, null);
                ___initiativeTooltip.enabled = true;
                ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData));
            }
            // if we've been bumped up, make it gold, if bumped down, make it red, else white.
            ___initiativeColor.SetUIColor((num2 > 0) ? UIColor.Gold : ((num2 < 0) ? UIColor.Red : UIColor.White));

            return(false);
        }
        public static bool ChangeColor(MechLabItemSlotElement __instance, UIColorRefTracker ___backgroundColor,
                                       GameObject ___fixedEquipmentOverlay, IMechLabDropTarget ___dropParent,
                                       UIColorRefTracker ___nameTextColor, UIColorRefTracker ___iconColor, SVGImage ___icon)
        {
            try
            {
                ___backgroundColor.SetColor(__instance.ComponentRef);

                if (__instance.ComponentRef.DamageLevel == ComponentDamageLevel.Functional)
                {
                    ___nameTextColor.SetTColor(___iconColor, __instance.ComponentRef);
                }
                else
                {
                    ___iconColor.SetUIColor(UIColor.White);
                }

                if (___icon.vectorGraphics == null && Control.Settings.FixIcons &&
                    !string.IsNullOrEmpty(__instance.ComponentRef.Def.Description.Icon))
                {
                    var loadrequest =
                        UnityGameInstance.BattleTechGame.DataManager.CreateLoadRequest();
                    loadrequest.AddLoadRequest <SVGAsset>(BTLoadUtils.GetResourceType(nameof(BattleTechResourceType.SVGAsset)),
                                                          __instance.ComponentRef.Def.Description.Icon,
                                                          (id, icon) =>
                    {
                        if (icon != null)
                        {
                            ___icon.vectorGraphics = icon;
                        }
                    });
                    loadrequest.ProcessRequests();
                }

                var color_tracker = ___fixedEquipmentOverlay.GetComponent <UIColorRefTracker>();
                // reset colors in case its a pooled item that was previously fixed
                color_tracker.SetUIColor(Control.Settings.DefaultOverlayColor);

                if (__instance.ComponentRef != null && __instance.ComponentRef.IsFixed)
                {
                    var preinstalled = false;
                    if (___dropParent is MechLabLocationWidget widget)
                    {
                        preinstalled = __instance.ComponentRef.IsModuleFixed((widget.parentDropTarget as MechLabPanel).activeMechDef);
                    }

                    if (!Control.Settings.UseDefaultFixedColor)
                    {
                        ___fixedEquipmentOverlay.SetActive(true);
                        color_tracker.colorRef.UIColor = UIColor.Custom;
                        color_tracker.colorRef.color   = preinstalled
                            ? Control.Settings.PreinstalledOverlayColor
                            : Control.Settings.DefaultFlagOverlayColor;
                    }
                    else
                    {
                        ___fixedEquipmentOverlay.SetActive(preinstalled);
                    }
                }
                else
                {
                    ___fixedEquipmentOverlay.SetActive(false);
                }
                color_tracker.RefreshUIColors();

                return(false);
            }
            catch (Exception e)
            {
                Control.LogError(e);
                return(true);
            }
        }
 public static void SetColor(LanceMechEquipmentListItem __instance,
                             MechComponentDef MechDef, UIColorRefTracker ___backgroundColor)
 {
     ___backgroundColor.SetColor(MechDef);
 }
Exemplo n.º 26
0
        public static void Postfix(
            MechLabPanel ___mechLab,
            ref float ___currentTonnage,
            TextMeshProUGUI ___totalTonnage,
            UIColorRefTracker ___totalTonnageColor,
            TextMeshProUGUI ___remainingTonnage,
            UIColorRefTracker ___remainingTonnageColor)
        {
            try
            {
                var     totalTonnage          = ___totalTonnage;
                var     mechLab               = ___mechLab;
                ref var currentTonnage        = ref ___currentTonnage;
                var     totalTonnageColor     = ___totalTonnageColor;
                var     remainingTonnage      = ___remainingTonnage;
                var     remainingTonnageColor = ___remainingTonnageColor;

                var mechDef = mechLab.CreateMechDef();
                if (mechDef == null)
                {
                    return;
                }

                currentTonnage += WeightsHandler.Shared.TonnageChanges(mechDef);

                var precisionHelper = InfoTonnageHelper.KilogramStandard;

                var maxTonnage = mechDef.Chassis.Tonnage;

                if (precisionHelper.IsSmaller(maxTonnage, currentTonnage))
                {
                    totalTonnageColor.SetUIColor(UIColor.Red);
                    remainingTonnageColor.SetUIColor(UIColor.Red);
                }
                else
                {
                    totalTonnageColor.SetUIColor(UIColor.WhiteHalf);
                    if (precisionHelper.IsSmaller(maxTonnage, currentTonnage + OverrideTonnageFeature.settings.UnderweightWarningThreshold))
                    {
                        remainingTonnageColor.SetUIColor(UIColor.White);
                    }
                    else
                    {
                        remainingTonnageColor.SetUIColor(UIColor.Gold);
                    }
                }

                totalTonnage.SetText(string.Format("{0} / {1}", InfoTonnageHelper.TonnageStandard.AsString(currentTonnage), maxTonnage));
                if (precisionHelper.IsSmaller(maxTonnage, currentTonnage, out var tonnageLeft))
                {
                    tonnageLeft = Mathf.Abs(tonnageLeft);
                    var left = precisionHelper.AsString(tonnageLeft);
                    var s    = precisionHelper.IsSame(tonnageLeft, 1f) ? "s" : string.Empty;
                    remainingTonnage.SetText(string.Format("{0} ton{1} overweight", left, s));
                }
                else
                {
                    var left = precisionHelper.AsString(tonnageLeft);
                    var s    = precisionHelper.IsSame(tonnageLeft, 1f) ? "s" : string.Empty;
                    remainingTonnage.SetText(string.Format("{0} ton{1} remaining", left, s));
                }
            }
 public static void SetUIColor(this UIColorRefTracker color_tracker, UIColor uicolor)
 {
     color_tracker.colorRef.UIColor = uicolor;
     color_tracker.colorRef.color   = LazySingletonBehavior <UIManager> .Instance.UIColorRefs.GetUIColor(uicolor);
 }
Exemplo n.º 28
0
            public static void Postfix(TaskManagementElement __instance, TextMeshProUGUI ___subTitleText, UIColorRefTracker ___subTitleColor,
                                       WorkOrderEntry ___entry)
            {
                WorkOrderEntry_MedBayHeal healOrder = ___entry as WorkOrderEntry_MedBayHeal;

                try
                {
                    if (healOrder.Pilot.pilotDef.TimeoutRemaining > 0 && healOrder.Pilot.pilotDef.Injuries == 0 &&
                        !healOrder.Pilot.pilotDef.PilotTags.Contains("pilot_lightinjury") && healOrder.Pilot.pilotDef.PilotTags.Contains("pilot_fatigued"))
                    {
                        ___subTitleText.text = "FATIGUED";
                        ___subTitleColor.SetUIColor(UIColor.Orange);
                    }
                }
                catch (Exception)
                {
                }
                try
                {
                    if (healOrder.Pilot.pilotDef.TimeoutRemaining > 0 && healOrder.Pilot.pilotDef.Injuries == 0 &&
                        !healOrder.Pilot.pilotDef.PilotTags.Contains("pilot_lightinjury") && !healOrder.Pilot.pilotDef.PilotTags.Contains("pilot_fatigued"))
                    {
                        ___subTitleText.text = "UNAVAILABLE";
                        ___subTitleColor.SetUIColor(UIColor.Blue);
                    }
                }
                catch (Exception)
                {
                }
                try
                {
                    if (healOrder.Pilot.pilotDef.PilotTags.Contains("pilot_lightinjury"))
                    {
                        ___subTitleText.text = "LIGHT INJURY";
                        ___subTitleColor.SetUIColor(UIColor.Green);
                    }
                }
                catch (Exception)
                {
                }
            }
Exemplo n.º 29
0
        static void Postfix(Pilot ___pilot, GameObject ___cantBuyMRBOverlay, HBSTooltip ___cantBuyToolTip,
                            LocalizableText ___costText, UIColorRefTracker ___costTextColor)
        {
            if (ModState.SimGameState == null)
            {
                return;                                // Only patch if we're in SimGame
            }
            Mod.Log.Debug?.Write($"Refreshing availability for pilot: {___pilot.Name}");

            // TODO: This may need to be improved, as it's used inside a loop. Maybe write to company stats?
            CrewDetails details = ModState.GetCrewDetails(___pilot.pilotDef);

            Mod.Log.Debug?.Write($"  -- pilot requires: {details.Size} berths");

            int usedBerths      = CrewHelper.UsedBerths(ModState.SimGameState.PilotRoster);
            int availableBerths = ModState.SimGameState.GetMaxMechWarriors() - usedBerths;

            Mod.Log.Debug?.Write($"AvailableBerths: {availableBerths} = max: {ModState.SimGameState.GetMaxMechWarriors()} - used: {usedBerths}");

            // Check berths limitations
            if (details.Size > availableBerths)
            {
                Mod.Log.Info?.Write($"Pilot {___pilot.Name} cannot be hired, not enough berths (needs {details.Size})");

                ___cantBuyMRBOverlay.SetActive(true);

                HBSTooltipStateData tooltipStateData = new HBSTooltipStateData();
                tooltipStateData.SetContextString($"DM.BaseDescriptionDefs[{ModConsts.Tooltip_NotEnoughBerths}]");
                ___cantBuyToolTip.SetDefaultStateData(tooltipStateData);
            }

            // Check type limitations
            if (!CrewHelper.CanHireMoreCrewOfType(details))
            {
                Mod.Log.Info?.Write($"Pilot {___pilot.Name} cannot be hired, too many of type already employed.");

                ___cantBuyMRBOverlay.SetActive(true);

                HBSTooltipStateData tooltipStateData = new HBSTooltipStateData();
                tooltipStateData.SetContextString($"DM.BaseDescriptionDefs[{ModConsts.Tooltip_TooManyOfType}]");
                ___cantBuyToolTip.SetDefaultStateData(tooltipStateData);
            }
            else
            {
                Mod.Log.Debug?.Write($"Pilot {___pilot.Name} can be hired, no limiations on max.");
            }

            // Set the prices
            //int purchaseCostAfterReputationModifier = ModState.SimGameState.CurSystem.GetPurchaseCostAfterReputationModifier(
            //    ModState.SimGameState.GetMechWarriorHiringCost(___pilot.pilotDef)
            //    );
            // TODO: Apply system cost multiplier
            // Hiring cost is influenced by:
            //  - current morale rating
            //  - any faction alignment for units
            //  - any reputation modifiers

            ___costText.SetText(SimGameState.GetCBillString(details.HiringBonus));

            UIColor costColor = UIColor.Red;

            if (details.HiringBonus <= ModState.SimGameState.Funds)
            {
                costColor = UIColor.White;
            }
            ___costTextColor.SetUIColor(costColor);
        }