/// <inheritdoc />
        protected override GameObject OnCreateControl(Transform loadBoxTransform)
        {
            var copy = Object.Instantiate(_baseToggle, _root.transform);
            copy.name = "tglItem";

            RemoveLocalisation(copy.gameObject);

            var tgl = copy.GetComponentInChildren<Toggle>();
            tgl.onValueChanged.AddListener(SetValue);
            BufferedValueChanged.Subscribe(b => tgl.isOn = b);
            tgl.image.raycastTarget = true;
            tgl.graphic.raycastTarget = true;

            var txt = copy.GetComponentInChildren<TextMeshProUGUI>();
            txt.text = Text;

            var singleWidth = TotalWidth / (_baseToggles.Count + Toggles.Count);

            var rt = copy.GetComponent<RectTransform>();
            rt.localPosition = new Vector3(_baseToggle.localPosition.x + singleWidth * _createdCount, _verticalOffset, 0);
            rt.offsetMax = new Vector2(rt.offsetMin.x + singleWidth, rt.offsetMin.y + 26);

            copy.gameObject.SetActive(true);
            _createdCount++;

            KoikatuAPI.Instance.StartCoroutine(FixLayout(rt));

            return copy.gameObject;
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var tr = Object.Instantiate(DropdownCopy, subCategoryList, false);

            var settingName = tr.Find("textKindTitle").GetComponent <TextMeshProUGUI>();

            settingName.text  = SettingName;
            settingName.color = TextColor;

            var dropdown = tr.GetComponentInChildren <TMP_Dropdown>();

            dropdown.options.AddRange(Options.Select(x => new TMP_Dropdown.OptionData(x)));

            dropdown.onValueChanged.AddListener(SetValue);
            BufferedValueChanged.Subscribe(i => dropdown.value = i);

            // Fix box not updating if BufferedValueChanged equals the default dropdown val
            if (Value == dropdown.value)
            {
                dropdown.RefreshShownValue();
                SetValue(dropdown.value);
            }

            return(tr.gameObject);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var tr = Object.Instantiate(SliderCopy, subCategoryList, true);

            tr.name = "sldTemp";

            var textMesh = tr.Find("textShape").GetComponent <TextMeshProUGUI>();

            textMesh.text  = _settingName;
            textMesh.color = TextColor;

            var slider = tr.Find("Slider").GetComponent <Slider>();

            slider.minValue = _minValue;
            slider.maxValue = _maxValue;
            slider.onValueChanged.AddListener(SetValue);

            slider.GetComponent <ObservableScrollTrigger>().OnScrollAsObservable().Subscribe(data =>
            {
                var scrollDelta = data.scrollDelta.y;
                var valueChange = Mathf.Pow(10, Mathf.Round(Mathf.Log10(slider.maxValue / 100)));

                if (scrollDelta < 0f)
                {
                    slider.value += valueChange;
                }
                else if (scrollDelta > 0f)
                {
                    slider.value -= valueChange;
                }
            });

            var inputField = tr.Find("InputField").GetComponent <TMP_InputField>();

            inputField.onEndEdit.AddListener(txt =>
            {
                var result   = StringToValue?.Invoke(txt) ?? float.Parse(txt) / 100f;
                slider.value = Mathf.Clamp(result, slider.minValue, slider.maxValue);
            });

            slider.onValueChanged.AddListener(f =>
            {
                if (ValueToString != null)
                {
                    inputField.text = ValueToString(f);
                }
                else
                {
                    inputField.text = Mathf.RoundToInt(f * 100).ToString();
                }
            });

            var resetButton = tr.Find("Button").GetComponent <Button>();

            resetButton.onClick.AddListener(() => slider.value = _defaultValue);

            BufferedValueChanged.Subscribe(f => slider.value = f);

            return(tr.gameObject);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var btn = ToolbarButton.CreateLeftToolbarButton(_iconTex);

            btn.onClick.AddListener(() => Value = !Value);
            BufferedValueChanged.Subscribe(b => btn.image.color = Value ? Color.green : Color.white);
            return(btn.gameObject);
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var dd = MakerAPI.GetMakerBase().CreateColorChangeButton(subCategoryList.gameObject, SettingName, Value, UseAlpha, SetValue);

            BufferedValueChanged.Subscribe(dd.SetColor);
            var text = dd.GetComponentInChildren <Text>();

            text.color = TextColor;
            SetTextAutosize(text);
            return(dd.gameObject);
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var sliderUi = MakerAPI.GetMakerBase().CreateInputSliderUI(subCategoryList.gameObject, _settingName, _minValue, _maxValue, true, _defaultValue, SetValue);

            BufferedValueChanged.Subscribe(sliderUi.SetValue);
            var text = Traverse.Create(sliderUi).Field <Text>("title").Value;

            text.color = TextColor;
            SetTextAutosize(text);
            Traverse.Create(sliderUi).Field("textFormat").SetValue(TextFormat);
            return(sliderUi.gameObject);
        }
