public ModOption create(Config.Field cfgField) { // creating SliderOption if we have range for the field (from RangeAttribute or SliderAttribute) if (cfgField.type != typeof(float) && cfgField.type != typeof(int)) { return(null); } var rangeAttr = cfgField.getAttr <Config.Field.RangeAttribute>(); var sliderAttr = cfgField.getAttr <SliderAttribute>(); // slider range can't be wider than field range float min = Math.Max(rangeAttr?.min ?? float.MinValue, sliderAttr?.minValue ?? float.MinValue); float max = Math.Min(rangeAttr?.max ?? float.MaxValue, sliderAttr?.maxValue ?? float.MaxValue); if (min == float.MinValue || max == float.MaxValue) // we need to have both bounds for creating slider { return(null); } // in case of custom value type we add valueFormat in that component instead of SliderOption string valueFormat = sliderAttr?.customValueType == null? sliderAttr?.valueFormat: null; string label = cfgField.getAttr <FieldAttribute>()?.label; ModOption option = new SliderOption(cfgField, label, min, max, sliderAttr?.defaultValue, valueFormat); if (sliderAttr?.customValueType != null) { option.addHandler(new Components.SliderValue.Add(sliderAttr.customValueType, sliderAttr.valueFormat)); } return(option); }
void SetupSlider(SliderOption slider, string name, float?value) { if (slider.GetOption() == name && value != null) { float newX = (float)(value * (slider.GetRadius() * 2)) - slider.GetRadius() + slider.GetCenter(); slider.GetComponent <RectTransform>().position = new Vector3(newX, slider.GetComponent <RectTransform>().position.y); } }
public void HtmlAttribute_SetsCssClassAttribute() { actual = string.Empty; returnHtml = string.Empty; SliderOption target = new SliderOption(); string expected = target.CssClass = "Sample"; returnHtml = Utility.ControlOptionHtmlBuilder <SliderOption>(target, _startTag); actual = Utility.GetAttribute(returnHtml, "class", _startTag); Assert.AreEqual(expected, actual); }
public void HtmlAttribute_SetsMinimumAttribute() { actual = string.Empty; returnHtml = string.Empty; SliderOption target = new SliderOption(); target.Minimum = 50; string expected = "{\"min\":50}"; returnHtml = Utility.ControlOptionHtmlBuilder <SliderOption>(target, _startTag); actual = Utility.GetAttribute(returnHtml, "data-control-options", _startTag); Assert.AreEqual(expected, actual); }
public void HtmlAttribute_SetsDisabledAttribute() { actual = string.Empty; returnHtml = string.Empty; SliderOption target = new SliderOption(); target.Disabled = true; string expected = "{\"disabled\":true}"; returnHtml = Utility.ControlOptionHtmlBuilder <SliderOption>(target, _startTag); actual = Utility.GetAttribute(returnHtml, "data-control-options", _startTag); Assert.AreEqual(expected, actual); }
public void HtmlAttribute_SetsCustomHtmlAttribute() { actual = string.Empty; returnHtml = string.Empty; SliderOption target = new SliderOption(); target.HtmlAttributeList = new RouteValueDictionary(new { CustomAttribute = "Sample" }); string expected = "Sample"; returnHtml = Utility.ControlOptionHtmlBuilder <SliderOption>(target, _startTag); actual = Utility.GetAttribute(returnHtml, "CustomAttribute", _startTag); Assert.AreEqual(expected, actual); }
public void HtmlAttribute_SetsOrientationAttribute() { actual = string.Empty; returnHtml = string.Empty; SliderOption target = new SliderOption(); target.Orientation = Orientation.Horizontal; string expected = "{\"orientation\":\"horizontal\"}"; returnHtml = Utility.ControlOptionHtmlBuilder <SliderOption>(target, _startTag); actual = Utility.GetAttribute(returnHtml, "data-control-options", _startTag); Assert.AreEqual(expected, actual); }
void GetSliderValue(SliderOption slider) { switch (slider.GetOption()) { case "Master": Messenger.MS.SetMasterVolume(slider.GetValue()); AudioListener.volume = (float)Messenger.MS.GetMasterVolume(); break; case "Music": Messenger.MS.SetMusicVolume(slider.GetValue()); AudioManager.AM.ChangeVolume(true, slider.GetValue()); break; case "Sound": Messenger.MS.SetSoundVolume(slider.GetValue()); AudioManager.AM.ChangeVolume(false, slider.GetValue()); break; } }
public SliderOptionUI(SliderOption option) : base(option.PropertyName, option.PropertyType, option.Owner, option.Min, option.Max) { }
public EmProperty <float> GetFloatProperty(SliderOption option) { return((EmProperty <float>) this[option.Id]); }
internal void LoadOptionListFromCategory(string modGuid, int categoryIndex, int headerCount) { UnloadExistingOptionButtons(); _panel.CategoryHeader.transform.Find("Scroll View").Find("Scrollbar Horizontal").gameObject.GetComponent <CustomScrollbar>().value = (1f / ((float)headerCount) - 1) * ((float)categoryIndex); _panel.ModOptionsDescriptionPanel.GetComponentInChildren <HGTextMeshProUGUI>().SetText(""); Category category = ModSettingsManager.OptionCollection[modGuid][categoryIndex]; var verticalLayoutTransform = _panel.ModOptionsPanel.transform.Find("Scroll View").Find("Viewport").Find("VerticalLayout"); Selectable lastSelectable = null; _modSettings = new ModSetting[category.OptionCount]; for (int i = 0; i < category.OptionCount; i++) { var option = category[i]; GameObject button = option switch { CheckBoxOption checkBoxOption => option.CreateOptionGameObject(_checkBoxPrefab, verticalLayoutTransform), SliderOption sliderOption => option.CreateOptionGameObject(_sliderPrefab, verticalLayoutTransform), StepSliderOption stepSliderOption => option.CreateOptionGameObject(_stepSliderPrefab, verticalLayoutTransform), KeyBindOption keyBindOption => option.CreateOptionGameObject(_keyBindPrefab, verticalLayoutTransform), StringInputFieldOption inputFieldOption => option.CreateOptionGameObject(_inputFieldPrefab, verticalLayoutTransform), GenericButtonOption genericButton => option.CreateOptionGameObject(_genericButtonPrefab, verticalLayoutTransform), // DropDownOption dropDownOption => option.CreateOptionGameObject(option, _dropDownPrefab, verticalLayoutTransform), _ => throw new ArgumentOutOfRangeException(option.Name) }; _modSettings[i] = button.GetComponentInChildren <ModSetting>(); _modSettings[i].optionController = this; CanvasGroup canvasGroup = button.AddComponent <CanvasGroup>(); var buttonComponent = button.GetComponentInChildren <HGButton>(); if (buttonComponent) { button.GetComponentInChildren <HGButton>().hoverToken = option.GetDescriptionToken(); button.GetComponentInChildren <HGButton>().onSelect.AddListener(delegate { _panel.ModOptionsDescriptionPanel.GetComponentInChildren <HGTextMeshProUGUI>().SetText(option.Description); }); } var selectable = button.GetComponentInChildren <Selectable>(); if (selectable) { var selectableNavigation = selectable.navigation; selectableNavigation.mode = Navigation.Mode.Explicit; if (i == 0 || i > category.OptionCount) { // Todo if at top of list, select category. } else if (lastSelectable) { var lastSelectableNavigation = lastSelectable.navigation; lastSelectableNavigation.selectOnDown = selectable; lastSelectable.navigation = lastSelectableNavigation; selectableNavigation.selectOnUp = lastSelectable; } selectable.navigation = selectableNavigation; lastSelectable = selectable; } else { lastSelectable = null; } // if (!option.Visibility) // { // canvasGroup.alpha = 1; // canvasGroup.blocksRaycasts = false; // button.GetComponent<LayoutElement>().ignoreLayout = true; // continue; // } button.SetActive(true); } }
public static SliderPane AddConfig <T>(ref UIPanel page, string label, string tooltip, SliderOption <T> opts, int?labelPadding = null, int?indentPadding = null, Color32?color = null, string bullet = null) { var font = FontStore.Get(11); if (opts.onSwitched != null) // has switch { var cb = Helper.AddCheckBox( ref page, label: label, tooltip: tooltip, initialValue: opts.isEnabled, (c, isEnabled) => { opts.onSwitched.Invoke(c, isEnabled); }, font, indentPadding: indentPadding ); if (labelPadding.HasValue) { cb.height += labelPadding.Value; } else { cb.height += 1; } } else { Helper.AddLabel(ref page, label, tooltip, font, Helper.Padding(0, 0, 2, 0), color: color, bullet: bullet); } var pane = Helper.AddSliderPane <T>(ref page, opts, font); return(pane); }