/// <summary> /// Creates a new subitem which can show a property on the node. /// </summary> /// <param name="owner">The node whose property we want to show. MUST be the same as the one the subitem belongs to.</param> /// <param name="property">The property we want to show.</param> /// <param name="att">The attribute associated with the property.</param> public SubItemProperty(Node owner, PropertyInfo property, DesignerProperty att) : base(null, null, __font, Brushes.White, Alignment.Center, false) { _owner = owner; _property = property; _attribute = att; }
public DesignerPropertyInfo(PropertyInfo property) { _property = property; DesignerProperty[] attributes = (DesignerProperty[])_property.GetCustomAttributes(typeof(DesignerProperty), true); if (attributes.Length != 1) { throw new Exception(Resources.ExceptionMultipleDesignerAttributes); } _attribute = attributes[0]; }
private void updateStructProperties(object owner) { IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(_structProperty.Type, DesignerProperty.SortByDisplayOrder); List <string> categories = new List <string>(); foreach (DesignerPropertyInfo property in properties) { if (!categories.Contains(property.Attribute.CategoryResourceString)) { categories.Add(property.Attribute.CategoryResourceString); } } categories.Sort(); foreach (string category in categories) { if (categories.Count > 1) { propertyGrid.AddCategory(Plugin.GetResourceString(category), true); } foreach (DesignerPropertyInfo property in properties) { if (property.Attribute.CategoryResourceString == category) { object member = property.GetValue(owner); Type type = property.Attribute.GetEditorType(member); Label label = propertyGrid.AddProperty(property.Attribute.DisplayName, type, property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly)); label.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); label.MouseEnter += new EventHandler(label_MouseEnter); if (type != null) { DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.SetRootNode(this._node); editor.SetProperty(property, owner); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.ValueWasChanged += editor_ValueWasChanged; } } } } if (properties.Count > 0) { propertyGrid.UpdateSizes(); propertyGrid.PropertiesVisible(true, true); } }
public static bool IsPureConstDatum(object obj, object parent, string paramName) { Debug.Check(obj != null); if (obj != null) { Type type = obj.GetType(); if (!Plugin.IsCustomClassType(type)) { return(false); } MethodDef method = parent as MethodDef; IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type, null); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave)) { object member = property.GetValue(obj); if (property.Attribute is DesignerStruct) { if (!IsPureConstDatum(member, parent, paramName)) { return(false); } } else { if (method != null) { MethodDef.Param param = method.GetParam(paramName, property); if (param != null) { if (!param.IsPureConstDatum) { return(false); } } } } } } } return(true); }
private string getExportValue(object item, Type itemType) { string str = string.Empty; if (item != null) { IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(itemType); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave)) { str += property.Property.Name + "=" + property.GetExportValue(item) + ";"; } } } return(str); }
private static bool getPropertyInfo(Type type, string propertyName, out DesignerPropertyInfo p) { IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave) && property.Property.Name == propertyName) { p = property; return(true); } } p = new DesignerPropertyInfo(); //throw new Exception(Resources.ExceptionDesignerAttributeInvalidType); return(false); }
public void SetupCastSettings(object obj) { if (obj != null && obj is Behaviac.Design.Nodes.Node) { Behaviac.Design.Nodes.Node assignNode = obj as Behaviac.Design.Nodes.Node; if (assignNode != null) { bool bCasting = assignNode.IsCasting; if (bCasting) { DesignerPropertyInfo leftPropInfo = DesignerProperty.GetDesignerProperty(assignNode.GetType(), "Opl"); VariableDef opl = (VariableDef)leftPropInfo.GetValue(assignNode); Type leftType = opl.ValueType; // if number if (Plugin.IsIntergerNumberType(leftType) || Plugin.IsFloatType(leftType)) { this.ValueType = ValueTypes.Int | ValueTypes.Float; this.FilterType = null; } else if (Plugin.IsRefType(leftType)) { //ref type/pointer type this.ValueType = ValueTypes.RefType; this.FilterType = leftType; } else { // } } } } }
/// <summary> /// Returns the property this one is linked to. /// </summary> /// <param name="linkBroken">Is true if a link was found but it does not work.</param> /// <returns>The info of the property this is linked to.</returns> public DesignerPropertyInfo GetLinkedProperty(object obj, out bool linkBroken) { linkBroken = false; if (string.IsNullOrEmpty(_linkedToProperty)) { return(new DesignerPropertyInfo()); } DesignerPropertyInfo dpi = DesignerProperty.GetDesignerProperty(obj.GetType(), _linkedToProperty); // if we are linked to a DesignerNodeProperty we get the information of its assigned property DesignerNodeProperty dnp = dpi.Attribute as DesignerNodeProperty; if (dnp == null) { return(dpi); } Attachments.Attachment attach = (Attachments.Attachment)obj; // check if a valid property is associated object objvalue = dpi.Property.GetValue(obj, null); string value = dnp.GetDisplayValue(objvalue); if (string.IsNullOrEmpty(value) || value == Resources.DesignerNodePropertyNone) { linkBroken = true; return(new DesignerPropertyInfo()); } // return the property we are pointing at return(DesignerProperty.GetDesignerProperty(attach.Node.GetType(), value)); }
private void updateStructProperties(object owner) { IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(_structProperty.Type, DesignerProperty.SortByDisplayOrder); List <string> categories = new List <string>(); foreach (DesignerPropertyInfo property in properties) { if (!categories.Contains(property.Attribute.CategoryResourceString)) { categories.Add(property.Attribute.CategoryResourceString); } } categories.Sort(); UIObject uiObj = owner as UIObject; if (uiObj != null) { uiPolicy = uiObj.CreateUIPolicy(); uiPolicy.Initialize(uiObj); } foreach (string category in categories) { if (categories.Count > 1) { propertyGrid.AddCategory(Plugin.GetResourceString(category), true); } foreach (DesignerPropertyInfo property in properties) { if (property.Attribute.CategoryResourceString == category) { if (uiPolicy != null && !uiPolicy.ShouldAddProperty(property)) { continue; } object member = property.GetValue(owner); Type type = property.Attribute.GetEditorType(member); DesignerMethodEnum propertyMethod = property.Attribute as DesignerMethodEnum; if (propertyMethod != null) { if ((propertyMethod.MethodType & MethodType.Task) == MethodType.Task) { type = typeof(DesignerMethodEnumEditor); } } string displayName = property.Attribute.DisplayName; if (uiPolicy != null) { displayName = uiPolicy.GetLabel(property); } Label label = propertyGrid.AddProperty(displayName, type, property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly)); label.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); label.MouseEnter += new EventHandler(label_MouseEnter); if (type != null) { DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.SetRootNode(this._node); editor.SetProperty(property, owner); editor.ValueWasAssigned(); editor.MouseEnter += editor_MouseEnter; editor.ValueWasChanged += editor_ValueWasChanged; if (uiPolicy != null) { uiPolicy.AddEditor(editor); } } MethodDef method = null; if (propertyMethod != null) { if (propertyMethod.MethodType != MethodType.Status) { method = member as MethodDef; } } else { DesignerRightValueEnum propertyRV = property.Attribute as DesignerRightValueEnum; if (propertyRV != null) { RightValueDef rv = member as RightValueDef; if (rv != null && rv.IsMethod) { method = rv.Method; } } } if (property.Attribute != null) { if (method != null) { if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplayOnProperty)) { //don't dipslay on the property panel } else { bool bReadonly = property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnlyParams); createParamEditor(owner, method, true, bReadonly); } } else { MethodDef.Param arrayIndexElement = null; if (member is VariableDef) { VariableDef var = member as VariableDef; arrayIndexElement = var.ArrayIndexElement; } else if (member is RightValueDef) { RightValueDef varRV = member as RightValueDef; if (varRV.Var != null) { arrayIndexElement = varRV.Var.ArrayIndexElement; } } if (arrayIndexElement != null) { createArrayIndexEditor(owner, " ", arrayIndexElement); } } } } } } if (uiPolicy != null) { uiPolicy.Update(null, new DesignerPropertyInfo()); } if (properties.Count > 0) { propertyGrid.UpdateSizes(); propertyGrid.PropertiesVisible(true, true); } }
public DesignerPropertyInfo(PropertyInfo property, DesignerProperty attribute) { _property = property; _attribute = attribute; }
public Param(Param other) { _paramInfo = other._paramInfo; _attribute = other._attribute; _nativeType = other._nativeType; _displayName = other._displayName; _description = other._description; _value = Plugin.CloneValue(other._value); }
public Param(Param other) { _paramInfo = other._paramInfo; _attribute = other._attribute; _nativeType = other._nativeType; _displayName = other._displayName; _description = other._description; _name = other._name; _type = other._type; _isOut = other._isOut; _isRef = other._isRef; _value = Plugin.CloneValue(other._value); _isArrayIndex = other._isArrayIndex; }
public Param(DesignerPropertyInfo property, object obj) { _paramInfo = null; _property = property; _object = obj; _value = property.GetValue(obj); _nativeType = (_value != null) ? Plugin.GetNativeTypeName(_value.GetType()) : string.Empty; DesignerProperty pattr = property.Attribute; _displayName = pattr.DisplayName; _description = pattr.Description; _attribute = pattr; _bParamFromStruct = true; }
public Param(string category, ParameterInfo pi, object v, string nativeType, string displayName, string description, bool isOut, bool isRef, float rangeMin, float rangeMax) { _paramInfo = pi; _value = v; _nativeType = nativeType; _isOut = isOut; _isRef = isRef; _displayName = displayName; _description = description; if (_paramInfo != null) { DesignerProperty attr = null; DesignerProperty[] attributes = (DesignerProperty[])_paramInfo.GetCustomAttributes(typeof(DesignerProperty), false); if (attributes.Length > 0) { attr = attributes[0]; } if (attr != null) { _attribute = attr; } else if (_paramInfo.ParameterType.IsEnum) { _attribute = new DesignerEnum(_paramInfo.Name, "", category, DesignerProperty.DisplayMode.Parameter, 0, DesignerProperty.DesignerFlags.NoFlags, ""); } else { _attribute = Plugin.InvokeTypeCreateDesignerProperty(category, _paramInfo.Name, _paramInfo.ParameterType, rangeMin, rangeMax); if (_attribute != null) { Type listType = Plugin.GetType("XMLPluginBehaviac.IList"); if ((Plugin.IsArrayType(pi.ParameterType) || pi.ParameterType == listType || pi.ParameterType == typeof(IList<>))) { _attribute.ValueType = ValueTypes.Array; } } } } }
public static string RetrieveExportValue(object obj, object parent, string paramName, bool bSave, int indexInArray = -1) { string str = ""; Debug.Check(obj != null); Type type = obj.GetType(); if (Plugin.IsRefType(type)) { return("null"); } bool bStructAsBasic = Plugin.IsRegisteredTypeName(type.Name); //struct as basic type, like Tag::Vector3, etc. //these types are exported as (W=0 X=0 Y=0 Z=0) if (!bSave && bStructAsBasic) { str = "("; } else { str = "{"; } if (Plugin.IsCustomClassType(type)) { MethodDef method = parent as MethodDef; bool bFirst = true; IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave)) { if (!bSave && bStructAsBasic && !bFirst) { str += " "; } bFirst = false; if (!bSave) { if (bStructAsBasic) { str += property.Property.Name + "="; } } else { str += property.Property.Name + "="; } object member = property.GetValue(obj); Type memberType = null; if (member != null) { memberType = member.GetType(); } else { memberType = property.GetTypeFallback(); } if (Plugin.IsArrayType(memberType)) { str += DesignerArray.RetrieveExportValue(member); } else { if (property.Attribute is DesignerStruct) { str += RetrieveExportValue(member, parent, paramName, bSave); } else { bool bStructProperty = false; if (method != null) { MethodDef.Param param = method.GetParam(paramName, property, indexInArray); if (param != null) { bStructProperty = true; string s = param.GetExportValue(null); if (Plugin.IsStringType(param.Value.GetType())) { str += string.Format("\"{0}\"", s); } else { str += s; } } } if (!bStructProperty) { string s = property.GetExportValue(obj); if (Plugin.IsStringType(property.Property.PropertyType)) { str += string.Format("\"{0}\"", s); } else { str += s; } } } } if (!bSave && bStructAsBasic) { } else { str += ";"; } } } } else { } if (!bSave && bStructAsBasic) { str += ")"; } else { str += "}"; } return(str); }
// Customized Parameter public Param(string name, Type type, string nativeName, string displayName, string description) { _name = name; _type = type; _nativeType = Plugin.GetNativeTypeName(type); _displayName = displayName; _description = description; if (_type != null) { _attribute = Plugin.InvokeTypeCreateDesignerProperty("Arguments", _name, _type, float.MinValue, float.MaxValue); _value = Plugin.DefaultValue(_type); } }
public Param(string category, ParameterInfo pi, object v, string nativeType, string displayName, string description, float rangeMin, float rangeMax) { _paramInfo = pi; _value = v; _nativeType = nativeType; _displayName = displayName; _description = description; if (_paramInfo != null) { DesignerProperty attr = null; DesignerProperty[] attributes = (DesignerProperty[])_paramInfo.GetCustomAttributes(typeof(DesignerProperty), false); if (attributes.Length > 0) attr = attributes[0]; if (attr != null) _attribute = attr; else if (_paramInfo.ParameterType.IsEnum) _attribute = new DesignerEnum(_paramInfo.Name, "", category, DesignerProperty.DisplayMode.Parameter, 0, DesignerProperty.DesignerFlags.NoFlags, ""); else { _attribute = Plugin.InvokeTypeCreateDesignerProperty(category, _paramInfo.Name, _paramInfo.ParameterType, rangeMin, rangeMax); } } }