public override void Instantiate()
        {
            gameObject       = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll <GameplayModifierToggle>().Where(g => g.transform.Find("BG"))?.Last().gameObject, Container);
            gameObject.name  = optionName;
            gameObject.layer = Container.gameObject.layer;
            gameObject.transform.SetParent(Container);
            gameObject.transform.localPosition = Vector3.zero;
            gameObject.transform.localScale    = Vector3.one;
            gameObject.transform.rotation      = Quaternion.identity;
            gameObject.SetActive(false);

            // Add a separator for this menu option
            AddSeparator(Container);

            // Remove the multiplier text if the toggle has no multiplier
            if (multiplier == 0)
            {
                gameObject.AddComponent <ToggleNameOverride>();
            }

            currentToggle = gameObject.GetComponent <GameplayModifierToggle>();
            if (currentToggle != null)
            {
                currentToggle.toggle.isOn = GetValue;
                currentToggle.toggle.onValueChanged.RemoveAllListeners();
                currentToggle.toggle.onValueChanged.AddListener((bool e) => OnToggle?.Invoke(e));
                currentToggle.name = optionName;

                GameplayModifierParamsSO _gameplayModifier = ScriptableObject.CreateInstance <GameplayModifierParamsSO>();
                _gameplayModifier.SetPrivateField("_modifierName", optionName);
                _gameplayModifier.SetPrivateField("_hintText", hintText);
                _gameplayModifier.SetPrivateField("_multiplier", multiplier);
                _gameplayModifier.SetPrivateField("_icon", optionIcon == null ? UIUtilities.BlankSprite : optionIcon);
                currentToggle.SetPrivateField("_gameplayModifier", _gameplayModifier);

                if (hintText != String.Empty)
                {
                    HoverHint hoverHint = currentToggle.GetPrivateField <HoverHint>("_hoverHint");
                    hoverHint.text = hintText;
                    hoverHint.name = optionName;
                    HoverHintController hoverHintController = Resources.FindObjectsOfTypeAll <HoverHintController>().First();
                    hoverHint.SetPrivateField("_hoverHintController", hoverHintController);
                }
            }
            initialized = true;
        }
        public override GameObject CreateObject(Transform parent)
        {
            if (toggleTemplate == null)
            {
                toggleTemplate = Resources.FindObjectsOfTypeAll <GameplayModifierToggle>().First(x => x.name == "InstaFail");
            }
            GameplayModifierToggle baseModifier = Object.Instantiate(toggleTemplate, parent, false);

            baseModifier.name = "BSMLModifier";

            GameObject gameObject = baseModifier.gameObject;

            gameObject.SetActive(false);

            Object.Destroy(baseModifier);
            Object.Destroy(gameObject.GetComponent <HoverTextSetter>());
            Object.Destroy(gameObject.transform.Find("Multiplier").gameObject);

            GameObject      nameText = gameObject.transform.Find("Name").gameObject;
            TextMeshProUGUI text     = nameText.GetComponent <TextMeshProUGUI>();

            text.text = "Default Text";

            LocalizableText localizedText = CreateLocalizableText(nameText);

            localizedText.MaintainTextAlignment = true;

            List <Component> externalComponents = gameObject.AddComponent <ExternalComponents>().components;

            externalComponents.Add(text);
            externalComponents.Add(localizedText);
            externalComponents.Add(gameObject.transform.Find("Icon").GetComponent <Image>());

            ToggleSetting toggleSetting = gameObject.AddComponent <ToggleSetting>();

            toggleSetting.toggle = gameObject.GetComponent <Toggle>();
            toggleSetting.toggle.onValueChanged.RemoveAllListeners();

            gameObject.SetActive(true);

            return(gameObject);
        }
        public void SetupConflictText()
        {
            GameplayModifierToggle currentToggle = gameObject.GetComponent <GameplayModifierToggle>();

            if (currentToggle == null)
            {
                return;
            }

            foreach (GameplayModifierToggle conflictToggle in Resources.FindObjectsOfTypeAll <GameplayModifierToggle>())
            {
                if (!conflicts.Contains(conflictToggle.gameplayModifier.modifierName))
                {
                    continue;
                }

                // Setup our hint text and onValueChanged callbacks for the conflicting modifiers
                InitializeConflict(conflictToggle, currentToggle);
            }
        }
