示例#1
0
 /// <summary>
 /// Sets the editor limits from member <see cref="LimitAttribute"/>.
 /// </summary>
 /// <param name="limit">The limit.</param>
 public void SetLimits(LimitAttribute limit)
 {
     if (limit != null)
     {
         FloatValue.SetLimits(limit);
     }
 }
示例#2
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            var grid        = layout.CustomContainer <UniformGridPanel>();
            var gridControl = grid.CustomControl;

            gridControl.ClipChildren      = false;
            gridControl.Height            = TextBox.DefaultHeight * 4;
            gridControl.SlotsHorizontally = 4;
            gridControl.SlotsVertically   = 4;

            LimitAttribute limit = null;

            if (Values.Info != null)
            {
                var attributes = Values.Info.GetCustomAttributes(true);
                limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
            }

            for (int i = 0; i < 16; i++)
            {
                var elemnt = grid.FloatValue();
                elemnt.SetLimits(limit);
                elemnt.FloatValue.ValueChanged += OnValueChanged;
                elemnt.FloatValue.SlidingEnd   += ClearToken;
                Elements[i] = elemnt;
            }
        }
示例#3
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            var grid        = layout.CustomContainer <UniformGridPanel>();
            var gridControl = grid.CustomControl;

            gridControl.ClipChildren      = false;
            gridControl.Height            = TextBox.DefaultHeight;
            gridControl.SlotsHorizontally = 2;
            gridControl.SlotsVertically   = 1;

            LimitAttribute limit      = null;
            var            attributes = Values.GetAttributes();

            if (attributes != null)
            {
                limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
            }

            XElement = grid.FloatValue();
            XElement.SetLimits(limit);
            XElement.FloatValue.ValueChanged += OnValueChanged;
            XElement.FloatValue.SlidingEnd   += ClearToken;

            YElement = grid.FloatValue();
            YElement.SetLimits(limit);
            YElement.FloatValue.ValueChanged += OnValueChanged;
            YElement.FloatValue.SlidingEnd   += ClearToken;
        }
 /// <summary>
 /// Sets the editor limits from member <see cref="LimitAttribute"/>.
 /// </summary>
 /// <param name="limit">The limit.</param>
 public void SetLimits(LimitAttribute limit)
 {
     if (limit != null)
     {
         ValueBox.SetLimits(limit);
     }
 }
示例#5
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            var grid        = layout.CustomContainer <UniformGridPanel>();
            var gridControl = grid.CustomControl;

            gridControl.Height            = TextBox.DefaultHeight;
            gridControl.SlotsHorizontally = 4;
            gridControl.SlotsVertically   = 1;

            LimitAttribute limit = null;

            if (Values.Info != null)
            {
                var attributes = Values.Info.GetCustomAttributes(true);
                limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
            }

            xElement = grid.FloatValue();
            xElement.SetLimits(limit);
            xElement.FloatValue.ValueChanged += OnValueChanged;

            yElement = grid.FloatValue();
            yElement.SetLimits(limit);
            yElement.FloatValue.ValueChanged += OnValueChanged;

            zElement = grid.FloatValue();
            zElement.SetLimits(limit);
            zElement.FloatValue.ValueChanged += OnValueChanged;

            wElement = grid.FloatValue();
            wElement.SetLimits(limit);
            wElement.FloatValue.ValueChanged += OnValueChanged;
        }
示例#6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType != SerializedPropertyType.Integer)
            {
                Debug.LogWarning("LimitAttribute can only be applied on integer properties/fields");
                return;
            }

            LimitAttribute limiter = attribute as LimitAttribute;

            property.intValue = limiter.Limit(EditorGUI.IntField(position, property.name, property.intValue));
        }
示例#7
0
        private FloatValueElement CreateFloatEditor(LayoutElementsContainer layout, LimitAttribute limit, Color borderColor)
        {
            var element = layout.FloatValue();

            element.SetLimits(limit);
            element.FloatValue.ValueChanged += OnValueChanged;
            var back          = FlaxEngine.GUI.Style.Current.TextBoxBackground;
            var grayOutFactor = 0.6f;

            element.FloatValue.BorderColor         = Color.Lerp(borderColor, back, grayOutFactor);
            element.FloatValue.BorderSelectedColor = borderColor;
            return(element);
        }
