コード例 #1
0
        public static void CheckIsValid(ISettingsPropertyDefinition prop, object settings)
        {
            // TODO:
            if (prop.PropertyReference is PropertyRef propertyRef)
            {
                if (!propertyRef.PropertyInfo.CanRead)
                {
                    throw new Exception($"Property {propertyRef.PropertyInfo.Name} in {settings.GetType().FullName} must have a getter.");
                }
                if (prop.SettingType != SettingType.Dropdown && !propertyRef.PropertyInfo.CanWrite)
                {
                    throw new Exception($"Property {propertyRef.PropertyInfo.Name} in {settings.GetType().FullName} must have a setter.");
                }

                if (prop.SettingType == SettingType.Float || prop.SettingType == SettingType.Int)
                {
                    if (prop.MinValue == prop.MaxValue)
                    {
                        throw new Exception($"Property {propertyRef.PropertyInfo.Name} in {settings.GetType().FullName} is a numeric type but the MinValue and MaxValue are the same.");
                    }
                }

                if (prop.SettingType != SettingType.Bool)
                {
                    if (prop.IsMainToggle)
                    {
                        throw new Exception($"Property {propertyRef.PropertyInfo.Name} in {settings.GetType().FullName} is marked as the main toggle for the group but is a numeric type. The main toggle must be a boolean type.");
                    }
                }
            }
        }
コード例 #2
0
        public static void OverrideValues(UndoRedoStack urs, ISettingsPropertyDefinition current, ISettingsPropertyDefinition @new)
        {
            if (SettingsUtils.Equals(current, @new))
            {
                return;
            }

            switch (current.SettingType)
            {
            case SettingType.Bool:
                urs.Do(new SetValueTypeAction <bool>(current.PropertyReference, (bool)@new.PropertyReference.Value));
                break;

            case SettingType.Int:
                urs.Do(new SetValueTypeAction <int>(current.PropertyReference, (int)@new.PropertyReference.Value));
                break;

            case SettingType.Float:
                urs.Do(new SetValueTypeAction <float>(current.PropertyReference, (float)@new.PropertyReference.Value));
                break;

            case SettingType.String:
                urs.Do(new SetStringAction(current.PropertyReference, (string)@new.PropertyReference.Value));
                break;

            case SettingType.Dropdown:
                urs.Do(new SetDropdownIndexAction(current.PropertyReference, SettingsUtils.GetSelector(@new.PropertyReference.Value)));
                break;
            }
        }
コード例 #3
0
        public static void OverrideValues(UndoRedoStack urs, ISettingsPropertyDefinition current, ISettingsPropertyDefinition @new)
        {
            if (SettingsUtils.Equals(current, @new))
            {
                return;
            }

            switch (current.SettingType)
            {
            case SettingType.Bool when @new.PropertyReference.Value is bool val:
                urs.Do(new SetValueTypeAction <bool>(current.PropertyReference, val));
                break;

            case SettingType.Int when @new.PropertyReference.Value is int val:
                urs.Do(new SetValueTypeAction <int>(current.PropertyReference, val));
                break;

            case SettingType.Float when @new.PropertyReference.Value is float val:
                urs.Do(new SetValueTypeAction <float>(current.PropertyReference, val));
                break;

            case SettingType.String when @new.PropertyReference.Value is string val:
                urs.Do(new SetStringAction(current.PropertyReference, val));
                break;

            case SettingType.Dropdown when @new.PropertyReference.Value is { } val:
                urs.Do(new SetSelectedIndexAction(current.PropertyReference, new SelectedIndexWrapper(val)));
                break;
            }
        }
コード例 #4
0
        public SettingsPropertyVM(ISettingsPropertyDefinition definition, SettingsVM settingsVM)
        {
            SettingsVM = settingsVM;
            SettingPropertyDefinition = definition;
            ValueFormatProvider       = SettingPropertyDefinition.CustomFormatter is not null
                ? Activator.CreateInstance(SettingPropertyDefinition.CustomFormatter) as IFormatProvider
                : null;

            // Moved to constructor
            IsInt              = SettingType == SettingType.Int;
            IsFloat            = SettingType == SettingType.Float;
            IsBool             = SettingType == SettingType.Bool;
            IsString           = SettingType == SettingType.String;
            IsDropdownDefault  = SettingType == SettingType.Dropdown && SettingsUtils.IsForTextDropdown(PropertyReference.Value);
            IsDropdownCheckbox = SettingType == SettingType.Dropdown && SettingsUtils.IsForCheckboxDropdown(PropertyReference.Value);
            IsDropdown         = IsDropdownDefault || IsDropdownCheckbox;
            IsButton           = SettingType == SettingType.Button;
            IsNotNumeric       = !(IsInt || IsFloat);
            NumericValueToggle = IsInt || IsFloat;
            // Moved to constructor

            PropertyReference.PropertyChanged += PropertyReference_OnPropertyChanged;

            if (IsDropdown)
            {
                DropdownValue.PropertyChanged          += DropdownValue_PropertyChanged;
                DropdownValue.PropertyChangedWithValue += DropdownValue_PropertyChangedWithValue;
            }

            RefreshValues();

            if (MCMUISubModule.ResetValueToDefault is { } key)
            {
                key.OnReleasedEvent += ResetValueToDefaultOnReleasedEvent;
            }
        }
 public void Add(ISettingsPropertyDefinition settingProp)
 {
     settingProperties.Add(settingProp);
 }