Beispiel #1
0
        public ViewVariablesPropertyControl(IViewVariablesManagerInternal viewVars, IResourceCache resourceCache)
        {
            _viewVariablesManager = viewVars;
            _resourceCache        = resourceCache;

            PerformLayout();
        }
        public ViewVariablesPropertyControl(IViewVariablesManagerInternal viewVars, IRobustSerializer robustSerializer)
        {
            MouseFilter = MouseFilterMode.Pass;

            _viewVariablesManager = viewVars;
            _robustSerializer     = robustSerializer;

            MouseFilter = MouseFilterMode.Pass;
            ToolTip     = "Click to expand";
            MinHeight   = 25;

            VBox = new BoxContainer
            {
                Orientation        = LayoutOrientation.Vertical,
                SeparationOverride = 0
            };
            AddChild(VBox);

            TopContainer = new BoxContainer
            {
                Orientation    = LayoutOrientation.Horizontal,
                VerticalExpand = true
            };
            VBox.AddChild(TopContainer);

            BottomContainer = new BoxContainer
            {
                Orientation = LayoutOrientation.Horizontal,
                Visible     = false
            };
            VBox.AddChild(BottomContainer);

            //var smallFont = new VectorFont(_resourceCache.GetResource<FontResource>("/Fonts/CALIBRI.TTF"), 10);

            _bottomLabel = new Label
            {
                //    FontOverride = smallFont,
                FontColorOverride = Color.DarkGray
            };
            BottomContainer.AddChild(_bottomLabel);

            NameLabel = new Label();
            TopContainer.AddChild(NameLabel);
        }
        public ViewVariablesPropertyControl(IViewVariablesManagerInternal viewVars, IRobustSerializer robustSerializer)
        {
            MouseFilter = MouseFilterMode.Pass;

            _viewVariablesManager = viewVars;
            _robustSerializer     = robustSerializer;

            MouseFilter       = MouseFilterMode.Pass;
            ToolTip           = "Click to expand";
            CustomMinimumSize = new Vector2(0, 25);

            VBox = new VBoxContainer {
                SeparationOverride = 0
            };
            AddChild(VBox);

            TopContainer = new HBoxContainer {
                SizeFlagsVertical = SizeFlags.FillExpand
            };
            VBox.AddChild(TopContainer);

            BottomContainer = new HBoxContainer
            {
                Visible = false
            };
            VBox.AddChild(BottomContainer);

            //var smallFont = new VectorFont(_resourceCache.GetResource<FontResource>("/Fonts/CALIBRI.TTF"), 10);

            _bottomLabel = new Label
            {
                //    FontOverride = smallFont,
                FontColorOverride = Color.DarkGray
            };
            BottomContainer.AddChild(_bottomLabel);

            NameLabel = new Label();
            TopContainer.AddChild(NameLabel);
        }
        protected internal static IEnumerable <IGrouping <Type, Control> > LocalPropertyList(object obj, IViewVariablesManagerInternal vvm,
                                                                                             IRobustSerializer robustSerializer)
        {
            var styleOther = false;
            var type       = obj.GetType();

            var members = new List <(MemberInfo, VVAccess, object?value, Action <object?, bool> onValueChanged, Type)>();

            foreach (var fieldInfo in type.GetAllFields())
            {
                if (!ViewVariablesUtility.TryGetViewVariablesAccess(fieldInfo, out var access))
                {
                    continue;
                }

                members.Add((fieldInfo, (VVAccess)access, fieldInfo.GetValue(obj), (v, _) => fieldInfo.SetValue(obj, v),
                             fieldInfo.FieldType));
            }

            foreach (var propertyInfo in type.GetAllProperties())
            {
                if (!ViewVariablesUtility.TryGetViewVariablesAccess(propertyInfo, out var access))
                {
                    continue;
                }

                if (!propertyInfo.IsBasePropertyDefinition())
                {
                    continue;
                }

                members.Add((propertyInfo, (VVAccess)access, propertyInfo.GetValue(obj),
                             (v, _) => propertyInfo.GetSetMethod(true) !.Invoke(obj, new[] { v }), propertyInfo.PropertyType));
            }

            var groupedSorted = members
                                .OrderBy(p => p.Item1.Name)
                                .GroupBy(p => p.Item1.DeclaringType !, tuple =>
            {
                var(memberInfo, access, value, onValueChanged, memberType) = tuple;
                var data = new ViewVariablesBlobMembers.MemberData
                {
                    Editable   = access == VVAccess.ReadWrite,
                    Name       = memberInfo.Name,
                    Type       = memberType.AssemblyQualifiedName,
                    TypePretty = TypeAbbreviation.Abbreviate(memberType),
                    Value      = value
                };

                var propertyEdit = new ViewVariablesPropertyControl(vvm, robustSerializer);
                propertyEdit.SetStyle(styleOther = !styleOther);
                var editor             = propertyEdit.SetProperty(data);
                editor.OnValueChanged += onValueChanged;
                return(propertyEdit);
            })
                                .OrderByDescending(p => p.Key, TypeHelpers.TypeInheritanceComparer);

            return(groupedSorted);
        }
 protected ViewVariablesInstance(IViewVariablesManagerInternal vvm, IRobustSerializer robustSerializer)
 {
     ViewVariablesManager = vvm;
     _robustSerializer    = robustSerializer;
 }
 public ViewVariablesInstanceEntity(IViewVariablesManagerInternal vvm, IEntityManager entityManager, IRobustSerializer robustSerializer) : base(vvm, robustSerializer)
 {
     _entityManager = entityManager;
 }