Ejemplo n.º 7
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var tr = Object.Instantiate(TextboxCopy, subCategoryList, false);

            tr.name = "sldTextbox";

            var textMesh = tr.Find("textShape").GetComponent <TextMeshProUGUI>();

            textMesh.text  = _settingName;
            textMesh.color = TextColor;

            var inputField = tr.Find("InputField").GetComponent <TMP_InputField>();

            inputField.contentType    = (TMP_InputField.ContentType)ContentType;
            inputField.characterLimit = CharacterLimit;
            switch (ContentType)
            {
            case InputField.ContentType.Autocorrected:
                inputField.inputType = TMP_InputField.InputType.AutoCorrect;
                break;

            case InputField.ContentType.Password:
                inputField.inputType = TMP_InputField.InputType.Password;
                break;

            default:
                inputField.inputType = TMP_InputField.InputType.Standard;
                break;
            }

            // Update either on every keystroke or only at end
            //inputField.onValueChanged.AddListener(SetValue);
            inputField.onEndEdit.AddListener(SetValue);

            if (MakerAPI.InsideMaker)
            {
                Singleton <ChaCustom.CustomBase> .Instance.lstTmpInputField.Add(inputField);
            }

#if KKS
            var resetButton = tr.Find("btnReset").GetComponent <Button>();
#else
            var resetButton = tr.Find("Button").GetComponent <Button>();
#endif
            resetButton.onClick.AddListener(() => SetValue(_defaultValue));

            BufferedValueChanged.Subscribe(text => inputField.text = text);

            var layout = tr.GetComponent <LayoutElement>();
            layout.flexibleWidth = 1;

            return(tr.gameObject);
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var dd = MakerAPI.GetMakerBase().CreateDropDownUI(subCategoryList.gameObject, SettingName, Options.Select(x => new Dropdown.OptionData(x)).ToList(), SetValue);

            BufferedValueChanged.Subscribe(dd.SetValue);
            var text = Traverse.Create(dd).Field <Text>("title").Value;

            text.color = TextColor;
            foreach (var txt in dd.GetComponentsInChildren <Text>(true))
            {
                SetTextAutosize(txt);
            }
            return(dd.gameObject);
        }
Ejemplo n.º 9
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var sw = MakerAPI.GetMakerBase().CreateSwitchUI(subCategoryList.gameObject, DisplayName, Value, SetValue);

            BufferedValueChanged.Subscribe(sw.SetValue);
            var text = sw.title;

            text.color = TextColor;
            foreach (var txt in sw.GetComponentsInChildren <Text>(true))
            {
                SetTextAutosize(txt);
            }
            return(sw.gameObject);
        }
Ejemplo n.º 10
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var tr = Object.Instantiate(ToggleCopy, subCategoryList, true);

            var tgl = tr.GetComponentInChildren <Toggle>();

            tgl.onValueChanged.AddListener(SetValue);

            BufferedValueChanged.Subscribe(b => tgl.isOn = b);

            var text = tr.GetComponentInChildren <TextMeshProUGUI>();

            text.text  = DisplayName;
            text.color = TextColor;

            return(tr.gameObject);
        }
Ejemplo n.º 11
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var copy = Object.Instantiate(_cachedToggle, subCategoryList);

            RemoveLocalisation(copy);

            var tgl = copy.GetComponent <Toggle>();

            tgl.onValueChanged.AddListener(SetValue);
            BufferedValueChanged.Subscribe(val => tgl.isOn = val);

            var txt = copy.GetComponentInChildren <Text>();

            txt.text  = Text;
            txt.color = TextColor;

            return(copy);
        }
Ejemplo n.º 12
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var tr = Object.Instantiate(GameObject.Find("CharaCustom/CustomControl/CanvasMain/SubMenu/SubMenuFace/Scroll View/Viewport/Content/Category/CategoryTop/SameSettingEyes"), subCategoryList, false);

            var tgl = tr.GetComponentInChildren <Toggle>();

            tgl.onValueChanged.ActuallyRemoveAllListeners();
            tgl.onValueChanged.AddListener(SetValue);

            BufferedValueChanged.Subscribe(b => tgl.isOn = b);

            var text = tr.GetComponentInChildren <Text>();

            text.text  = DisplayName;
            text.color = TextColor;
            SetTextAutosize(text);

            return(tr.gameObject);
        }
