Exemplo n.º 1
0
 public AlignmentPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
 {
     EditorContainer.AddNode(new Widget {
         Layout = new HBoxLayout {
             DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4
         },
         Nodes =
         {
             (selectorH = editorParams.DropDownListFactory()),
             (selectorV = editorParams.DropDownListFactory())
         }
     });
     var items = new [] {
Exemplo n.º 2
0
        public FontPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            selector            = editorParams.DropDownListFactory();
            selector.LayoutCell = new LayoutCell(Alignment.Center);
            EditorContainer.AddNode(selector);
            var propType = editorParams.PropertyInfo.PropertyType;
            var items    = AssetBundle.Current.EnumerateFiles(defaultFontDirectory).
                           Where(i => i.EndsWith(".fnt") || i.EndsWith(".tft") || i.EndsWith(".cft")).
                           Select(i => new DropDownList.Item(FontPool.ExtractFontNameFromPath(i, defaultFontDirectory)));

            foreach (var i in items)
            {
                selector.Items.Add(i);
            }

            var current = CoalescedPropertyValue().GetValue();

            selector.Text     = current.IsDefined ? GetFontName(current.Value) : ManyValuesText;
            selector.Changed += a => {
                SetProperty(new SerializableFont((string)a.Value));
            };
            selector.AddChangeLateWatcher(CoalescedPropertyValue(), i => {
                selector.Text = i.IsDefined ? GetFontName(i.Value): ManyValuesText;
            });
        }
Exemplo n.º 3
0
        public EnumPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            Selector            = editorParams.DropDownListFactory();
            Selector.LayoutCell = new LayoutCell(Alignment.Center);
            EditorContainer.AddNode(Selector);
            var propType      = editorParams.PropertyInfo.PropertyType;
            var fields        = propType.GetFields(BindingFlags.Public | BindingFlags.Static);
            var allowedFields = fields.Where(f => !Attribute.IsDefined((MemberInfo)f, typeof(TangerineIgnoreAttribute)));

            foreach (var field in allowedFields)
            {
                Selector.Items.Add(new CommonDropDownList.Item(field.Name, field.GetValue(null)));
            }
            Selector.Changed += a => {
                if (a.ChangedByUser)
                {
                    SetProperty((T)Selector.Items[a.Index].Value);
                }
            };
            Selector.AddChangeLateWatcher(CoalescedPropertyValue(), v => {
                if (v.IsDefined)
                {
                    Selector.Value = v.Value;
                }
                else
                {
                    Selector.Text = ManyValuesText;
                }
            });
        }
Exemplo n.º 4
0
        public FontPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            selector            = editorParams.DropDownListFactory();
            selector.LayoutCell = new LayoutCell(Alignment.Center);
            ContainerWidget.AddNode(selector);
            var propType = editorParams.PropertyInfo.PropertyType;
            var items    = AssetBundle.Current.EnumerateFiles("Fonts").
                           Where(i => i.EndsWith(".fnt") || i.EndsWith(".tft")).
                           Select(i => new DropDownList.Item(Path.ChangeExtension(Path.GetFileName(i), null)));

            foreach (var i in items)
            {
                selector.Items.Add(i);
            }
            selector.Text     = GetFontName(CoalescedPropertyValue().GetValue());
            selector.Changed += a => {
                SetProperty(new SerializableFont((string)a.Value));
            };
            selector.AddChangeWatcher(CoalescedPropertyValue(), i => {
                selector.Text = GetFontName(i);
            });
        }
