// draws the input control for Enum settings
        private bool DrawHandleInputEnum(SettingHandle handle, Rect controlRect, HandleControlInfo info)
        {
            if (info.enumNames == null)
            {
                return(false);
            }
            var readableValue = (handle.EnumStringPrefix + info.inputValue).Translate();

            if (Widgets.ButtonText(controlRect, readableValue))
            {
                var floatOptions = new List <FloatMenuOption>();
                foreach (var valueName in info.enumNames)
                {
                    var name           = valueName;
                    var readableOption = (handle.EnumStringPrefix + name).Translate();
                    floatOptions.Add(new FloatMenuOption(readableOption, () => {
                        handle.StringValue       = info.inputValue = name;
                        info.validationScheduled = true;
                    }));
                }
                ModSettingsWidgets.OpenFloatMenu(floatOptions);
            }
            if (info.validationScheduled)
            {
                info.validationScheduled = false;
                return(true);
            }
            return(false);
        }
        // draws the input control for integer settings
        private bool DrawHandleInputSpinner(SettingHandle handle, Rect controlRect, HandleControlInfo info)
        {
            var buttonSize      = controlRect.height;
            var leftButtonRect  = new Rect(controlRect.x, controlRect.y, buttonSize, buttonSize);
            var rightButtonRect = new Rect(controlRect.x + controlRect.width - buttonSize, controlRect.y, buttonSize, buttonSize);
            var changed         = false;

            if (Widgets.ButtonText(leftButtonRect, "-"))
            {
                if (int.TryParse(info.inputValue, out var parsed))
                {
                    info.inputValue = (parsed - handle.SpinnerIncrement).ToString();
                }
                info.validationScheduled = true;
                changed = true;
            }
            if (Widgets.ButtonText(rightButtonRect, "+"))
            {
                if (int.TryParse(info.inputValue, out var parsed))
                {
                    info.inputValue = (parsed + handle.SpinnerIncrement).ToString();
                }
                info.validationScheduled = true;
                changed = true;
            }
            var textRect = new Rect(controlRect.x + buttonSize + 1, controlRect.y, controlRect.width - buttonSize * 2 - 2f, controlRect.height);

            if (DrawHandleInputText(handle, textRect, info))
            {
                changed = true;
            }
            return(changed);
        }
 private void ResetSetting(SettingHandle handle)
 {
     if (!handle.CanBeReset)
     {
         return;
     }
     handle.ResetToDefault();
     handleControlInfo[handle] = new HandleControlInfo(handle);
     settingsHaveChanged       = true;
 }
        // draws the input control for boolean settings
        private bool DrawHandleInputCheckbox(SettingHandle handle, Rect controlRect, HandleControlInfo info)
        {
            const float defaultCheckboxHeight = 24f;
            var         checkOn = bool.Parse(info.inputValue);

            Widgets.Checkbox(controlRect.x, controlRect.y + (controlRect.height - defaultCheckboxHeight) / 2, ref checkOn);
            if (checkOn != bool.Parse(info.inputValue))
            {
                handle.StringValue = info.inputValue = checkOn.ToString();
                return(true);
            }
            return(false);
        }
        // draws the input control for string settings
        private bool DrawHandleInputText(SettingHandle handle, Rect controlRect, HandleControlInfo info)
        {
            var evt = Event.current;

            GUI.SetNextControlName(info.controlName);
            info.inputValue = Widgets.TextField(controlRect, info.inputValue);
            var focused = GUI.GetNameOfFocusedControl() == info.controlName;

            if (focused)
            {
                info.validationScheduled = true;
                if (evt.type == EventType.KeyUp && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter))
                {
                    focused = false;
                }
            }
            var changed = false;

            if (info.validationScheduled && !focused)
            {
                try {
                    if (handle.Validator != null && !handle.Validator(info.inputValue))
                    {
                        info.badInput = true;
                    }
                    else
                    {
                        info.badInput      = false;
                        handle.StringValue = info.inputValue;
                        changed            = true;
                    }
                } catch (Exception e) {
                    HugsLibController.Logger.ReportException(e, currentlyDrawnEntry, false, "SettingsHandle.Validator");
                }
                info.validationScheduled = false;
            }
            if (info.badInput)
            {
                DrawBadTextValueOutline(controlRect);
            }
            return(changed);
        }
 private void ResetHandleControlInfo(SettingHandle handle)
 {
     handleControlInfo[handle] = new HandleControlInfo(handle);
 }
Ejemplo n.º 7
0
 private void ResetSetting(SettingHandle handle)
 {
     handle.ResetToDefault();
     handleControlInfo[handle] = new HandleControlInfo(handle);
     settingsHaveChanged       = true;
 }