示例#4
0
        public override GameObject CreateObject(Transform parent)
        {
            GameplayModifierToggle baseModifier = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll <GameplayModifierToggle>().First(x => (x.name == "InstaFail")), parent, false);

            baseModifier.name = "BSMLModifier";

            GameObject gameObject = baseModifier.gameObject;

            MonoBehaviour.Destroy(baseModifier);
            MonoBehaviour.Destroy(gameObject.GetComponent <HoverHint>());

            ExternalComponents externalComponents = gameObject.AddComponent <ExternalComponents>();

            externalComponents.components.Add(gameObject.GetComponentInChildren <TextMeshProUGUI>());
            externalComponents.components.Add(gameObject.transform.Find("Icon").GetComponent <Image>());

            CheckboxSetting checkboxSetting = gameObject.AddComponent <CheckboxSetting>();

            checkboxSetting.checkbox = gameObject.GetComponent <Toggle>();

            return(gameObject);
        }
        private void InitializeConflict(GameplayModifierToggle toMod, GameplayModifierToggle conflict, bool recursive = true)
        {
            string conflictingDisplayName = $"\uE069{conflict.gameplayModifier.modifierName}\uE069";

            if (!toMod.gameplayModifier.hintText.Contains(ConflictText))
            {
                toMod.gameplayModifier.SetPrivateField("_hintText", toMod.gameplayModifier.hintText + ConflictText);
            }

            if (!toMod.gameplayModifier.hintText.Contains(conflictingDisplayName))
            {
                toMod.gameplayModifier.SetPrivateField("_hintText", toMod.gameplayModifier.hintText + conflictingDisplayName);
                toMod.toggle.onValueChanged.AddListener((e) => { if (e)
                                                                 {
                                                                     conflict.toggle.isOn = false;
                                                                 }
                                                        });
            }
            if (recursive)
            {
                InitializeConflict(conflict, toMod, false);
            }
        }
        public override GameObject CreateObject(Transform parent)
        {
            GameplayModifierToggle baseSetting = Object.Instantiate(Resources.FindObjectsOfTypeAll <GameplayModifierToggle>().First(x => x.name == "InstaFail"), parent, false);

            baseSetting.name = "BSMLCheckboxSetting";

            GameObject gameObject = baseSetting.gameObject;

            gameObject.SetActive(false);

            Object.Destroy(baseSetting);
            Object.Destroy(gameObject.transform.GetChild(0).gameObject);              //Remove icon
            Object.Destroy(gameObject.GetComponent <SignalOnUIToggleValueChanged>()); //Remove base game signal
            Object.Destroy(gameObject.GetComponent <HoverHint>());                    //When parsing, "RectTransform" will already add a new one. No need for this.
            CheckboxSetting checkboxSetting = gameObject.AddComponent <CheckboxSetting>();

            checkboxSetting.checkbox = gameObject.GetComponent <Toggle>();
            TextMeshProUGUI text = gameObject.GetComponentInChildren <TextMeshProUGUI>();

            text.fontSize = 5; //Change some settings to conform more to the List Dropdown/IncDec settings controllers
            text.rectTransform.localPosition    = Vector2.zero;
            text.rectTransform.anchoredPosition = Vector2.zero;
            text.rectTransform.sizeDelta        = Vector2.zero;
            gameObject.AddComponent <ExternalComponents>().components.Add(text);

            LayoutElement layout = gameObject.GetComponent <LayoutElement>(); //If Beat Games decides to add one later down the road.

            if (layout is null)
            {
                layout = gameObject.AddComponent <LayoutElement>(); //For the time being, they dont have one, so time to add one myself!
            }
            layout.preferredWidth  = 90;                            //Again, to conform to List Dropdown/IncDec settings controllers
            layout.preferredHeight = 8;

            gameObject.SetActive(true);
            return(gameObject);
        }
