コード例 #1
0
        static void Postfix(SimGameDifficultySettingsModule __instance, PreGameCareerModeSettingsTotalScoreDescAndBar ___difficultyBarAndMod)
        {
            if (__instance != null && ___difficultyBarAndMod != null)
            {
                ___difficultyBarAndMod.TotalScoreModifierLabel.SetText(
                    new Text(Mod.LocalizedText.SimGameDifficultyStrings[ModText.SGDS_Desc], new object[] { })
                    );

                GameObject difficultyTotalGO = __instance.gameObject.FindFirstChildNamed("OBJ_difficultyTotal");
                if (difficultyTotalGO != null)
                {
                    // Find difTotal-text
                    GameObject diffTotalGO = difficultyTotalGO.FindFirstChildNamed("difTotal-text");
                    if (diffTotalGO != null)
                    {
                        // Use the label here
                        LocalizableText localText = diffTotalGO.GetComponent <LocalizableText>();
                        if (localText != null)
                        {
                            Mod.Log.Info?.Write("UPDATED LABEL");
                            localText.SetText(Mod.LocalizedText.SimGameDifficultyStrings[ModText.SGDS_Label]);
                        }
                        else
                        {
                            Mod.Log.Warn?.Write("FAILED TO FIND LocalizableText COMP FOR `diffTotal-text`");
                        }
                    }
                    else
                    {
                        Mod.Log.Warn?.Write("FAILED TO FIND `diffTotal-text` CHILD OF `OBJ_difficultyTotal`!");
                    }
                }
            }
        }
コード例 #2
0
        static bool Prefix(SimGameDifficultySettingsModule __instance, SimGameDifficulty ___cachedDiff,
                           PreGameCareerModeSettingsTotalScoreDescAndBar ___difficultyBarAndMod)
        {
            float num    = __instance.CalculateRawScoreMod();
            bool  active = __instance.ShouldShowDifficultyData();

            ___difficultyBarAndMod.gameObject.SetActive(active);
            ___difficultyBarAndMod.RefreshInfo(num);

            if (__instance.CanModifyStartSettings)
            {
                var atlasSkull      = GameObject.Find("atlasSkull-image");
                var atlasImage      = atlasSkull.gameObject.GetComponent <Image>();
                var currentModifier = Mathf.Abs(Mathf.Max(0, num) - ModState.MaxDiffModifier);
                var scaledModifier  = Mathf.FloorToInt(currentModifier * 255 / ModState.MaxDiffModifier);
                Mod.Log.Info?.Write($"COLOR SCORE MOD THING: real score {num} vs current {currentModifier} vs scaled {scaledModifier}");
                Mod.Log.Info?.Write($"From UPDATEDIFFICULTYSCOREBAR: Atlas values: {atlasImage.color.r}, {atlasImage.color.g}, {atlasImage.color.b}, {atlasImage.color.a}");
                atlasImage.color = new Color32(255, (byte)scaledModifier, (byte)scaledModifier, 255);;
            }

            return(false);
        }
コード例 #3
0
        static void Postfix(SimGameDifficultySettingsModule __instance, SimGameDifficulty ___cachedDiff, string ___ironManModeId, string ___autoEquipMechsId, string ___mechPartsReqId, string ___skipPrologueId, string ___randomMechId, string ___argoUpgradeCostId, SGDSToggle ___ironManModeToggle, SGDSDropdown ___mechPartsReqDropdown, GameObject ___disabledOverlay, List <SGDSDropdown> ___activeDropdowns, List <SGDSToggle> ___activeToggles, List <SGDSDropdown> ___cachedDropdowns, List <SGDSToggle> ___cachedToggles, SGDSToggle ___togglePrefab, SGDSDropdown ___dropdownPrefab)
        {
            var existingStartOnlyVars = new List <string>()
            {
                ___ironManModeId,
                ___autoEquipMechsId,
                ___mechPartsReqId,
                ___skipPrologueId,
                ___randomMechId,
                ___argoUpgradeCostId
            };

            ___cachedDiff = UnityGameInstance.BattleTechGame.DifficultySettings;
            var settings = ___cachedDiff.GetSettings();

            settings.Sort(delegate(SimGameDifficulty.DifficultySetting a, SimGameDifficulty.DifficultySetting b)
            {
                if (a.UIOrder != b.UIOrder)
                {
                    return(a.UIOrder.CompareTo(b.UIOrder));
                }
                return(a.Name.CompareTo(b.Name));
            });

            foreach (var setting in settings)
            {
                if (setting.Visible)
                {
                    int curSettingIndex = ___cachedDiff.GetCurSettingIndex(setting.ID);

                    if (setting.StartOnly && existingStartOnlyVars.All(x => x != setting.ID))
                    {
                        if (!setting.Toggle)
                        {
                            var sourceSettingDropDownGO = ___mechPartsReqDropdown.gameObject;

                            GameObject newDropDownObject = UnityEngine.Object.Instantiate <GameObject>(sourceSettingDropDownGO, sourceSettingDropDownGO.transform.parent);

                            SGDSDropdown newDropDown = newDropDownObject.GetOrAddComponent <SGDSDropdown>();

                            var dropdown     = Traverse.Create(newDropDown).Field("dropdown").GetValue <HBS_Dropdown>();
                            var dropdownrect = dropdown.gameObject.GetComponent <RectTransform>();
                            dropdownrect.sizeDelta = new Vector2(170, 40);

                            var dropdownLabel = Traverse.Create(dropdown).Field("m_CaptionText")
                                                .GetValue <LocalizableText>();
                            dropdownLabel.enableWordWrapping = false;

                            if (!ModState.instantiatedDropdowns.Contains(newDropDown))
                            {
                                ___activeDropdowns.Add(newDropDown);
                                newDropDown.Initialize(__instance, setting, curSettingIndex);
                                newDropDown.gameObject.SetActive(true);
                                ModState.instantiatedDropdowns.Add(newDropDown);
                            }
                        }
                        else if (setting.Toggle)
                        {
                            var        sourceDiffToggleGO = ___ironManModeToggle.gameObject;
                            GameObject sourceDiffToggle   = UnityEngine.Object.Instantiate <GameObject>(sourceDiffToggleGO, sourceDiffToggleGO.transform.parent);
                            SGDSToggle newToggle          = sourceDiffToggle.GetOrAddComponent <SGDSToggle>();

                            if (!ModState.instantiatedToggles.Contains(newToggle))
                            {
                                ___activeToggles.Add(newToggle);
                                newToggle.Initialize(__instance, setting, curSettingIndex);
                                newToggle.gameObject.SetActive(true);
                                ModState.instantiatedToggles.Add(newToggle);
                            }
                        }
                    }
                }
            }

            var newDisabledOverlay =
                UnityEngine.Object.Instantiate <GameObject>(___disabledOverlay, ___disabledOverlay.transform.parent);

            ___disabledOverlay.SetActive(false);
            newDisabledOverlay.SetActive(!__instance.CanModifyStartSettings);
            __instance.UpdateDifficultyScoreBar();
            ModState.HaveDiffSettingsInitiated = true;
        }