Ejemplo n.º 13
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var origTgl = GameObject.Find("CustomScene/CustomRoot/FrontUIGroup/CvsDraw/Top/tglBlink");
            var copy    = Object.Instantiate(origTgl, origTgl.transform.parent);

            var tgl = copy.GetComponentInChildren <Toggle>();

            tgl.graphic.raycastTarget = true;
            tgl.onValueChanged.RemoveAllListeners();

            tgl.onValueChanged.AddListener(SetValue);
            BufferedValueChanged.Subscribe(val => tgl.isOn = val);

            var txt = copy.GetComponentInChildren <TextMeshProUGUI>();

            txt.text  = Text;
            txt.color = TextColor;
            txt.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 145);

            return(copy);
        }
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform loadBoxTransform)
        {
            var copy = Object.Instantiate(loadBoxTransform.Find("Toggle Acce").gameObject, loadBoxTransform);

            copy.name = "Toggle " + Text + GuiApiNameAppendix;

            RemoveLocalisation(copy.gameObject);

            var tgl = copy.GetComponent <Toggle>();

            tgl.onValueChanged.AddListener(SetValue);
            BufferedValueChanged.Subscribe(b => tgl.isOn = b);
            tgl.image.raycastTarget   = true;
            tgl.graphic.raycastTarget = true;

            var txt = copy.GetComponentInChildren <Text>();

            txt.text = Text;

            copy.gameObject.SetActive(true);

            return(copy.gameObject);
        }
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var tr = Object.Instantiate(RadioCopy, subCategoryList, false);

            tr.name = "rb";

            var settingName = tr.Find("textTglTitle").GetComponent <TextMeshProUGUI>();

            settingName.text  = _settingName;
            settingName.color = TextColor;

            var sourceToggle = tr.Find("rb00");

            Buttons = _buttons.Select(
                (x, i) =>
            {
                if (i == 0)
                {
                    return(sourceToggle);
                }

                var newButton  = Object.Instantiate(sourceToggle, tr, false);
                newButton.name = "rb0" + i;

                return(newButton);
            })
                      .Select(x => x.GetComponent <Toggle>())
                      .ToList()
                      .AsReadOnly();

            // If there's less toggles than the number of toggles in a row, expand them to fill all space
            var singleToggleWidth = 280 / Mathf.Min(Buttons.Count, ColumnCount);
            var rowCount          = Mathf.CeilToInt((float)Buttons.Count / ColumnCount);

            tr.GetComponent <LayoutElement>().minHeight = 40 * rowCount;
            var buttonIndex = 0;

            for (var rowIndex = 0; rowIndex < rowCount; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < ColumnCount; columnIndex++)
                {
                    if (buttonIndex >= Buttons.Count)
                    {
                        break;
                    }
                    var toggle = Buttons[buttonIndex];

                    var rt = toggle.GetComponent <RectTransform>();
                    rt.offsetMin = new Vector2(singleToggleWidth * columnIndex - 280, 8);
                    rt.offsetMax = new Vector2(singleToggleWidth * (columnIndex + 1) - 280, -8);

                    rt.anchorMax = new Vector2(1, 1 - rowIndex / (float)rowCount);
                    rt.anchorMin = new Vector2(1, 1 - (rowIndex + 1) / (float)rowCount);

                    toggle.GetComponentInChildren <TextMeshProUGUI>().text = _buttons[buttonIndex];

                    var indexCopy = buttonIndex;
                    toggle.onValueChanged.AddListener(
                        a =>
                    {
                        if (a || indexCopy == Value)
                        {
                            SetValue(indexCopy);
                        }
                    });

                    buttonIndex++;
                }
            }

            KoikatuAPI.Assert(buttonIndex >= Buttons.Count, "Didn't loop over all radio buttons, only " + buttonIndex);

            BufferedValueChanged.Subscribe(
                i =>
            {
                for (var index = 0; index < Buttons.Count; index++)
                {
                    var tgl  = Buttons[index];
                    tgl.isOn = index == i;
                }
            });

            return(tr.gameObject);
        }
