Exemplo n.º 1
0
            public override void Initialize(LayoutElementsContainer layout)
            {
                _proxy = (PropertiesProxy)Values[0];
                if (_proxy?.DefaultValues == null)
                {
                    layout.Label("Loading...", TextAlignment.Center);
                    return;
                }

                var isPlayModeActive = _proxy.Window.Editor.StateMachine.IsPlayMode;

                if (isPlayModeActive)
                {
                    layout.Label("Play mode is active. Editing runtime values.", TextAlignment.Center);
                    layout.Space(10);

                    foreach (var e in _proxy.DefaultValues)
                    {
                        var name           = e.Key;
                        var value          = _proxy.Asset.GetValue(name);
                        var valueContainer = new VariableValueContainer(_proxy, name, value, false);
                        var propertyLabel  = new PropertyNameLabel(name)
                        {
                            Tag = name,
                        };
                        string tooltip = null;
                        if (_proxy.DefaultValues.TryGetValue(name, out var defaultValue))
                        {
                            tooltip = "Default value: " + defaultValue;
                        }
                        layout.Object(propertyLabel, valueContainer, null, tooltip);
                    }
                }
                else
                {
                    foreach (var e in _proxy.DefaultValues)
                    {
                        var name           = e.Key;
                        var value          = e.Value;
                        var valueContainer = new VariableValueContainer(_proxy, name, value, true);
                        var propertyLabel  = new ClickablePropertyNameLabel(name)
                        {
                            Tag = name,
                        };
                        propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(name, label);
                        propertyLabel.SetupContextMenu     += OnPropertyLabelSetupContextMenu;
                        layout.Object(propertyLabel, valueContainer, null, "Type: " + CustomEditorsUtil.GetTypeNameUI(value.GetType()));
                    }

                    // TODO: improve the UI
                    layout.Space(40);
                    var addParamType = layout.ComboBox().ComboBox;
                    addParamType.Items         = AllowedTypes.Select(CustomEditorsUtil.GetTypeNameUI).ToList();
                    addParamType.SelectedIndex = 0;
                    _addParamType = addParamType;
                    var addParamButton = layout.Button("Add").Button;
                    addParamButton.Clicked += OnAddParamButtonClicked;
                }
            }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var type = Values.Type;
            var size = Count;

            // Try get MemberCollectionAttribute for collection editor meta
            var attributes = Values.GetAttributes();

            if (attributes != null)
            {
                var memberCollection = (MemberCollectionAttribute)attributes.FirstOrDefault(x => x is MemberCollectionAttribute);
                if (memberCollection != null)
                {
                    // TODO: handle ReadOnly and NotNullItems by filtering child editors SetValue
                    // TODO: handle CanReorderItems

                    _readOnly        = memberCollection.ReadOnly;
                    _canReorderItems = memberCollection.CanReorderItems;
                    _notNullItems    = memberCollection.NotNullItems;
                }
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var elementType = ElementType;
                for (int i = 0; i < size; i++)
                {
                    layout.Object("Element " + i, new ListValueContainer(elementType, i, Values));
                }
            }
            _elementsCount = size;
        }
Exemplo n.º 3
0
            /// <inheritdoc />
            public override void Initialize(LayoutElementsContainer layout)
            {
                base.Initialize(layout);

                var instance   = (AnimEvent)Values[0];
                var scriptType = TypeUtils.GetObjectType(instance);
                var editor     = CustomEditorsUtil.CreateEditor(scriptType, false);

                layout.Object(Values, editor);
            }