Exemplo n.º 5
0
        public InstancePropertyEditor(IPropertyEditorParams editorParams, Action <Widget> onValueChanged) : base(editorParams)
        {
            Selector            = editorParams.DropDownListFactory();
            Selector.LayoutCell = new LayoutCell(Alignment.Center);
            var propertyType = typeof(T);
            var meta         = Yuzu.Metadata.Meta.Get(editorParams.Type, InternalPersistence.Instance.YuzuCommonOptions);

            if (!propertyType.IsInterface && !propertyType.IsAbstract)
            {
                Selector.Items.Add(new CommonDropDownList.Item(propertyType.Name, propertyType));
            }
            foreach (var t in DerivedTypesCache.GetDerivedTypesFor(propertyType))
            {
                Selector.Items.Add(new CommonDropDownList.Item(t.Name, t));
            }
            EditorContainer.AddChangeLateWatcher(CoalescedPropertyValue(
                                                     comparator: (t1, t2) => t1 == null && t2 == null || t1 != null && t2 != null && t1.GetType() == t2.GetType()),
                                                 v => {
                onValueChanged?.Invoke(ExpandableContent);
                if (v.IsDefined)
                {
                    Selector.Value = v.Value?.GetType();
                }
                else
                {
                    Selector.Text = ManyValuesText;
                }
            }
                                                 );
            Selector.Changed += a => {
                if (a.ChangedByUser)
                {
                    var type = (Type)Selector.Items[a.Index].Value;
                    SetProperty <object>((_) => type != null ? Activator.CreateInstance(type) : null);
                }
            };
            var propertyMetaItem     = meta.Items.FirstOrDefault(i => i.Name == editorParams.PropertyName);
            var defaultValue         = propertyMetaItem?.GetValue(meta.Default);
            var resetToDefaultButton = new ToolbarButton(IconPool.GetTexture("Tools.Revert"))
            {
                Clicked = () => SetProperty(Cloner.Clone(defaultValue))
            };

            if (Selector.Items.Count == 1)
            {
                var t = Selector.Items[0].Value as Type;
                var b = new ToolbarButton("Create")
                {
                    TabTravesable = new TabTraversable(),
                    LayoutCell    = new LayoutCell(Alignment.LeftCenter),
                    Padding       = new Thickness(left: 5.0f),
                    HitTestTarget = true,
                    MinWidth      = 0,
                    MaxWidth      = float.PositiveInfinity
                };
                b.Clicked = () => {
                    b.Visible = false;
                    SetProperty <object>(_ => t != null ? Activator.CreateInstance(t) : null);
                    onValueChanged?.Invoke(ExpandableContent);
                    Expanded = true;
                };
                var value = CoalescedPropertyValue().GetValue();
                b.Visible = Equals(value.Value, defaultValue);
                resetToDefaultButton.Clicked = () => {
                    b.Visible = true;
                    SetProperty(defaultValue);
                    onValueChanged?.Invoke(ExpandableContent);
                };
                EditorContainer.AddNode(b);
                EditorContainer.AddNode(Spacer.HStretch());
                onValueChanged?.Invoke(ExpandableContent);
            }
            else
            {
                EditorContainer.Nodes.Insert(0, Selector);
            }
            EditorContainer.AddNode(resetToDefaultButton);
            EditorContainer.AddChangeLateWatcher(CoalescedPropertyValue(), v => {
                resetToDefaultButton.Visible = !Equals(v.Value, defaultValue);
            });
        }
Exemplo n.º 6
0
        public InstancePropertyEditor(IPropertyEditorParams editorParams, Action <Widget> OnValueChanged) : base(editorParams)
        {
            Selector            = editorParams.DropDownListFactory();
            Selector.LayoutCell = new LayoutCell(Alignment.Center);
            EditorContainer.AddNode(Selector);
            var propertyType     = typeof(T);
            var meta             = Yuzu.Metadata.Meta.Get(editorParams.Type, Serialization.YuzuCommonOptions);
            var propertyMetaItem = meta.Items.Where(i => i.Name == editorParams.PropertyName).FirstOrDefault();

            if (propertyMetaItem != null)
            {
                var defaultValue         = propertyMetaItem.GetValue(meta.Default);
                var resetToDefaultButton = new ToolbarButton(IconPool.GetTexture("Tools.Revert"))
                {
                    Clicked = () => { SetProperty(defaultValue); }
                };
                EditorContainer.AddNode(resetToDefaultButton);
                Selector.AddChangeWatcher(CoalescedPropertyValue(), v => {
                    resetToDefaultButton.Visible = !Equals(v, defaultValue);
                });
            }
            if (!propertyType.IsInterface)
            {
                Selector.Items.Add(new CommonDropDownList.Item(propertyType.Name, propertyType));
            }
            // TODO: invalidate cache on loading new assemblies at runtime
            if (!derivedTypesCache.TryGetValue(propertyType, out List <Type> derivedTypes))
            {
                derivedTypes = new List <Type>();
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    var assignables = assembly
                                      .GetTypes()
                                      .Where(t =>
                                             !t.IsInterface &&
                                             t.GetCustomAttribute <TangerineIgnoreAttribute>(false) == null &&
                                             t != propertyType &&
                                             propertyType.IsAssignableFrom(t));
                    foreach (var type in assignables)
                    {
                        derivedTypes.Add(type);
                    }
                }
                derivedTypesCache.Add(propertyType, derivedTypes);
            }
            foreach (var t in derivedTypes)
            {
                Selector.Items.Add(new CommonDropDownList.Item(t.Name, t));
            }
            Selector.Changed += a => {
                if (a.ChangedByUser)
                {
                    Type type = (Type)Selector.Items[a.Index].Value;
                    SetProperty <object>((_) => type != null ? Activator.CreateInstance(type) : null);
                }
            };
            Selector.AddChangeWatcher(CoalescedPropertyValue(), v => {
                OnValueChanged?.Invoke(ExpandableContent);
                Selector.Value = v?.GetType();
            });
        }