Exemplo n.º 1
0
        /// <summary>
        /// Spawns the property for the given item.
        /// </summary>
        /// <param name="itemLayout">The item layout.</param>
        /// <param name="itemValues">The item values.</param>
        /// <param name="item">The item.</param>
        protected virtual void SpawnProperty(LayoutElementsContainer itemLayout, ValueContainer itemValues, ItemInfo item)
        {
            int labelIndex = 0;

            if (item.VisibleIf != null && itemLayout.Children.Count > 0 && itemLayout.Children[itemLayout.Children.Count - 1] is PropertiesListElement propertiesListElement)
            {
                labelIndex = propertiesListElement.Labels.Count;
            }

            itemLayout.Property(item.DisplayName, itemValues, item.OverrideEditor, item.TooltipText);

            if (item.VisibleIf != null)
            {
                PropertiesListElement list;
                if (itemLayout.Children.Count > 0 && itemLayout.Children[itemLayout.Children.Count - 1] is PropertiesListElement list1)
                {
                    list = list1;
                }
                else
                {
                    // TODO: support inlined objects hididng?
                    return;
                }

                // Get source member used to check rule
                var sourceMember = GetVisibleIfSource(item.Info.DeclaringType, item.VisibleIf);
                if (sourceMember == null)
                {
                    return;
                }

                // Find the target control to show/hide


                // Resize cache
                if (_visibleIfCaches == null)
                {
                    _visibleIfCaches = new VisibleIfCache[8];
                }
                int count = 0;
                while (count < _visibleIfCaches.Length && _visibleIfCaches[count].Target != null)
                {
                    count++;
                }
                if (count >= _visibleIfCaches.Length)
                {
                    Array.Resize(ref _visibleIfCaches, count * 2);
                }

                // Add item
                _visibleIfCaches[count] = new VisibleIfCache
                {
                    Target         = item.Info,
                    Source         = sourceMember,
                    PropertiesList = list,
                    LabelIndex     = labelIndex,
                };
            }
        }
