Пример #1
0
        private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            InspectorPropertyData dataContext = (InspectorPropertyData)this.DataContext;

            this.inspectorFactory = new InspectorFactory(
                dataContext.EditorContext,
                dataContext.EditorContext != null ? dataContext.EditorContext.LocalizationContext : null);

            InspectorPropertyAttribute inspectorProperty = dataContext.InspectorProperty;

            this.itemType = inspectorProperty.AttributeType ?? inspectorProperty.PropertyType.GetGenericArguments()[0];
            this.itemInspectorProperty = inspectorProperty.Clone();
            this.itemInspectorProperty.PropertyType = this.itemType;

            // Set items.
            this.ClearItemControls();

            if (dataContext.Value != null)
            {
                // Backwards compatibility if the attribute was a single item first and
                // changed to a list now.
                IList items = dataContext.Value as IList;
                if (items != null)
                {
                    foreach (var item in items)
                    {
                        this.AddItemControl(item);
                    }
                }
                else
                {
                    this.AddItemControl(dataContext.Value);
                }
            }
        }
Пример #2
0
 private object GetDefaultValue(InspectorPropertyAttribute inspectorProperty)
 {
     return(this.selectedBlueprint != null
                ? this.selectedBlueprint.Blueprint.GetAttributeTable()
            .GetValueOrDefault(inspectorProperty.Name, inspectorProperty.Default)
                : null);
 }
Пример #3
0
        /// <summary>
        ///   Gets the condition for the specified attribute to have its inspector shown,
        ///   or <c>null</c> if the inspector should always be shown.
        /// </summary>
        /// <param name="attribute">Attribute to get the inspector condition of.</param>
        /// <returns>
        ///   Condition for the specified attribute to have its inspector shown,
        ///   or <c>null</c> if the inspector should always be shown.
        /// </returns>
        public InspectorConditionalPropertyAttribute GetCondition(InspectorPropertyAttribute attribute)
        {
            InspectorConditionalPropertyAttribute condition;

            this.conditionalInspectors.TryGetValue(attribute, out condition);
            return(condition);
        }
Пример #4
0
        private void OnPropertyControlValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue)
        {
            EntityConfiguration entityConfiguration = (EntityConfiguration)this.Value ?? new EntityConfiguration();

            // Remove value if default value or inherited from blueprint. Otherwise set it.
            object defaultValue = this.GetDefaultValue(inspectorProperty);

            var defaultList = defaultValue as IList;
            var newList     = newValue as IList;

            if (defaultList != null && newList != null && CollectionUtils.ListEqual(defaultList, newList))
            {
                entityConfiguration.Configuration.RemoveValue(inspectorProperty.Name);
            }
            else if (Equals(newValue, defaultValue))
            {
                entityConfiguration.Configuration.RemoveValue(inspectorProperty.Name);
            }
            else
            {
                entityConfiguration.Configuration.SetValue(inspectorProperty.Name, newValue);
            }

            this.OnValueChanged();
        }
Пример #5
0
        protected void OnValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue)
        {
            InspectorControlValueChangedDelegate handler = this.ValueChanged;

            if (handler != null)
            {
                handler(inspectorProperty, newValue);
            }
        }
Пример #6
0
 /// <summary>
 ///   Initializes the control with the inspector property it is for and the current value.
 /// </summary>
 /// <param name="inspectorProperty">Inspector property the control is for.</param>
 /// <param name="editorContext">Editor context this control lives in.</param>
 /// <param name="localizationContext">Context used for showing and changing localized attribute values.</param>
 /// <param name="currentValue">Current value.</param>
 /// <param name="valueInherited">Indicates if the current value was inherited.</param>
 public virtual void Init(InspectorPropertyAttribute inspectorProperty, EditorContext editorContext, LocalizationContext localizationContext, object currentValue, bool valueInherited)
 {
     // Setup data context of control.
     this.dataContext = new InspectorPropertyData(inspectorProperty, localizationContext)
     {
         EditorContext = editorContext, Value = currentValue, ValueInherited = valueInherited
     };
     this.dataContext.ValueChanged += this.OnValueChanged;
     this.DataContext = this.dataContext;
 }