Ejemplo n.º 16
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var tr = Object.Instantiate(SliderCopy, subCategoryList, false);

            tr.name = "sldTemp";

            var textMesh = tr.Find("textShape").GetComponent <TextMeshProUGUI>();

            textMesh.text  = _settingName;
            textMesh.color = TextColor;

            var slider = tr.Find("Slider").GetComponent <Slider>();

            slider.minValue     = _minValue;
            slider.maxValue     = _maxValue;
            slider.wholeNumbers = WholeNumbers;
            slider.onValueChanged.AddListener(SetValue);
            slider.value = _defaultValue;
            slider.GetComponent <ObservableScrollTrigger>()
            .OnScrollAsObservable()
            .Subscribe(
                data =>
            {
                var scrollDelta = data.scrollDelta.y;
                var valueChange = Mathf.Pow(10, Mathf.Floor(Mathf.Log10(Mathf.Max(Mathf.Abs(slider.minValue), Mathf.Abs(slider.maxValue)) / 100)));

                if (scrollDelta < 0f)
                {
                    slider.value += valueChange;
                }
                else if (scrollDelta > 0f)
                {
                    slider.value -= valueChange;
                }
            });

            var inputField = tr.Find("InputField").GetComponent <TMP_InputField>();

            if (MakerAPI.InsideMaker)
            {
                Singleton <ChaCustom.CustomBase> .Instance.lstTmpInputField.Add(inputField);
            }

            InputField(_defaultValue, inputField);

            inputField.onEndEdit.AddListener(
                txt =>
            {
                try
                {
                    var result   = StringToValue?.Invoke(txt) ?? float.Parse(txt) / 100f;
                    slider.value = Mathf.Clamp(result, slider.minValue, slider.maxValue);
                }
                catch
                {
                    // Ignore parsing errors, lets user keep typing
                }
            });

            slider.onValueChanged.AddListener(
                f =>
            {
                InputField(f, inputField);
            });

#if KKS
            var resetButton = tr.Find("btnReset").GetComponent <Button>();
#else
            var resetButton = tr.Find("Button").GetComponent <Button>();
#endif
            resetButton.onClick.AddListener(() => slider.value = _defaultValue);

            BufferedValueChanged.Subscribe(f => slider.value = f);

            return(tr.gameObject);
        }
Ejemplo n.º 17
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var tr = Object.Instantiate(RadioCopy, subCategoryList, false);

            tr.name = "rb";

            var settingName = tr.Find("textTglTitle").GetComponent <TextMeshProUGUI>();

            settingName.text  = _settingName;
            settingName.color = TextColor;

            var sourceToggle = tr.Find("rb00");

            Buttons = _buttons.Select(
                (x, i) =>
            {
                if (i == 0)
                {
                    return(sourceToggle);
                }

                var newButton  = Object.Instantiate(sourceToggle, tr, false);
                newButton.name = "rb0" + i;

                return(newButton);
            })
                      .Select(x => x.GetComponent <Toggle>())
                      .ToList()
                      .AsReadOnly();

            var singleToggleWidth = 280 / Buttons.Count;

            for (var index = 0; index < Buttons.Count; index++)
            {
                var toggle = Buttons[index];

                var rt = toggle.GetComponent <RectTransform>();
                rt.offsetMin = new Vector2(singleToggleWidth * index - 280, 8);
                rt.offsetMax = new Vector2(singleToggleWidth * (index + 1) - 280, -8);

                toggle.GetComponentInChildren <TextMeshProUGUI>().text = _buttons[index];

                var indexCopy = index;
                toggle.onValueChanged.AddListener(
                    a =>
                {
                    if (a || indexCopy == Value)
                    {
                        SetValue(indexCopy);
                    }
                });
            }

            BufferedValueChanged.Subscribe(
                i =>
            {
                for (var index = 0; index < Buttons.Count; index++)
                {
                    var tgl  = Buttons[index];
                    tgl.isOn = index == i;
                }
            });

            return(tr.gameObject);
        }