示例#8
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            float trackBallSize = 80.0f;
            float margin        = 4.0f;

            // Panel
            var masterPanel        = layout.CustomContainer <GridPanel>();
            var masterPanelControl = masterPanel.CustomControl;

            masterPanelControl.ClipChildren = false;
            masterPanelControl.SlotPadding  = new Margin(0, 0, margin, margin);
            masterPanelControl.Height       = trackBallSize + margin + margin;
            masterPanelControl.ColumnFill   = new[]
            {
                -trackBallSize,
                1.0f
            };
            masterPanelControl.RowFill = new[] { 1.0f };

            // Trackball
            _trackball = masterPanel.Custom <ColorSelector>();
            _trackball.CustomControl.ColorChanged += OnColorWheelChanged;
            _trackball.CustomControl.SlidingEnd   += ClearToken;

            // Scale editor
            {
                var grid        = masterPanel.CustomContainer <UniformGridPanel>();
                var gridControl = grid.CustomControl;
                gridControl.SlotPadding       = new Margin(4, 2, 2, 2);
                gridControl.ClipChildren      = false;
                gridControl.SlotsHorizontally = 1;
                gridControl.SlotsVertically   = 4;

                LimitAttribute limit      = null;
                var            attributes = Values.GetAttributes();
                if (attributes != null)
                {
                    limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
                }

                _xElement = CreateFloatEditor(grid, limit, Color.Red);
                _yElement = CreateFloatEditor(grid, limit, Color.Green);
                _zElement = CreateFloatEditor(grid, limit, Color.Blue);
                _wElement = CreateFloatEditor(grid, limit, Color.White);
            }
        }
        public BindingMember(MemberInfo propertyInfo, object baseObject, BindingMember parent = null, bool lean = false)
        {
            BoundSources = new List <BoundSource>();

            _propertyInfo = propertyInfo as PropertyInfo;
            _baseObject   = baseObject;

            PropertyName = propertyInfo.Name;

            if (lean)
            {
                return;
            }

            _defaultValueAttribute      = GetAttribute <DefaultValueAttribute>(propertyInfo);
            _limitAttribute             = GetAttribute <LimitAttribute>(propertyInfo);
            _displayNameAttribute       = GetAttribute <DisplayNameAttribute>(propertyInfo);
            _descriptionAttribute       = GetAttribute <DescriptionAttribute>(propertyInfo);
            _uiControlAttribute         = GetAttribute <UIControlAttribute>(propertyInfo);
            _categoryAttribute          = GetAttribute <CategoryAttribute>(propertyInfo);
            _advancedAttribute          = GetAttribute <AdvancedSetting>(propertyInfo);
            _limitBindingAttribute      = GetAttribute <LimitBindingAttribute>(propertyInfo);
            _isGroupControllerAttribute = GetAttribute <IsGroupController>(propertyInfo);
            _groupAttribute             = GetAttribute <GroupAttribute>(propertyInfo);

            //Core.Logger.Verbose($"Created Binding Member for {propertyInfo.Name}");

            var notify = baseObject as INotifyPropertyChanged;

            if (notify != null)
            {
                //Core.Logger.Verbose($"Registering Property Changed for {baseObject.GetType().Name} ({propertyInfo.Name})");
                notify.PropertyChanged += NotifyOnPropertyChanged;
            }

            //_bindingAttribute = GetAttribute<BindingAttribute>(propertyInfo);

            _BindingAttributes = propertyInfo.GetCustomAttributes(typeof(BindingAttribute)).OfType <BindingAttribute>().ToList();

            if (_categoryAttribute == null && parent != null && parent.Category != null)
            {
                _categoryAttribute = new CategoryAttribute(parent.Category);
            }

            // The parent property of embedded TrinitySettings objects can define a category
            // When children do not have one explicitly set.
            if (_categoryAttribute == null && parent != null && parent.Category != null)
            {
                _categoryAttribute = new CategoryAttribute(parent.Category);
            }

            // GroupControllers notify other instances that a category has changed.
            // Applicable listners can then refresh their state in the UI.
            OnCategoryChanged += categoryId =>
            {
                if (categoryId == GroupId)
                {
                    OnPropertyChanged(nameof(IsEnabled));
                }
            };

            IsNoLabel = _uiControlAttribute != null && _uiControlAttribute.Options.HasFlag(UIControlOptions.NoLabel);

            //IsUseDescription = _uiControlAttribute != null && _uiControlAttribute.Options.HasFlag(UIControlOptions.UseDescription);

            IsInline = _uiControlAttribute != null && _uiControlAttribute.Options.HasFlag(UIControlOptions.Inline);

            if (_limitAttribute != null)
            {
                Range = new Range
                {
                    Min = _limitAttribute.Low,
                    Max = _limitAttribute.High
                };
            }

            _type = _baseObject.GetType();

            if (_limitBindingAttribute != null)
            {
                var lowSource  = _limitBindingAttribute.LowSource;
                var highSource = _limitBindingAttribute.HighSource;

                if (!BotMain.IsRunning)
                {
                    using (ZetaDia.Memory.AcquireFrame())
                    {
                        Range = new Range
                        {
                            Min                     = lowSource != null?GetMemberValue <double>(lowSource) : _limitBindingAttribute.Low,
                                                Max = highSource != null?GetMemberValue <double>(highSource) : _limitBindingAttribute.High
                        };
                    }
                }
                else
                {
                    Range = new Range
                    {
                        Min                     = lowSource != null?GetMemberValue <double>(lowSource) : _limitBindingAttribute.Low,
                                            Max = highSource != null?GetMemberValue <double>(highSource) : _limitBindingAttribute.High
                    };
                }
            }

            if (_BindingAttributes != null && _BindingAttributes.Any())
            {
                var attributes = _BindingAttributes.OrderBy(a => a.Order).ToList();
                foreach (var bindingAttr in attributes)
                {
                    var member = GetMember(bindingAttr);
                    var prop   = member as PropertyInfo;
                    if (prop == null)
                    {
                        continue;
                    }
                    var boundSource = new BoundSource
                    {
                        Member = new BindingMember(prop, baseObject, this),
                        Items  = GetBoundItems(prop, bindingAttr)
                    };
                    BoundSources.Add(boundSource);
                }
            }

            if (IsGroupController)
            {
                ChangeGroup(GroupId, Value);
            }

            Source = new BoundSource
            {
                Member = this,
                Items  = GetBoundItems(propertyInfo)
            };
        }