Exemplo n.º 4
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            // Get the target options
            _options = Options;
            if (_options == null)
            {
                throw new ArgumentNullException();
            }

            int  selectedIndex     = -1;
            bool hasDifferentTypes = Values.HasDifferentTypes;
            var  type = Type;

            _type = type;

            // Type
            var typeEditor = layout.ComboBox(TypeComboBoxName, "Type of the object value. Use it to change the object.");

            for (int i = 0; i < _options.Length; i++)
            {
                typeEditor.ComboBox.AddItem(_options[i].Name);
                selectedIndex = _options[i].Type == type.Type ? i : selectedIndex;
            }
            typeEditor.ComboBox.SupportMultiSelect    = false;
            typeEditor.ComboBox.SelectedIndex         = hasDifferentTypes ? -1 : selectedIndex;
            typeEditor.ComboBox.SelectedIndexChanged += OnSelectedIndexChanged;

            // Editing different types is not supported
            if (Values.HasDifferentTypes)
            {
                var property = layout.AddPropertyItem("Value");
                property.Label("Different Values");
                return;
            }

            // Nothing to edit
            if (Values.HasNull)
            {
                var property = layout.AddPropertyItem("Value");
                property.Label("<null>");
                return;
            }

            // Value
            var values = new CustomValueContainer(type, (instance, index) => instance, (instance, index, value) => { });

            values.AddRange(Values);
            var editor = CustomEditorsUtil.CreateEditor(type);
            var style  = editor.Style;

            if (style == DisplayStyle.InlineIntoParent)
            {
                layout.Object(values, editor);
            }
            else if (style == DisplayStyle.Group)
            {
                var group = layout.Group("Value", true);
                group.Panel.Open(false);
                group.Object(values, editor);

                // Remove empty group
                if (group.ContainerControl.ChildrenCount == 0)
                {
                    layout.Children.Remove(group);
                    group.Panel.Dispose();
                }
            }
            else
            {
                layout.AddPropertyItem("Value").Object(values, editor);
            }
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly     = false;
            _notNullItems = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var type      = Values.Type;
            var size      = Count;
            var argTypes  = type.GetGenericArguments();
            var keyType   = argTypes[0];
            var valueType = argTypes[1];

            _canEditKeys = keyType == typeof(string) || keyType.IsPrimitive || keyType.IsEnum;

            // Try get CollectionAttribute for collection editor meta
            var   attributes         = Values.GetAttributes();
            Type  overrideEditorType = null;
            float spacing            = 0.0f;

            if (attributes != null)
            {
                var collection = (CollectionAttribute)attributes.FirstOrDefault(x => x is CollectionAttribute);
                if (collection != null)
                {
                    // TODO: handle ReadOnly and NotNullItems by filtering child editors SetValue

                    _readOnly          = collection.ReadOnly;
                    _notNullItems      = collection.NotNullItems;
                    overrideEditorType = TypeUtils.GetType(collection.OverrideEditorTypeName).Type;
                    spacing            = collection.Spacing;
                }
            }

            // Size
            if (_readOnly || !_canEditKeys)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var keysEnumerable = ((IDictionary)Values[0]).Keys.OfType <object>();
                var keys           = keysEnumerable as object[] ?? keysEnumerable.ToArray();
                for (int i = 0; i < size; i++)
                {
                    if (i != 0 && spacing > 0f)
                    {
                        if (layout.Children.Count > 0 && layout.Children[layout.Children.Count - 1] is PropertiesListElement propertiesListElement)
                        {
                            if (propertiesListElement.Labels.Count > 0)
                            {
                                var label  = propertiesListElement.Labels[propertiesListElement.Labels.Count - 1];
                                var margin = label.Margin;
                                margin.Bottom += spacing;
                                label.Margin   = margin;
                            }
                            propertiesListElement.Space(spacing);
                        }
                        else
                        {
                            layout.Space(spacing);
                        }
                    }

                    var key            = keys.ElementAt(i);
                    var overrideEditor = overrideEditorType != null ? (CustomEditor)Activator.CreateInstance(overrideEditorType) : null;
                    layout.Object(new DictionaryItemLabel(this, key), new DictionaryValueContainer(new ScriptType(valueType), key, Values), overrideEditor);
                }
            }
            _elementsCount = size;

            // Add/Remove buttons
            if (!_readOnly && _canEditKeys)
            {
                var area      = layout.Space(20);
                var addButton = new Button(area.ContainerControl.Width - (16 + 16 + 2 + 2), 2, 16, 16)
                {
                    Text         = "+",
                    TooltipText  = "Add new item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl
                };
                addButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count + 1);
                };
                var removeButton = new Button(addButton.Right + 2, addButton.Y, 16, 16)
                {
                    Text         = "-",
                    TooltipText  = "Remove last item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl,
                    Enabled      = size > 0
                };
                removeButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count - 1);
                };
            }
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var size = Count;

            // Try get MemberCollectionAttribute for collection editor meta
            var attributes = Values.GetAttributes();

            if (attributes != null)
            {
                var memberCollection = (MemberCollectionAttribute)attributes.FirstOrDefault(x => x is MemberCollectionAttribute);
                if (memberCollection != null)
                {
                    // TODO: handle NotNullItems by filtering child editors SetValue

                    _readOnly        = memberCollection.ReadOnly;
                    _canReorderItems = memberCollection.CanReorderItems;
                    _notNullItems    = memberCollection.NotNullItems;
                }
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var elementType = ElementType;
                if (_canReorderItems)
                {
                    for (int i = 0; i < size; i++)
                    {
                        layout.Object(new CollectionItemLabel(this, i), new ListValueContainer(elementType, i, Values));
                    }
                }
                else
                {
                    for (int i = 0; i < size; i++)
                    {
                        layout.Object("Element " + i, new ListValueContainer(elementType, i, Values));
                    }
                }
            }
            _elementsCount = size;

            // Add/Remove buttons
            if (!_readOnly)
            {
                var area      = layout.Space(20);
                var addButton = new Button(area.ContainerControl.Width - (16 + 16 + 2 + 2), 2, 16, 16)
                {
                    Text        = "+",
                    TooltipText = "Add new item",
                    AnchorStyle = AnchorStyle.UpperRight,
                    Parent      = area.ContainerControl
                };
                addButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count + 1);
                };
                var removeButton = new Button(addButton.Right + 2, addButton.Y, 16, 16)
                {
                    Text        = "-",
                    TooltipText = "Remove last item",
                    AnchorStyle = AnchorStyle.UpperRight,
                    Parent      = area.ContainerControl,
                    Enabled     = size > 0
                };
                removeButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count - 1);
                };
            }
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            _readOnly        = false;
            _canReorderItems = true;
            _notNullItems    = false;

            // No support for different collections for now
            if (HasDifferentValues || HasDifferentTypes)
            {
                return;
            }

            var size = Count;

            // Try get CollectionAttribute for collection editor meta
            var   attributes         = Values.GetAttributes();
            Type  overrideEditorType = null;
            float spacing            = 10.0f;
            var   collection         = (CollectionAttribute)attributes?.FirstOrDefault(x => x is CollectionAttribute);

            if (collection != null)
            {
                // TODO: handle NotNullItems by filtering child editors SetValue

                _readOnly          = collection.ReadOnly;
                _canReorderItems   = collection.CanReorderItems;
                _notNullItems      = collection.NotNullItems;
                overrideEditorType = TypeUtils.GetType(collection.OverrideEditorTypeName).Type;
                spacing            = collection.Spacing;
            }

            // Size
            if (_readOnly)
            {
                layout.Label("Size", size.ToString());
            }
            else
            {
                _size = layout.IntegerValue("Size");
                _size.IntValue.MinValue      = 0;
                _size.IntValue.MaxValue      = ushort.MaxValue;
                _size.IntValue.Value         = size;
                _size.IntValue.ValueChanged += OnSizeChanged;
            }

            // Elements
            if (size > 0)
            {
                var elementType = ElementType;
                if (_canReorderItems)
                {
                    for (int i = 0; i < size; i++)
                    {
                        if (i != 0 && spacing > 0f)
                        {
                            if (layout.Children.Count > 0 && layout.Children[layout.Children.Count - 1] is PropertiesListElement propertiesListElement)
                            {
                                if (propertiesListElement.Labels.Count > 0)
                                {
                                    var label  = propertiesListElement.Labels[propertiesListElement.Labels.Count - 1];
                                    var margin = label.Margin;
                                    margin.Bottom += spacing;
                                    label.Margin   = margin;
                                }
                                propertiesListElement.Space(spacing);
                            }
                            else
                            {
                                layout.Space(spacing);
                            }
                        }

                        var overrideEditor = overrideEditorType != null ? (CustomEditor)Activator.CreateInstance(overrideEditorType) : null;
                        layout.Object(new CollectionItemLabel(this, i), new ListValueContainer(elementType, i, Values), overrideEditor);
                    }
                }
                else
                {
                    for (int i = 0; i < size; i++)
                    {
                        if (i != 0 && spacing > 0f)
                        {
                            if (layout.Children.Count > 0 && layout.Children[layout.Children.Count - 1] is PropertiesListElement propertiesListElement)
                            {
                                propertiesListElement.Space(spacing);
                            }
                            else
                            {
                                layout.Space(spacing);
                            }
                        }

                        var overrideEditor = overrideEditorType != null ? (CustomEditor)Activator.CreateInstance(overrideEditorType) : null;
                        layout.Object("Element " + i, new ListValueContainer(elementType, i, Values), overrideEditor);
                    }
                }
            }
            _elementsCount = size;

            // Add/Remove buttons
            if (!_readOnly)
            {
                var area      = layout.Space(20);
                var addButton = new Button(area.ContainerControl.Width - (16 + 16 + 2 + 2), 2, 16, 16)
                {
                    Text         = "+",
                    TooltipText  = "Add new item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl
                };
                addButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count + 1);
                };
                var removeButton = new Button(addButton.Right + 2, addButton.Y, 16, 16)
                {
                    Text         = "-",
                    TooltipText  = "Remove last item",
                    AnchorPreset = AnchorPresets.TopRight,
                    Parent       = area.ContainerControl,
                    Enabled      = size > 0
                };
                removeButton.Clicked += () =>
                {
                    if (IsSetBlocked)
                    {
                        return;
                    }

                    Resize(Count - 1);
                };
            }
        }