示例#7
0
        public static void Postfix(GameplayModifierToggle __instance)
        {
            RectTransform rectTransform = (RectTransform)__instance.transform.Find("Name");

            rectTransform.sizeDelta += new Vector2(0, 0.1f);
        }
 void Awake()
 {
     _toggle  = GetComponent <GameplayModifierToggle>();
     _tmpText = _toggle.GetPrivateField <TextMeshProUGUI>("_nameText");
 }
        public override void Instantiate()
        {
            //We have to find our own target
            //TODO: Clean up time complexity issue. This is called for each new option
            SoloFreePlayFlowCoordinator sfpfc = Resources.FindObjectsOfTypeAll <SoloFreePlayFlowCoordinator>().First();
            GameplaySetupViewController gsvc  = sfpfc.GetField <GameplaySetupViewController>("_gameplaySetupViewController");
            RectTransform container           = (RectTransform)gsvc.transform.Find(pageName).Find(panelName);

            gameObject       = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll <GameplayModifierToggle>().Where(g => g.transform.Find("BG"))?.Last().gameObject, container);
            gameObject.name  = optionName;
            gameObject.layer = container.gameObject.layer;
            gameObject.transform.SetParent(container);
            gameObject.transform.localPosition = Vector3.zero;
            gameObject.transform.localScale    = Vector3.one;
            gameObject.transform.rotation      = Quaternion.identity;
            gameObject.SetActive(false);

            foreach (Transform t in container)
            {
                if (t.name.StartsWith("Separator"))
                {
                    separator      = UnityEngine.Object.Instantiate(t.gameObject, container);
                    separator.name = "ExtraSeparator";
                    separator.SetActive(false);
                    break;
                }
            }

            string ConflictText  = "\r\n\r\n<size=60%><color=#ff0000ff><b>Conflicts </b></color>";
            var    currentToggle = gameObject.GetComponent <GameplayModifierToggle>();

            if (currentToggle != null)
            {
                currentToggle.toggle.isOn = GetValue;
                currentToggle.toggle.onValueChanged.RemoveAllListeners();
                currentToggle.toggle.onValueChanged.AddListener((bool e) => OnToggle?.Invoke(e));
                currentToggle.name = optionName.Replace(" ", "");

                GameplayModifierToggle[] gameplayModifierToggles = Resources.FindObjectsOfTypeAll <GameplayModifierToggle>();

                if (conflicts.Count > 0)
                {
                    hintText += ConflictText;
                    foreach (string conflict in conflicts)
                    {
                        var conflictingModifier = gameplayModifierToggles.Where(t => t?.gameplayModifier?.modifierName == conflict).FirstOrDefault();
                        if (conflictingModifier)
                        {
                            if (!hintText.Contains(ConflictText))
                            {
                                hintText += ConflictText;
                            }

                            hintText += Char.ConvertFromUtf32((char)0xE069) + conflict + Char.ConvertFromUtf32((char)0xE069);
                        }
                    }
                }

                GameplayModifierParamsSO _gameplayModifier = new GameplayModifierParamsSO();
                _gameplayModifier.SetPrivateField("_modifierName", optionName);
                _gameplayModifier.SetPrivateField("_hintText", hintText);
                _gameplayModifier.SetPrivateField("_multiplier", multiplier);
                _gameplayModifier.SetPrivateField("_icon", optionIcon == null ? UIUtilities.BlankSprite : optionIcon);
                currentToggle.SetPrivateField("_gameplayModifier", _gameplayModifier);

                string currentDisplayName = Char.ConvertFromUtf32((char)0xE069) + optionName + Char.ConvertFromUtf32((char)0xE069);
                foreach (string conflictingModifierName in conflicts)
                {
                    GameplayModifierToggle conflictToggle = gameplayModifierToggles.Where(t => t?.gameplayModifier?.modifierName == conflictingModifierName).FirstOrDefault();
                    if (conflictToggle)
                    {
                        if (!conflictToggle.gameplayModifier.hintText.Contains(ConflictText))
                        {
                            conflictToggle.gameplayModifier.SetPrivateField("_hintText", conflictToggle.gameplayModifier.hintText + ConflictText);
                        }

                        if (!conflictToggle.gameplayModifier.hintText.Contains(currentDisplayName))
                        {
                            conflictToggle.gameplayModifier.SetPrivateField("_hintText", conflictToggle.gameplayModifier.hintText + currentDisplayName);
                        }

                        conflictToggle.toggle.onValueChanged.AddListener((e) => { if (e)
                                                                                  {
                                                                                      currentToggle.toggle.isOn = false;
                                                                                  }
                                                                         });
                        currentToggle.toggle.onValueChanged.AddListener((e) => { if (e)
                                                                                 {
                                                                                     conflictToggle.toggle.isOn = false;
                                                                                 }
                                                                        });
                    }
                }

                if (hintText != String.Empty)
                {
                    HoverHint hoverHint = currentToggle.GetPrivateField <HoverHint>("_hoverHint");
                    hoverHint.text = hintText;
                    hoverHint.name = optionName;
                    HoverHintController hoverHintController = Resources.FindObjectsOfTypeAll <HoverHintController>().First();
                    hoverHint.SetPrivateField("_hoverHintController", hoverHintController);
                }
            }
            initialized = true;
        }