示例#10
0
        /// <summary> Возвращает необходимый свойству FrameworkElement </summary>
        private Control GetControl(PropertyInfo property)
        {
            Control Result = null;

            if (property.PropertyType == typeof(string))
            {
                LimitAttribute limitAttribute = property.GetAttribute <LimitAttribute>() as LimitAttribute;
                Result = new TextBox();
                if (limitAttribute != null)
                {
                    (Result as TextBox).MaxLength = limitAttribute.UpLimit;
                }
            }
            else if (property.PropertyType == typeof(int))
            {
                LimitAttribute limitAttribute = property.GetAttribute <LimitAttribute>() as LimitAttribute;
                Result = new IntegerUpDown();
                if (limitAttribute != null)
                {
                    (Result as IntegerUpDown).Minimum = limitAttribute.LowLimit;
                    (Result as IntegerUpDown).Maximum = limitAttribute.UpLimit;
                }
            }
            else if (property.PropertyType == typeof(bool))
            {
                Result = new CheckBox();
            }
            else if (property.PropertyType == typeof(double))
            {
                Result = new DoubleUpDown();
            }
            else if (property.PropertyType == typeof(id))
            {
                Result = new TextBox()
                {
                    IsEnabled = false
                };
            }
            else if (property.PropertyType == typeof(DateTime))
            {
                Result = new DatePicker();
            }
            else if (property.PropertyType.IsEnum)
            {
                Result = new ComboBox();
                (Result as ComboBox).SelectionChanged += (s, eventArgs) =>
                {
                    if (DataContext != null)
                    {
                        if ((s as ComboBox).SelectedIndex != -1)
                        {
                            property.SetValue(DataContext, new EnumToIntConverter().ConvertBack((s as ComboBox).SelectedIndex, property.PropertyType, null, null), null);
                        }
                    }
                    else
                    {
                        System.Windows.MessageBox.Show("Редактируемый объект не выбран!", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                };
                this.AddItems(Result as ComboBox, property.PropertyType);
            }
            else if (property.PropertyType == typeof(bool?))
            {
                Result = new ToggleButton()
                {
                    IsThreeState = true
                };
                Binding binding = new Binding(property.Name);
                binding.Mode      = BindingMode.OneWay;
                binding.Converter = new NullableBoolToStringConverter();
                BindingOperations.SetBinding(Result, ToggleButton.ContentProperty, binding);
            }
            else if (property.PropertyType.Is <DBObject>())
            {
                Result = new DBObjectSelector(property);
            }

            if (property.PropertyType != typeof(id))
            {
                EditingPropertyAttribute editingPropertyAttribute = property.GetAttribute <EditingPropertyAttribute>();
                Result.IsEnabled = !editingPropertyAttribute.IsReadOnly;
            }

            Result.MinHeight         = 24;
            Result.VerticalAlignment = System.Windows.VerticalAlignment.Center;

            return(Result);
        }