Beispiel #7
0
 public ViewVariablesTraitMembers(IViewVariablesManagerInternal vvm, IResourceCache resourceCache)
 {
     _resourceCache = resourceCache;
     _vvm           = vvm;
 }
 public ViewVariablesInstanceEntity(IViewVariablesManagerInternal vvm, IResourceCache resCache, IEntityManager entityManager) : base(vvm, resCache)
 {
     _entityManager = entityManager;
 }
        protected internal static IEnumerable <Control> LocalPropertyList(object obj, IViewVariablesManagerInternal vvm)
        {
            var styleOther = false;
            var type       = obj.GetType();

            var members = new List <(MemberInfo, VVAccess, object value, Action <object> onValueChanged, Type)>();

            foreach (var fieldInfo in type.GetAllFields())
            {
                var attr = fieldInfo.GetCustomAttribute <ViewVariablesAttribute>();
                if (attr == null)
                {
                    continue;
                }

                members.Add((fieldInfo, attr.Access, fieldInfo.GetValue(obj), v => fieldInfo.SetValue(obj, v),
                             fieldInfo.FieldType));
            }

            foreach (var propertyInfo in type.GetAllProperties())
            {
                var attr = propertyInfo.GetCustomAttribute <ViewVariablesAttribute>();
                if (attr == null)
                {
                    continue;
                }

                members.Add((propertyInfo, attr.Access, propertyInfo.GetValue(obj),
                             v => propertyInfo.GetSetMethod(true).Invoke(obj, new[] { v }), propertyInfo.PropertyType));
            }

            members.Sort((a, b) => string.Compare(a.Item1.Name, b.Item1.Name, StringComparison.Ordinal));

            foreach (var(memberInfo, access, value, onValueChanged, memberType) in members)
            {
                var data = new ViewVariablesBlobMembers.MemberData
                {
                    Editable   = access == VVAccess.ReadWrite,
                    Name       = memberInfo.Name,
                    Type       = memberType.AssemblyQualifiedName,
                    TypePretty = memberType.ToString(),
                    Value      = value
                };

                var propertyEdit = new ViewVariablesPropertyControl();
                propertyEdit.SetStyle(styleOther = !styleOther);
                var editor = propertyEdit.SetProperty(data);
                editor.OnValueChanged += onValueChanged;
                // TODO: should this maybe not be hardcoded?
                if (editor is ViewVariablesPropertyEditorReference refEditor)
                {
                    refEditor.OnPressed += () => vvm.OpenVV(data.Value);
                }

                yield return(propertyEdit);
            }
        }
 protected ViewVariablesInstance(IViewVariablesManagerInternal vvm)
 {
     ViewVariablesManager = vvm;
 }
 public ViewVariablesTraitMembers(IViewVariablesManagerInternal vvm, IRobustSerializer robustSerializer)
 {
     _robustSerializer = robustSerializer;
     _vvm = vvm;
 }
Beispiel #12
0
 protected ViewVariablesInstance(IViewVariablesManagerInternal vvm, IResourceCache resCache)
 {
     ViewVariablesManager = vvm;
     _resourceCache       = resCache;
 }
Beispiel #13
0
 public ViewVariablesInstanceObject(IViewVariablesManagerInternal vvm) : base(vvm)
 {
 }
 public ViewVariablesInstanceObject(IViewVariablesManagerInternal vvm, IResourceCache resCache)
     : base(vvm, resCache)
 {
 }
 public ViewVariablesInstanceEntity(IViewVariablesManagerInternal vvm) : base(vvm)
 {
 }
        protected internal static IEnumerable <Control> LocalPropertyList(object obj, IViewVariablesManagerInternal vvm,
                                                                          IResourceCache resCache)
        {
            var styleOther = false;
            var type       = obj.GetType();

            var members = new List <(MemberInfo, VVAccess, object?value, Action <object> onValueChanged, Type)>();

            foreach (var fieldInfo in type.GetAllFields())
            {
                var attr = fieldInfo.GetCustomAttribute <ViewVariablesAttribute>();
                if (attr == null)
                {
                    continue;
                }

                members.Add((fieldInfo, attr.Access, fieldInfo.GetValue(obj), v => fieldInfo.SetValue(obj, v),
                             fieldInfo.FieldType));
            }

            foreach (var propertyInfo in type.GetAllProperties())
            {
                var attr = propertyInfo.GetCustomAttribute <ViewVariablesAttribute>();
                if (attr == null)
                {
                    continue;
                }

                if (!propertyInfo.IsBasePropertyDefinition())
                {
                    continue;
                }

                members.Add((propertyInfo, attr.Access, propertyInfo.GetValue(obj),
                             v => propertyInfo.GetSetMethod(true) !.Invoke(obj, new[] { v }), propertyInfo.PropertyType));
            }

            members.Sort((a, b) => string.Compare(a.Item1.Name, b.Item1.Name, StringComparison.Ordinal));

            foreach (var(memberInfo, access, value, onValueChanged, memberType) in members)
            {
                var data = new ViewVariablesBlobMembers.MemberData
                {
                    Editable   = access == VVAccess.ReadWrite,
                    Name       = memberInfo.Name,
                    Type       = memberType.AssemblyQualifiedName,
                    TypePretty = TypeAbbreviation.Abbreviate(memberType),
                    Value      = value
                };

                var propertyEdit = new ViewVariablesPropertyControl(vvm, resCache);
                propertyEdit.SetStyle(styleOther = !styleOther);
                var editor = propertyEdit.SetProperty(data);
                editor.OnValueChanged += onValueChanged;

                yield return(propertyEdit);
            }
        }