Пример #7
0
        private void TestAddingDefaultItemToEmptyList(InspectorType inspectorType, string propertyName)
        {
            InspectorPropertyAttribute testAttribute =
                inspectorType.Properties.First(property => property.Name == propertyName);

            // Create list.
            var list = testAttribute.GetEmptyList();

            list.Add(testAttribute.DefaultListItem);
        }
Пример #8
0
        /// <summary>
        ///   Creates and positions a new inspector control for the passed property.
        /// </summary>
        /// <param name="inspectorProperty">Property to create an inspector control for.</param>
        /// <param name="currentValue">Current value of the observed property.</param>
        /// <param name="valueInherited">Indicates if the current value was inherited.</param>
        public IInspectorControl CreateInspectorControlFor(
            InspectorPropertyAttribute inspectorProperty, object currentValue, bool valueInherited)
        {
            // Create inspector control.
            IInspectorControl inspectorControl;

            if (inspectorProperty.IsList)
            {
                inspectorControl = new ListInspector();
            }
            else if (inspectorProperty is InspectorBoolAttribute)
            {
                inspectorControl = new CheckBoxInspector();
            }
            else if (inspectorProperty is InspectorStringAttribute)
            {
                inspectorControl = new TextBoxInspector();
            }
            else if (inspectorProperty is InspectorFloatAttribute)
            {
                inspectorControl = new SingleUpDownInspector();
            }
            else if (inspectorProperty is InspectorIntAttribute)
            {
                inspectorControl = new IntegerUpDownInspector();
            }
            else if (inspectorProperty is InspectorEnumAttribute)
            {
                inspectorControl = new ComboBoxInspector();
            }
            else if (inspectorProperty is InspectorBlueprintAttribute)
            {
                inspectorControl = null;
            }
            else if (inspectorProperty is InspectorDataAttribute)
            {
                inspectorControl = new DataInspector();
            }
            else if (inspectorProperty is InspectorEntityAttribute)
            {
                inspectorControl = new EntityInspector();
            }
            else
            {
                inspectorControl = null;
            }

            // Setup control.
            if (inspectorControl != null)
            {
                inspectorControl.Init(inspectorProperty, this.editorContext, this.localizationContext, currentValue, valueInherited);
            }

            return(inspectorControl);
        }
Пример #9
0
        private void OnPropertyValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue)
        {
            if (this.value == null)
            {
                this.value = new AttributeTable();
            }

            this.value.SetValue(inspectorProperty.Name, newValue);

            InspectorPropertyData dataContext = (InspectorPropertyData)this.DataContext;

            dataContext.Value = this.value;
        }
Пример #10
0
        private object GetPropertyValue(InspectorPropertyAttribute inspectorProperty, out bool inherited)
        {
            object propertyValue;

            if (this.value != null &&
                this.value.TryGetValue(inspectorProperty.Name, out propertyValue))
            {
                inherited = false;
                return(propertyValue);
            }

            inherited = true;
            return(inspectorProperty.Default);
        }
Пример #11
0
        private object GetCurrentAttributeValue(InspectorPropertyAttribute inspectorProperty, out bool inherited)
        {
            object value;
            EntityConfiguration entityConfiguration = (EntityConfiguration)this.Value;

            if (entityConfiguration != null &&
                entityConfiguration.Configuration.TryGetValue(inspectorProperty.Name, out value))
            {
                inherited = false;
            }
            else
            {
                inherited = true;
                value     = this.GetDefaultValue(inspectorProperty);
            }
            return(value);
        }
