Exemplo n.º 1
0
        /// <summary>
        /// Places the page item in the page
        /// </summary>
        /// <param name="holder"></param>
        /// <param name="owner"></param>
        public override void CreatePageItem(GameObject holder, Mod owner)
        {
            KeyCodeInput keyCodeInput = InternalAssetBundleReferences.ModsWindow.InstantiateObject("CustomKeyCodeInput").AddComponent <KeyCodeInput>();

            keyCodeInput.transform.parent = holder.transform;
            keyCodeInput.Init(DefaultValue, delegate(KeyCode keyCode)
            {
                OptionsSaver.SetSetting(owner, SaveID, (int)keyCode, true);

                if (OnChange != null)
                {
                    OnChange(keyCode);
                }
            });

            object loadedValue = OptionsSaver.LoadSetting(owner, SaveID);

            if (loadedValue != null && loadedValue is int intValue && intValue != (int)DefaultValue)
            {
                keyCodeInput.SelectedKey = (KeyCode)intValue;
            }

            keyCodeInput.GetComponent <ModdedObject>().GetObject <Text>(2).text = DisplayName;

            applyCustomRect(keyCodeInput.gameObject);

            if (OnCreate != null)
            {
                OnCreate(keyCodeInput);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Places the page item in the page
        /// </summary>
        /// <param name="holder"></param>
        /// <param name="owner"></param>
        public override void CreatePageItem(GameObject holder, Mod owner)
        {
            if (Options.Length <= DefaultValue || DefaultValue < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(DefaultValue) + " must be in the bounds of the passed options");
            }

            GameObject spawnedPrefab = InternalAssetBundleReferences.ModsWindow.InstantiateObject("DropDown");

            spawnedPrefab.transform.parent = holder.transform;
            ModdedObject spawnedModdedObject = spawnedPrefab.GetComponent <ModdedObject>();

            spawnedModdedObject.GetObject <Text>(0).text = DisplayName;

            Dropdown dropdown = spawnedModdedObject.GetObject <Dropdown>(1);

            dropdown.options.Clear();

            foreach (string option in Options)
            {
                Dropdown.OptionData data = new Dropdown.OptionData(option);
                dropdown.options.Add(data);
            }
            dropdown.value = DefaultValue;
            dropdown.RefreshShownValue();

            object loadedValue = OptionsSaver.LoadSetting(owner, SaveID);

            if (loadedValue != null && loadedValue is int intValue)
            {
                dropdown.value = intValue;
                dropdown.RefreshShownValue();
            }

            if (OnChange != null)
            {
                OnChange(dropdown.value);
            }

            dropdown.onValueChanged.AddListener(delegate(int value)
            {
                OptionsSaver.SetSetting(owner, SaveID, value, true);

                if (OnChange != null)
                {
                    OnChange(value);
                }
            });

            applyCustomRect(spawnedPrefab);

            if (OnCreate != null)
            {
                OnCreate(dropdown);
            }
        }
        /// <summary>
        /// Places the page item in the page
        /// </summary>
        /// <param name="holder"></param>
        /// <param name="owner"></param>
        public override void CreatePageItem(GameObject holder, Mod owner)
        {
            GameObject spawnedPrefab = InternalAssetBundleReferences.ModsWindow.InstantiateObject("InputField");

            spawnedPrefab.transform.parent = holder.transform;
            ModdedObject spawnedModdedObject = spawnedPrefab.GetComponent <ModdedObject>();

            spawnedModdedObject.GetObject <Text>(0).text = DisplayName;
            InputField inputField = spawnedModdedObject.GetObject <InputField>(1);

            inputField.text = DefaultValue;

            object loadedValue = OptionsSaver.LoadSetting(owner, SaveID);

            if (loadedValue != null && loadedValue is string stringValue)
            {
                inputField.text = stringValue;
                _oldValue       = stringValue;

                if (OnChange != null)
                {
                    OnChange(inputField.text);
                }
            }
            else
            {
                _oldValue = DefaultValue;
            }

            inputField.onEndEdit.AddListener(delegate(string value)
            {
                if (!Verify(value))
                {
                    inputField.text = _oldValue;
                    return;
                }

                _oldValue = value;

                OptionsSaver.SetSetting(owner, SaveID, value, true);

                if (OnChange != null)
                {
                    OnChange(value);
                }
            });

            applyCustomRect(spawnedPrefab);

            if (OnCreate != null)
            {
                OnCreate(inputField);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Places the page item in the page
        /// </summary>
        /// <param name="holder"></param>
        /// <param name="owner"></param>
        public override void CreatePageItem(GameObject holder, Mod owner)
        {
            GameObject spawnedPrefab = InternalAssetBundleReferences.ModsWindow.InstantiateObject("Slider");

            spawnedPrefab.transform.parent = holder.transform;
            ModdedObject spawnedModdedObject = spawnedPrefab.GetComponent <ModdedObject>();

            spawnedModdedObject.GetObject <Text>(0).text = DisplayName;
            Slider slider = spawnedModdedObject.GetObject <Slider>(1);

            slider.minValue     = Min;
            slider.maxValue     = Max;
            slider.value        = DefaultValue;
            slider.wholeNumbers = true;
            Text numberDisplay = spawnedModdedObject.GetObject <Text>(2);

            object loadedValue = OptionsSaver.LoadSetting(owner, SaveID);

            if (loadedValue != null && loadedValue is int intValue)
            {
                slider.value = intValue;
            }

            if (OnChange != null)
            {
                OnChange((int)slider.value);
            }

            numberDisplay.text = slider.value.ToString();

            slider.onValueChanged.AddListener(delegate(float value)
            {
                OptionsSaver.SetSetting(owner, SaveID, (int)value, true);

                if (OnChange != null)
                {
                    OnChange((int)value);
                }

                numberDisplay.text = value.ToString();
            });

            applyCustomRect(spawnedModdedObject.gameObject);

            if (OnCreate != null)
            {
                OnCreate(slider);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Places the page item in the page
        /// </summary>
        /// <param name="holder"></param>
        /// <param name="owner"></param>
        public override void CreatePageItem(GameObject holder, Mod owner)
        {
            GameObject spawnedObject = InternalAssetBundleReferences.ModsWindow.InstantiateObject("Checkbox");

            spawnedObject.transform.parent = holder.transform;
            ModdedObject moddedObject = spawnedObject.GetComponent <ModdedObject>();
            Toggle       toggle       = moddedObject.GetObject <Toggle>(0);

            toggle.isOn = DefaultValue;
            moddedObject.GetObject <GameObject>(1).GetComponent <Text>().text = DisplayName;

            object loadedBool = OptionsSaver.LoadSetting(owner, SaveID);

            if (loadedBool != null && loadedBool is bool boolValue)
            {
                toggle.isOn = boolValue;
            }

            if (OnChange != null)
            {
                OnChange(toggle.isOn);
            }

            toggle.onValueChanged.AddListener(delegate(bool value)
            {
                OptionsSaver.SetSetting(owner, SaveID, value, true);

                if (OnChange != null)
                {
                    OnChange(value);
                }
            });

            applyCustomRect(moddedObject.gameObject);

            if (OnCreate != null)
            {
                OnCreate(toggle);
            }
        }