Exemplo n.º 2
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("Type", "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 ? 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);

            layout.Property("Value", values, editor);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Spawns the property for the given item.
        /// </summary>
        /// <param name="itemLayout">The item layout.</param>
        /// <param name="itemValues">The item values.</param>
        /// <param name="item">The item.</param>
        protected virtual void SpawnProperty(LayoutElementsContainer itemLayout, ValueContainer itemValues, ItemInfo item)
        {
            int labelIndex = 0;

            if ((item.IsReadOnly || item.VisibleIf != null) &&
                itemLayout.Children.Count > 0 &&
                itemLayout.Children[itemLayout.Children.Count - 1] is PropertiesListElement propertiesListElement)
            {
                labelIndex = propertiesListElement.Labels.Count;
            }

            itemLayout.Property(item.DisplayName, itemValues, item.OverrideEditor, item.TooltipText);

            if (item.IsReadOnly && itemLayout.Children.Count > 0)
            {
                PropertiesListElement list  = null;
                int  firstChildControlIndex = 0;
                bool disableSingle          = true;
                var  control = itemLayout.Children[itemLayout.Children.Count - 1];
                if (control is GroupElement group && group.Children.Count > 0)
                {
                    list          = group.Children[0] as PropertiesListElement;
                    disableSingle = false; // Disable all nested editors
                }
                else if (control is PropertiesListElement list1)
                {
                    list = list1;
                    firstChildControlIndex = list.Labels[labelIndex].FirstChildControlIndex;
                }

                if (list != null)
                {
                    // Disable controls added to the editor
                    var count = list.Properties.Children.Count;
                    for (int j = firstChildControlIndex; j < count; j++)
                    {
                        var child = list.Properties.Children[j];
                        if (disableSingle && child is PropertyNameLabel)
                        {
                            break;
                        }

                        if (child != null)
                        {
                            child.Enabled = false;
                        }
                    }
                }
            }
Exemplo n.º 4
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            // Atlas
            var atlasField  = typeof(Sprite).GetField("Atlas");
            var atlasValues = new ValueContainer(atlasField, Values);

            layout.Property("Atlas", atlasValues, null, "The target atlas texture used as a sprite image source.");
            _atlasValues = atlasValues;

            // Sprite
            var spriteIndexField = typeof(Sprite).GetField("Index");

            _indexValues = new ValueContainer(spriteIndexField, Values);
            var spriteLabel = layout.AddPropertyItem("Sprite", "The selected sprite from the atlas.");

            // Check state
            if (atlasValues.HasDifferentValues)
            {
                spriteLabel.Label("Different values");
                return;
            }
            var value = (SpriteAtlas)atlasValues[0];

            if (value == null)
            {
                spriteLabel.Label("Pick atlas first");
                return;
            }

            // TODO: don't stall use Refresh to rebuild UI when sprite atlas gets loaded
            if (value.WaitForLoaded())
            {
                return;
            }

            // List all sprites from the atlas asset
            var spritesCount = value.SpritesCount;
            var spritePicker = spriteLabel.ComboBox();

            spritePicker.ComboBox.Items.Capacity = spritesCount;
            for (int i = 0; i < spritesCount; i++)
            {
                spritePicker.ComboBox.AddItem(value.GetSprite(i).Name);
            }
            spritePicker.ComboBox.SupportMultiSelect    = false;
            spritePicker.ComboBox.SelectedIndexChanged += OnSelectedIndexChanged;
            _spritePicker = spritePicker.ComboBox;
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        protected override void SpawnProperty(LayoutElementsContainer itemLayout, ValueContainer itemValues, ItemInfo item)
        {
            var order = item.Order.Order;

            if (order != FrictionCombineModeOrder && order != RestitutionCombineModeOrder)
            {
                base.SpawnProperty(itemLayout, itemValues, item);
                return;
            }

            // Add labels with a check box
            var label = new CheckablePropertyNameLabel(item.DisplayName);

            label.CheckBox.Tag  = order;
            label.CheckChanged += CheckBoxOnCheckChanged;
            _labels.Add(label);
            itemLayout.Property(label, itemValues, item.OverrideEditor, item.TooltipText);
        }
        /// <inheritdoc />
        protected override void SpawnProperty(LayoutElementsContainer itemLayout, ValueContainer itemValues, ItemInfo item)
        {
            var setting = item.Info.GetCustomAttribute <PostProcessSettingAttribute>();

            if (setting == null)
            {
                base.SpawnProperty(itemLayout, itemValues, item);
                return;
            }

            // Add labels with a check box
            var label = new CheckablePropertyNameLabel(item.DisplayName);

            label.CheckBox.Tag  = setting.Bit;
            label.CheckChanged += CheckBoxOnCheckChanged;
            _labels.Add(label);
            itemLayout.Property(label, itemValues, item.OverrideEditor, item.TooltipText);
        }
        /// <inheritdoc />
        protected override void SpawnProperty(LayoutElementsContainer itemLayout, ValueContainer itemValues, ItemInfo item)
        {
            var order = item.Order.Order;

            // Skip for PosFx Materials
            if (order == 10000)
            {
                base.SpawnProperty(itemLayout, itemValues, item);
                return;
            }

            // Add labels with a check box
            var label = new CheckablePropertyNameLabel(item.DisplayName);

            label.CheckBox.Tag  = order;
            label.CheckChanged += CheckBoxOnCheckChanged;
            _labels.Add(label);
            itemLayout.Property(label, itemValues, item.OverrideEditor, item.TooltipText);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Spawns the property for the given item.
 /// </summary>
 /// <param name="itemLayout">The item layout.</param>
 /// <param name="itemValues">The item values.</param>
 /// <param name="item">The item.</param>
 protected virtual void SpawnProperty(LayoutElementsContainer itemLayout, ValueContainer itemValues, ItemInfo item)
 {
     itemLayout.Property(item.DisplayName, itemValues, item.OverrideEditor, item.TooltipText);
 }