Пример #12
0
        public override void Init(
            InspectorPropertyAttribute inspectorProperty,
            EditorContext editorContext,
            LocalizationContext localizationContext,
            object currentValue, bool valueInherited)
        {
            base.Init(inspectorProperty, editorContext, localizationContext, currentValue, valueInherited);

            // Disable for localized strings.
            // TODO(np): Enable editing while not showing RAW values.
            var stringProperty = inspectorProperty as InspectorStringAttribute;

            if (stringProperty != null && stringProperty.Localized)
            {
                this.IsEnabled = false;
            }
        }
Пример #13
0
        /// <summary>
        ///   Draws an inspector for the specified logic property.
        /// </summary>
        /// <param name="inspectorProperty">Logic property to draw the inspector for.</param>
        /// <param name="currentValue">Current logic property value.</param>
        /// <param name="inspectorTypeTable"></param>
        /// <param name="blueprintManager"></param>
        /// <returns>New logic property value.</returns>
        public static object LogicInspectorPropertyField(
            InspectorPropertyAttribute inspectorProperty,
            object currentValue,
            InspectorTypeTable inspectorTypeTable,
            IBlueprintManager blueprintManager)
        {
            if (inspectorProperty.IsList)
            {
                // Build array.
                IList currentList = currentValue as IList;
                InspectorPropertyAttribute localInspectorProperty = inspectorProperty;
                IList newList;

                ListField(
                    true,
                    new GUIContent(inspectorProperty.Name),
                    currentList,
                    count =>
                {
                    IList list = localInspectorProperty.GetEmptyList();
                    for (int idx = 0; idx < count; idx++)
                    {
                        list.Add(localInspectorProperty.DefaultListItem);
                    }
                    return(list);
                },
                    (obj, index) =>
                    LogicInspectorPropertyField(
                        localInspectorProperty,
                        obj,
                        new GUIContent("Item " + index),
                        inspectorTypeTable,
                        blueprintManager),
                    out newList);

                return(newList);
            }

            // Draw inspector property.
            return(LogicInspectorPropertyField(
                       inspectorProperty,
                       currentValue,
                       new GUIContent(inspectorProperty.Name, inspectorProperty.Description),
                       inspectorTypeTable,
                       blueprintManager));
        }
Пример #14
0
        public InspectorPropertyData(
            InspectorPropertyAttribute inspectorProperty, LocalizationContext localizationContext)
        {
            this.inspectorProperty = inspectorProperty;

            // Check for localized attribute.
            var stringProperty = this.inspectorProperty as InspectorStringAttribute;

            if (stringProperty != null && stringProperty.Localized)
            {
                this.localizationContext = localizationContext;

                if (this.localizationContext != null)
                {
                    this.localizationContext.ProjectLanguageChanged += this.OnProjectLanguageChanged;
                }
            }
        }
Пример #15
0
 private void OnValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue)
 {
     this.RaiseEvent(new ValueChangedEventArgs {
         RoutedEvent = ValueChangedEvent, NewValue = newValue
     });
 }
