Beispiel #1
0
 public void init()
 {
     //
     if (GetComponents <BoxCollider>() == null)
     {
         boundSource = BoundSource.meshes;
     }
     setPoints();
     setLines();
     setLineRenderers();
 }
        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)
            };
        }