コード例 #4
0
        static void Prefix(SimGameDifficultySettingsModule __instance, SimGameDifficulty ___cachedDiff, PreGameCareerModeSettingsTotalScoreDescAndBar ___difficultyBarAndMod)
        {
            if (ModState.HaveDiffSettingsInitiated)
            {
                return;
            }

            ___cachedDiff = UnityGameInstance.BattleTechGame.DifficultySettings;

            if (ModState.MaxDiffModifier == 0f && ModState.MinDiffModifier == 0f)
            {
                Helper.DifficultyHelper.GetDifficultyModifierRange(___cachedDiff);
            }

            if (__instance.CanModifyStartSettings)
            {
                var atlasSkull      = GameObject.Find("atlasSkull-image");
                var atlasImage      = atlasSkull.gameObject.GetComponent <Image>();
                var currentModifier = Mathf.Abs(Mathf.Max(0, __instance.CalculateRawScoreMod()) - ModState.MaxDiffModifier);
                var scaledModifier  = Mathf.FloorToInt(currentModifier * 255 / ModState.MaxDiffModifier);
                atlasImage.color = new Color32(255, (byte)scaledModifier, (byte)scaledModifier, 255);
                Mod.Log.Info?.Write($"From INITSETTINGS: Atlas values: {atlasImage.color.r}, {atlasImage.color.g}, {atlasImage.color.b}, {atlasImage.color.a}");
            }

            var settings = ___cachedDiff.GetSettings();

            settings.Sort(delegate(SimGameDifficulty.DifficultySetting a, SimGameDifficulty.DifficultySetting b)
            {
                if (a.UIOrder != b.UIOrder)
                {
                    return(a.UIOrder.CompareTo(b.UIOrder));
                }
                return(a.Name.CompareTo(b.Name));
            });
            var startCount = -5;

            foreach (var setting in settings)
            {
                if (setting.Visible && setting.StartOnly && setting.Enabled)
                {
                    startCount += 1;
                }
            }

            var startYAdjust = startCount / 2;

            var regularDiffs = GameObject.Find("difficulty_scroll");
            var startOnly    = GameObject.Find("OBJ_startOnly_settings");
            var startRect    = startOnly.GetComponent <RectTransform>();


            if (startYAdjust > 0)
            {
                if (__instance.CanModifyStartSettings)
                {
                    var barRect       = ___difficultyBarAndMod.gameObject.GetComponent <RectTransform>();
                    var currentbarPos = barRect.position;
                    currentbarPos.x  = 700f;
                    currentbarPos.y  = 400f;
                    barRect.position = currentbarPos;
                }
                else
                {
                    var barRect       = ___difficultyBarAndMod.gameObject.GetComponent <RectTransform>();
                    var currentbarPos = barRect.position;
                    currentbarPos.y  = 820f;
                    barRect.position = currentbarPos;
                }


                var currentStartPosition = startRect.position;
                currentStartPosition.y += Mod.Config.Misc.DifficultyUIScaling.StartOnlyPositionY;
                startRect.position      = currentStartPosition;

                var currentStartSizeDelta = startRect.sizeDelta;

                currentStartSizeDelta.y += startYAdjust * Mod.Config.Misc.DifficultyUIScaling.StartOnlyScalar;
                startRect.sizeDelta      = currentStartSizeDelta;

                var regularRect         = regularDiffs.GetComponent <RectTransform>();
                var currentRegSizeDelta = regularRect.sizeDelta;
                currentRegSizeDelta.y -= startYAdjust - 1 * Mod.Config.Misc.DifficultyUIScaling.StartOnlyScalar;
                regularRect.sizeDelta  = currentRegSizeDelta;

                var currentRegPosition = regularRect.position;
                currentRegPosition.y += Mod.Config.Misc.DifficultyUIScaling.RegularPositionY;
                currentRegPosition.y -= (startYAdjust * Mod.Config.Misc.DifficultyUIScaling.StartOnlyPositionY);
                regularRect.position  = currentRegPosition;
            }

            var startTransformLayoutGroup = startOnly.GetComponent <RectTransform>().GetComponent <GridLayoutGroup>();

            startTransformLayoutGroup.childAlignment = TextAnchor.UpperCenter;
            startTransformLayoutGroup.cellSize       = new Vector2(375, 40);
            startTransformLayoutGroup.spacing        = new Vector2(25, 10);
        }