Ejemplo n.º 18
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var tr = Object.Instantiate(SliderCopy, subCategoryList, false);

            tr.name = "SliderSet";

            var sliderSet = tr.GetComponent <CustomSliderSet>();

            sliderSet.onChange          = null;
            sliderSet.onPointerUp       = null;
            sliderSet.onSetDefaultValue = null;
            GameObject.Destroy(sliderSet);

            sliderSet.title.text  = _settingName;
            sliderSet.title.color = TextColor;
            SetTextAutosize(sliderSet.title);

            var slider = sliderSet.slider;

            slider.minValue = _minValue;
            slider.maxValue = _maxValue;
            slider.onValueChanged.ActuallyRemoveAllListeners();
            slider.onValueChanged.AddListener(SetValue);

            slider.GetComponent <ObservableScrollTrigger>()
            .OnScrollAsObservable()
            .Subscribe(
                data =>
            {
                var scrollDelta = data.scrollDelta.y;
                var valueChange = Mathf.Pow(10, Mathf.Floor(Mathf.Log10(Mathf.Max(Mathf.Abs(slider.minValue), Mathf.Abs(slider.maxValue)) / 100)));

                if (scrollDelta < 0f)
                {
                    slider.value += valueChange;
                }
                else if (scrollDelta > 0f)
                {
                    slider.value -= valueChange;
                }
            });

            var inputField = sliderSet.input;

            inputField.onEndEdit.AddListener(
                txt =>
            {
                try
                {
                    var result   = StringToValue?.Invoke(txt) ?? float.Parse(txt) / 100f;
                    slider.value = Mathf.Clamp(result, slider.minValue, slider.maxValue);
                }
                catch
                {
                    // Ignore parsing errors, lets user keep typing
                }
            });

            slider.onValueChanged.AddListener(
                f =>
            {
                if (ValueToString != null)
                {
                    inputField.text = ValueToString(f);
                }
                else
                {
                    inputField.text = Mathf.RoundToInt(f * 100).ToString();
                }
            });


            var resetButton = sliderSet.button;

            resetButton.onClick.ActuallyRemoveAllListeners();
            resetButton.onClick.AddListener(() => slider.value = _defaultValue);

            BufferedValueChanged.Subscribe(f => slider.value = f);

            return(tr.gameObject);
        }
Ejemplo n.º 19
0
        /// <inheritdoc />
        protected override GameObject OnCreateControl(Transform subCategoryList)
        {
            var selGo = Object.Instantiate(GameObject.Find("SettingWindow/WinBody/B_Nip/SelectMenu"), subCategoryList);

            selGo.name = "rb";

            var       toggleGroup  = selGo.GetComponent <ToggleGroup>();
            Transform singleButton = null;

            foreach (var c in selGo.transform.Children())
            {
                var singleToggle = c.GetComponent <UI_ToggleEx>();
                toggleGroup.UnregisterToggle(singleToggle);
                if (c.name == "tgl01")
                {
                    singleToggle.onValueChanged.ActuallyRemoveAllListeners();
                    singleButton = c;
                }
                else
                {
                    Object.DestroyImmediate(c.gameObject);
                }
            }

            var txtGo = Object.Instantiate(GameObject.Find("SettingWindow/WinBody/B_Nip/Setting/Setting02/Scroll View/Viewport/Content/ColorSet/Text"), selGo.transform);

            txtGo.transform.SetAsFirstSibling();
            const int textWidth = 110;

            txtGo.AddComponent <LayoutElement>().minWidth = textWidth;
            var txtCmp = txtGo.GetComponent <Text>();

            txtCmp.text  = _settingName;
            txtCmp.color = TextColor;
            SetTextAutosize(txtCmp);

            RemoveLocalisation(selGo);

            var newButtons = new List <Toggle>();

            for (int i = 0; i < _buttons.Length; i++)
            {
                var toggleId = i;

                Transform newBtn;
                if (toggleId <= 0)
                {
                    newBtn = singleButton ?? throw new ArgumentNullException(nameof(singleButton));
                }
                else
                {
                    newBtn      = Object.Instantiate(singleButton, selGo.transform);
                    newBtn.name = "tgl0" + toggleId;
                }

                var newTglText = newBtn.GetComponentInChildren <Text>();
                newTglText.text = _buttons[i];
                SetTextAutosize(newTglText);

                var newTgl = newBtn.GetComponent <UI_ToggleEx>();
                newTgl.group = toggleGroup;

                newTgl.onValueChanged.AddListener(
                    val =>
                {
                    if (val)
                    {
                        SetValue(toggleId);
                    }
                });

                newButtons.Add(newTgl);
            }

            Buttons = newButtons.AsReadOnly();


            var singleToggleWidth = (selGo.GetComponent <RectTransform>().sizeDelta.x - textWidth - 10) / Buttons.Count;

            foreach (var button in Buttons)
            {
                button.GetComponent <LayoutElement>().minWidth = singleToggleWidth;
            }

            BufferedValueChanged.Subscribe(
                i =>
            {
                for (var index = 0; index < Buttons.Count; index++)
                {
                    var tgl  = Buttons[index];
                    tgl.isOn = index == i;
                }
            });

            return(selGo.gameObject);
        }