Пример #16
0
        /// <summary>
        ///   Draws an inspector for the specified logic property.
        /// </summary>
        /// <param name="inspectorProperty">Logic property to draw the inspector for.</param>
        /// <param name="currentValue">Current logic property value.</param>
        /// <param name="label">Text to show next to the property editor.</param>
        /// <param name="inspectorTypeTable"></param>
        /// <param name="blueprintManager"></param>
        /// <returns>New logic property value.</returns>
        public static object LogicInspectorPropertyField(
            InspectorPropertyAttribute inspectorProperty,
            object currentValue,
            GUIContent label,
            InspectorTypeTable inspectorTypeTable,
            IBlueprintManager blueprintManager)
        {
            // Draw inspector control.
            if (inspectorProperty is InspectorBoolAttribute)
            {
                return(EditorGUILayout.Toggle(label, Convert.ToBoolean(currentValue)));
            }
            if (inspectorProperty is InspectorStringAttribute || inspectorProperty is InspectorBlueprintAttribute)
            {
                return(EditorGUILayout.TextField(label, Convert.ToString(currentValue)));
            }
            if (inspectorProperty is InspectorFloatAttribute)
            {
                return(EditorGUILayout.FloatField(label, Convert.ToSingle(currentValue)));
            }
            if (inspectorProperty is InspectorIntAttribute)
            {
                return(EditorGUILayout.IntField(label, Convert.ToInt32(currentValue)));
            }
            InspectorEnumAttribute enumInspectorProperty = inspectorProperty as InspectorEnumAttribute;

            if (enumInspectorProperty != null)
            {
                object currentEnumValue = (currentValue != null)
                    ? Convert.ChangeType(currentValue, enumInspectorProperty.PropertyType)
                    : Enum.GetValues(enumInspectorProperty.PropertyType).GetValue(0);
                return(EditorGUILayout.EnumPopup(label, (Enum)currentEnumValue));
            }
            InspectorVectorAttribute vectorInspectorproperty = inspectorProperty as InspectorVectorAttribute;

            if (vectorInspectorproperty != null)
            {
                if (vectorInspectorproperty.PropertyType == typeof(Vector2I) ||
                    vectorInspectorproperty.PropertyType == typeof(List <Vector2I>))
                {
                    Vector2I currentVector2IValue = (currentValue != null) ? (Vector2I)currentValue : Vector2I.Zero;
                    return(Vector2IField(label, currentVector2IValue));
                }
                if (vectorInspectorproperty.PropertyType == typeof(Vector2F) ||
                    vectorInspectorproperty.PropertyType == typeof(List <Vector2F>))
                {
                    Vector2F currentVector2FValue = (currentValue != null) ? (Vector2F)currentValue : Vector2F.Zero;
                    return(Vector2FField(label, currentVector2FValue));
                }
            }
            InspectorEntityAttribute entityInspector = inspectorProperty as InspectorEntityAttribute;

            if (entityInspector != null)
            {
                EntityConfiguration entityConfiguration = currentValue as EntityConfiguration;
                if (entityConfiguration == null)
                {
                    entityConfiguration = new EntityConfiguration();
                }

                entityConfiguration.BlueprintId = BlueprintIdSelection(
                    label,
                    entityConfiguration.BlueprintId,
                    inspectorTypeTable,
                    blueprintManager);

                if (!string.IsNullOrEmpty(entityConfiguration.BlueprintId))
                {
                    Blueprint blueprint = blueprintManager.GetBlueprint(entityConfiguration.BlueprintId);
                    if (blueprint != null)
                    {
                        if (entityConfiguration.Configuration == null)
                        {
                            entityConfiguration.Configuration = new AttributeTable();
                        }

                        ++EditorGUI.indentLevel;
                        BlueprintComponentsField(
                            blueprint,
                            entityConfiguration.Configuration,
                            inspectorTypeTable,
                            blueprintManager);
                        --EditorGUI.indentLevel;
                    }
                }

                return(entityConfiguration);
            }

            EditorGUILayout.HelpBox(
                string.Format(
                    "No inspector found for property {0} of type {1}.",
                    inspectorProperty.Name,
                    inspectorProperty.PropertyType),
                MessageType.Warning);
            return(currentValue);
        }
        /// <summary>
        ///   Gets the current value of the specified property for the passed blueprint,
        ///   taking into account, in order: Blueprint attribute table, parents, default value.
        /// </summary>
        /// <param name="property">Property to get the current value of.</param>
        /// <returns>Current value of the specified property for the passed blueprint.</returns>
        private object GetCurrentAttributeValue(InspectorPropertyAttribute property, out bool inherited)
        {
            BlueprintViewModel viewModel = (BlueprintViewModel)this.DataContext;

            return(viewModel.GetCurrentAttributeValue(property.Name, out inherited));
        }
        private void OnPropertyControlValueChanged(InspectorPropertyAttribute inspectorProperty, object newValue)
        {
            BlueprintViewModel viewModel = (BlueprintViewModel)this.DataContext;

            viewModel.SetAttributeValue(inspectorProperty.Name, newValue);
        }