Exemple #1
0
                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);
                }
Exemple #2
0
                public ModOption create(Config.Field cfgField)
                {
                    if (cfgField.type != typeof(int) || cfgField.getAttr <ButtonAttribute>() == null)                    // it's good enough for now
                    {
                        return(null);
                    }

                    return(new ButtonOption(cfgField, cfgField.getAttr <FieldAttribute>()?.label));
                }
Exemple #3
0
                public ModOption create(Config.Field cfgField)
                {
                    if (cfgField.type != typeof(bool))
                    {
                        return(null);
                    }

                    return(new ToggleOption(cfgField, cfgField.getAttr <FieldAttribute>()?.label));
                }
Exemple #4
0
                    public void setConfigField(Config.Field cfgField)
                    {
                        var range = cfgField.getAttr <Config.Field.RangeAttribute>();

                        Debug.assert(range != null);

                        min = range.min;
                        max = range.max;
                    }
Exemple #5
0
                public ModOption create(Config.Field cfgField)
                {
                    if (cfgField.type != typeof(KeyCode))
                    {
                        return(null);
                    }

                    return(new KeyBindOption(cfgField, cfgField.getAttr <FieldAttribute>()?.label));
                }
                public ModOption create(Config.Field cfgField)
                {
                    if (cfgField.type.IsEnum && cfgField.type != typeof(UnityEngine.KeyCode))                     // add choice option for enum
                    {
                        var names  = Enum.GetNames(cfgField.type).Select(name => name.Replace('_', ' ')).ToArray();
                        var values = Enum.GetValues(cfgField.type).OfType <object>().ToArray();

                        return(create(cfgField, cfgField.getAttr <FieldAttribute>()?.label, names, values));
                    }

                    if (cfgField.type == typeof(float) || cfgField.type == typeof(int))                     // creating ChoiceOption if we also have choice attribute
                    {
                        if (cfgField.getAttr <ChoiceAttribute>() is ChoiceAttribute choice && choice.choices.Length > 0)
                        {
                            return(create(cfgField, cfgField.getAttr <FieldAttribute>()?.label, choice.choices, choice.values));
                        }
                    }

                    return(null);
                }