예제 #1
0
        private ITreeStringNode addReadonlyNodeToTree(InspectorProperty property, ITreeStringNode parent)
        {
            IInspectorPropertyEditor editor = new StringPropertyEditor(_factory, false);
            ITreeStringNode          node   = new InspectorTreeNode(property, editor);

            addToTree(node, parent);
            var propertyChanged = property.Object as INotifyPropertyChanged;

            if (propertyChanged != null)
            {
                propertyChanged.PropertyChanged += (sender, e) =>
                {
                    if (e.PropertyName != property.Name)
                    {
                        return;
                    }
                    bool isExpanded = _treeView.IsCollapsed(node) == false;
                    if (isExpanded)
                    {
                        _treeView.Collapse(node);
                    }
                    refreshChildrenProperties(property);
                    node.TreeNode.Children.Clear();
                    addChildrenToTree(node, property);

                    //todo: we'd like to enable expanding a node that was previously expanded however there's a bug that needs to be investigated before that, to reproduce:
                    //In the demo game, show the inspector for the character and expand its current room. Then move to another room.
                    //For some reason this results in endless boundin box/matrix changes until stack overflow is reached.
                    //if (isExpanded)
                    //  _treeView.Expand(node);
                };
            }
            return(node);
        }
예제 #2
0
        private ITreeStringNode addToTree(InspectorProperty property, ITreeStringNode parent)
        {
            if (property.IsReadonly)
            {
                return(addReadonlyNodeToTree(property, parent));
            }
            IInspectorPropertyEditor editor;

            var propType = property.Prop.PropertyType;

            if (propType == typeof(bool))
            {
                editor = new BoolPropertyEditor(_factory);
            }
            else if (propType == typeof(Color))
            {
                editor = new ColorPropertyEditor(_factory);
            }

            else if (propType == typeof(int))
            {
                editor = new NumberPropertyEditor(_state, _factory, true, false);
            }
            else if (propType == typeof(float))
            {
                editor = new NumberPropertyEditor(_state, _factory, false, false);
            }
            else if (propType == typeof(SizeF))
            {
                editor = new SizeFPropertyEditor(_state, _factory, false);
            }
            else if (propType == typeof(Size))
            {
                editor = new SizePropertyEditor(_state, _factory, false);
            }
            else if (propType == typeof(PointF))
            {
                editor = new PointFPropertyEditor(_state, _factory, false);
            }
            else if (propType == typeof(Point))
            {
                editor = new PointPropertyEditor(_state, _factory, false);
            }
            else if (propType == typeof(Vector2))
            {
                editor = new Vector2PropertyEditor(_state, _factory, false);
            }
            else if (propType == typeof(ILocation))
            {
                var entity   = _currentEntity;
                var drawable = entity == null ? null : entity.GetComponent <IDrawableInfoComponent>();
                editor = new LocationPropertyEditor(_state, _factory, false, _settings, drawable);
            }
            else if (propType == typeof(RectangleF))
            {
                editor = new RectangleFPropertyEditor(_state, _factory, false);
            }
            else if (propType == typeof(Rectangle))
            {
                editor = new RectanglePropertyEditor(_state, _factory, false);
            }

            else if (propType == typeof(int?))
            {
                editor = new NumberPropertyEditor(_state, _factory, true, true);
            }
            else if (propType == typeof(float?))
            {
                editor = new NumberPropertyEditor(_state, _factory, false, true);
            }
            else if (propType == typeof(SizeF?))
            {
                editor = new SizeFPropertyEditor(_state, _factory, true);
            }
            else if (propType == typeof(Size?))
            {
                editor = new SizePropertyEditor(_state, _factory, true);
            }
            else if (propType == typeof(PointF?))
            {
                editor = new PointFPropertyEditor(_state, _factory, true);
            }
            else if (propType == typeof(Point?))
            {
                editor = new PointPropertyEditor(_state, _factory, true);
            }
            else if (propType == typeof(Vector2?))
            {
                editor = new Vector2PropertyEditor(_state, _factory, true);
            }
            else if (propType == typeof(RectangleF?))
            {
                editor = new RectangleFPropertyEditor(_state, _factory, true);
            }
            else if (propType == typeof(Rectangle?))
            {
                editor = new RectanglePropertyEditor(_state, _factory, true);
            }

            else
            {
                var typeInfo = propType.GetTypeInfo();
                if (typeInfo.IsEnum)
                {
                    editor = new EnumPropertyEditor(_factory.UI);
                }
                else
                {
                    editor = new StringPropertyEditor(_factory, propType == typeof(string));
                }
            }

            ITreeStringNode node = new InspectorTreeNode(property, editor);

            return(addToTree(node, parent));
        }