示例#1
0
 public ConfigElement(PropertyFieldWrapper memberInfo, object item, IList array)
 {
     Width.Set(0f, 1f);
     Height.Set(30f, 0f);
     this.memberInfo           = memberInfo;
     this.item                 = item;
     this.array                = array;
     this.backgroundColor      = UICommon.defaultUIBlue;
     this._TextDisplayFunction = () => memberInfo.Name;
     labelAttribute            = ConfigManager.GetCustomAttribute <LabelAttribute>(memberInfo, item, array);
     if (labelAttribute != null)
     {
         this._TextDisplayFunction = () => labelAttribute.Label;
     }
     tooltipAttribute = ConfigManager.GetCustomAttribute <TooltipAttribute>(memberInfo, item, array);
     if (tooltipAttribute != null)
     {
         this._TooltipFunction = () => tooltipAttribute.Tooltip;
     }
     backgroundColorAttribute = ConfigManager.GetCustomAttribute <BackgroundColorAttribute>(memberInfo, item, array);
     if (backgroundColorAttribute != null)
     {
         backgroundColor = backgroundColorAttribute.color;
     }
     rangeAttribute     = ConfigManager.GetCustomAttribute <RangeAttribute>(memberInfo, item, array);
     incrementAttribute = ConfigManager.GetCustomAttribute <IncrementAttribute>(memberInfo, item, array);
 }
示例#2
0
        public void IdAttribute_InitializingConstructor()
        {
            const string Label = "test label";

            _labelAttribute = new LabelAttribute(Label);
            Assert.AreEqual(Label, _labelAttribute.Value);
        }
示例#3
0
 public LabelControl(LabelAttribute attribute)
 {
     InitializeComponent();
     Label.Content = attribute.Label;
     this.SetValue(Grid.RowProperty, attribute.Row);
     this.SetValue(Grid.ColumnProperty, attribute.Column);
     this.SetValue(Grid.ColumnSpanProperty, attribute.ColumnSpan);
 }
示例#4
0
        public static string GetLabel(this SerializedProperty self)
        {
            LabelAttribute labelAttribute = self.GetAttribute <LabelAttribute>();

            return((labelAttribute == null)
                                ? self.displayName
                                : labelAttribute.OverriddenLabel);
        }
        public static string GetLabel(SerializedProperty property)
        {
            LabelAttribute labelAttribute = GetAttribute <LabelAttribute>(property);

            return((labelAttribute == null)
                                ? property.displayName
                                : labelAttribute.Label);
        }
示例#6
0
        public void GivenStringAttribute_ThenReturnsProperRecordForIt()
        {
            LabelAttribute la       = new LabelAttribute("b");
            DotHelper      dh       = new DotHelper();
            string         record   = dh.GetRecordFromAttribute(la);
            string         expected = la.Key + "=b";

            Assert.Equal(expected, record);
        }
示例#7
0
        public static GUIContent GetLabel(LabelAttribute labelAttribute, SerializedProperty property)
        {
            string labelText = (labelAttribute == null)
                                ? property.displayName
                                : labelAttribute.Label;

            GUIContent label = new GUIContent(labelText);

            return(label);
        }
示例#8
0
        public void Label_should_be_valid()
        {
            //arrange
            var label = new LabelAttribute("label");

            //act
            var result = label.IsValid(null);

            //assert
            Assert.IsTrue(result);
        }
示例#9
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Rect labelPos = new Rect(new Vector2(position.x + 210, position.y + 10),
                                 position.size);
        LabelAttribute labelAttribute = attribute as LabelAttribute;
        GUIContent     labelContent   = new GUIContent(labelAttribute.label);

        base.OnGUI(position, property, label);
        EditorGUI.BeginProperty(labelPos, labelContent, property);
        EditorGUI.LabelField(labelPos, labelAttribute.label);
        EditorGUI.EndProperty();
    }
示例#10
0
    private bool GetConditionalHideAttributeResult(LabelAttribute condHAtt, SerializedProperty property)
    {
        bool               enabled             = true;
        string             propertyPath        = property.propertyPath;
        string             conditionPath       = propertyPath.Replace(property.name, condHAtt.ConditionalSourceField);
        SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(conditionPath);

        if (sourcePropertyValue != null)
        {
            enabled = sourcePropertyValue.boolValue;
        }
        return(enabled == condHAtt.condictionValue);
    }
示例#11
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        LabelAttribute condHAtt = (LabelAttribute)attribute;
        bool           enabled  = GetConditionalHideAttributeResult(condHAtt, property);

        if (enabled)
        {
            return(EditorGUI.GetPropertyHeight(property, label));
        }
        else
        {
            return(0.1f);
        }
    }
示例#12
0
        public void GivenAttributeWithNullValue_ThenDoesntEnumerateIt()
        {
            UrlAttribute   a1 = new UrlAttribute("abc");
            LabelAttribute a2 = new LabelAttribute("xyz");

            IAttrSet set = AttrSet.Empty.Add(a1).Add(a2);

            Assert.Equal(new IAttribute[] { a1, a2 }, set);

            UrlAttribute a3 = new UrlAttribute(null);

            set = set.Add(a3);

            Assert.Equal(new IAttribute[] { a2 }, set);
        }
示例#13
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        //get the attribute data
        LabelAttribute condHAtt = (LabelAttribute)attribute;
        //check if the propery we want to draw should be enabled
        bool enabled = GetConditionalHideAttributeResult(condHAtt, property);

        if (enabled)
        {
            return(base.GetPropertyHeight(property, label));
        }
        else
        {
            return(0.1f);
        }
    }
示例#14
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //get the attribute data
        LabelAttribute condHAtt = (LabelAttribute)attribute;
        //check if the propery we want to draw should be enabled
        bool enabled = true;

        if (condHAtt.ctrlByParam)
        {
            enabled = GetConditionalHideAttributeResult(condHAtt, property);
        }

        //Enable/disable the property
        bool wasEnabled = GUI.enabled;

        GUI.enabled = enabled;

        //Check if we should draw the property
        if (enabled)
        {
            label.text = condHAtt.Label;


            if (condHAtt.condiction)
            {
                if (property.propertyType == SerializedPropertyType.Float)
                {
                    EditorGUI.Slider(position, property, condHAtt.min, condHAtt.max, label);
                }
                else if (property.propertyType == SerializedPropertyType.Integer)
                {
                    EditorGUI.IntSlider(position, property, (int)condHAtt.min, (int)condHAtt.max, label);
                }
                else
                {
                    EditorGUI.PropertyField(position, property, label, true);
                }
            }
            else
            {
                EditorGUI.PropertyField(position, property, label, true);
            }
        }

        //Ensure that the next property that is being drawn uses the correct settings
        GUI.enabled = wasEnabled;
    }
示例#15
0
        /// <summary>
        /// Generates the labeled list for the enum type.
        /// </summary>
        static private NamedItemList <Enum> CreateLabeledList(Type inType, bool inbSorted = false)
        {
            NamedItemList <Enum> itemList = new NamedItemList <Enum>();

            foreach (var field in inType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                if (field.IsDefined(typeof(HiddenAttribute)) || field.IsDefined(typeof(ObsoleteAttribute)))
                {
                    continue;
                }

                LabelAttribute labeledAttr = (LabelAttribute)field.GetCustomAttribute(typeof(LabelAttribute));
                OrderAttribute orderAttr   = (OrderAttribute)field.GetCustomAttribute(typeof(OrderAttribute));

                string name;
                int    order;
                Enum   val = (Enum)field.GetValue(null);

                if (labeledAttr != null)
                {
                    name = labeledAttr.Name;
                }
                else
                {
                    name = ObjectNames.NicifyVariableName(val.ToString());
                }

                if (orderAttr != null)
                {
                    order = orderAttr.Order;
                }
                else if (inbSorted)
                {
                    order = 100;
                }
                else
                {
                    order = Convert.ToInt32(val);
                }

                itemList.Add(val, name, order);
            }
            return(itemList);
        }
示例#16
0
    public static string GetLabel(this ECategory value)
    {
        Type   type = value.GetType();
        string name = Enum.GetName(type, value);

        if (name != null)
        {
            FieldInfo field = type.GetField(name);
            if (field != null)
            {
                LabelAttribute attr = Attribute.GetCustomAttribute(field, typeof(LabelAttribute)) as LabelAttribute;
                if (attr != null)
                {
                    return(attr.Name);
                }
            }
        }
        return(null);
    }
示例#17
0
    private bool GetConditionalHideAttributeResult(LabelAttribute condHAtt, SerializedProperty property)
    {
        bool enabled = true;
        //Look for the sourcefield within the object that the property belongs to
        string             propertyPath        = property.propertyPath;                                                //returns the property path of the property we want to apply the attribute to
        string             conditionPath       = propertyPath.Replace(property.name, condHAtt.ConditionalSourceField); //changes the path to the conditionalsource property path
        SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(conditionPath);

        if (sourcePropertyValue != null)
        {
            enabled = sourcePropertyValue.boolValue;
        }
        else
        {
            Debug.LogWarning("Attempting to use a ConditionalLabelAttribute but no matching SourcePropertyValue found in object: " + condHAtt.ConditionalSourceField);
        }

        return(enabled);
    }
            public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
            {
                LabelAttribute labelAtt = (LabelAttribute)attribute;

                string content;

                if (property.propertyType == SerializedPropertyType.String)
                {
                    content = property.stringValue;
                }
                else if (property.propertyType == SerializedPropertyType.Integer)
                {
                    content = property.intValue.ToString();
                }
                else if (property.propertyType == SerializedPropertyType.Float)
                {
                    content = property.floatValue.ToString();
                }
                else
                {
                    content = "Use Label with string, int and float values only.";
                }

                GUIStyle style = GUIHelper.GUIStyleFromLabelStyle(labelAtt.style);

                //store font size before
                int fontSize = style.fontSize;

                //set size
                if (labelAtt.textSize != TextSize.normal)
                {
                    style.fontSize = (int)labelAtt.textSize;
                }

                EditorGUI.LabelField(position, content, style);

                //set size
                if (labelAtt.textSize != TextSize.normal)
                {
                    style.fontSize = fontSize;
                }
            }
示例#19
0
 public virtual void OnBind()
 {
     TextDisplayFunction = () => memberInfo.Name;
     labelAttribute      = ConfigManager.GetCustomAttribute <LabelAttribute>(memberInfo, item, list);
     if (labelAttribute != null)
     {
         TextDisplayFunction = () => labelAttribute.Label;
     }
     tooltipAttribute = ConfigManager.GetCustomAttribute <TooltipAttribute>(memberInfo, item, list);
     if (tooltipAttribute != null)
     {
         this.TooltipFunction = () => tooltipAttribute.Tooltip;
     }
     backgroundColorAttribute = ConfigManager.GetCustomAttribute <BackgroundColorAttribute>(memberInfo, item, list);
     if (backgroundColorAttribute != null)
     {
         backgroundColor = backgroundColorAttribute.color;
     }
     rangeAttribute     = ConfigManager.GetCustomAttribute <RangeAttribute>(memberInfo, item, list);
     incrementAttribute = ConfigManager.GetCustomAttribute <IncrementAttribute>(memberInfo, item, list);
 }
示例#20
0
    private bool GetConditionalHideAttributeResult(LabelAttribute condHAtt, SerializedProperty property)
    {
        if (condHAtt.conditionalSourceField.Length <= 0)
        {
            return(true);
        }
        bool enabled = true;
        //Look for the sourcefield within the object that the property belongs to
        string propertyPath = property.propertyPath; //returns the property path of the property we want to apply the attribute to

        string conditionPath = propertyPath;
        int    index         = conditionPath.LastIndexOf(".");

        if (index > 0)
        {
            conditionPath = conditionPath.Substring(0, index + 1) + condHAtt.conditionalSourceField;
        }
        else
        {
            conditionPath = condHAtt.conditionalSourceField;
        }

        //string conditionPath = propertyPath.Replace(property.name, condHAtt.conditionalSourceField); //changes the path to the conditionalsource property path

        SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(conditionPath);

        if (sourcePropertyValue != null)
        {
            enabled = sourcePropertyValue.boolValue;
        }

        /*else
         * {
         * Debug.LogWarning("Attempting to use a ConditionalLabelAttribute but no matching SourcePropertyValue found in object: " + condHAtt.ConditionalSourceField);
         * }*/

        return(enabled);
    }
示例#21
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        LabelAttribute range = attribute as LabelAttribute;

        label.text = range.label;
        bool disableSlider = (range.min == range.max && range.max == -10000);

        if (!disableSlider)
        {
            if (property.propertyType == SerializedPropertyType.Float)
            {
                EditorGUI.Slider(position, property, range.min, range.max, label);
            }
            else if (property.propertyType == SerializedPropertyType.Integer)
            {
                EditorGUI.IntSlider(position, property, (int)range.min, (int)range.max, label);
            }
        }
        else
        {
            EditorGUI.PropertyField(position, property, label);
        }
    }
示例#22
0
        /// <summary>
        /// Generates the flag mapping for the given enum type.
        /// </summary>
        static private void CreateFlagMapping(Type inType, NamedItemList <Enum> inLabeledList, out string[] outFlagNames, out FlagMapping[] outMapping)
        {
            List <FlagMapping> mappings;
            List <string>      names;

            if (inLabeledList != null)
            {
                int labeledCount = inLabeledList.Count;
                names    = new List <string>(labeledCount);
                mappings = new List <FlagMapping>(labeledCount);

                for (int i = 0; i < inLabeledList.Count; ++i)
                {
                    Enum val    = inLabeledList.Get(i);
                    int  input  = Convert.ToInt32(val);
                    int  output = 1 << mappings.Count;

                    if (Mathf.IsPowerOfTwo(input))
                    {
                        names.Add(inLabeledList.SortedStrings() [i]);
                        mappings.Add(new FlagMapping(input, output));
                    }
                }
            }
            else
            {
                FieldInfo[] fields     = inType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly);
                int         fieldCount = fields.Length;

                names    = new List <string>(fieldCount);
                mappings = new List <FlagMapping>(fieldCount);

                for (int i = 0; i < fieldCount; ++i)
                {
                    FieldInfo field = fields[i];

                    if (field.IsDefined(typeof(HiddenAttribute)) || field.IsDefined(typeof(ObsoleteAttribute)))
                    {
                        continue;
                    }

                    LabelAttribute labeledAttr = (LabelAttribute)field.GetCustomAttribute(typeof(LabelAttribute));

                    string name;
                    Enum   val = (Enum)field.GetValue(null);

                    if (labeledAttr != null)
                    {
                        name = labeledAttr.Name;
                    }
                    else
                    {
                        name = ObjectNames.NicifyVariableName(val.ToString());
                    }

                    int input  = Convert.ToInt32(val);
                    int output = 1 << mappings.Count;

                    if (Mathf.IsPowerOfTwo(input))
                    {
                        names.Add(name);
                        mappings.Add(new FlagMapping(input, output));
                    }
                }
            }

            outFlagNames = names.ToArray();
            outMapping   = mappings.ToArray();
        }
示例#23
0
 public AccountTypeItem(AccountTypes value)
 {
     _value = value;
     _label = LabelAttribute.GetLabel(value);
     _defaultBudgetingType = DefaultBudgetingAttribute.GetDefaultBudgetingType(value);
 }
示例#24
0
        void BuildControl(Grid grid, AbstractMember member, PluginConfigurationOptions pluginConfigurationOptions)
        {
            Control control = null;

            object[] attributes = member.GetAttributes();

            if (attributes == null || attributes.Length == 0)
            {
                return;
            }

            LabelAttribute labelAttribute = attributes.Select(x => x as LabelAttribute).Where(i => i != null).First();

            bool isBool   = member.Type == typeof(bool);
            bool isString = member.Type == typeof(string);
            bool isChoice = attributes.FirstOrDefault(x => x is ItemsAttribute) != null;

            if (isBool)
            {
                control = new CheckBox()
                {
                    VerticalAlignment = VerticalAlignment.Center, IsChecked = (bool)member.Read(pluginConfigurationOptions), Name = member.Name
                };
                (control as CheckBox).Checked   += new RoutedEventHandler(PluginConfigureView_Checked);
                (control as CheckBox).Unchecked += new RoutedEventHandler(PluginConfigureView_Checked);
            }
            else if (isChoice)
            {
                control = new ComboBox()
                {
                    Margin = new Thickness(0, 2, 0, 2), Name = member.Name, Width = 200
                };
                (control as ComboBox).SelectionChanged += new SelectionChangedEventHandler(PluginConfigureView_SelectionChanged);
                ItemsAttribute itemsAttribute = attributes.Select(x => x as ItemsAttribute).Where(i => i != null).First();
                foreach (var item in itemsAttribute.Items.Split(','))
                {
                    (control as ComboBox).Items.Add(item);
                }
                (control as ComboBox).Text = (string)member.Read(pluginConfigurationOptions);
            }
            else if (isString)
            {
                control = new TextBox()
                {
                    Margin = new Thickness(0, 2, 0, 2), Text = (string)member.Read(pluginConfigurationOptions), Name = member.Name, Width = 200
                };
                (control as TextBox).TextChanged += new TextChangedEventHandler(PluginConfigureView_TextChanged);
            }
            else
            {
                return;
            }

            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(30)
            });
            Label label = new Label()
            {
                Margin = new Thickness(0, 0, 10, 0), HorizontalAlignment = HorizontalAlignment.Right, Content = labelAttribute.Label
            };

            grid.Children.Add(label);
            Grid.SetColumn(label, 0);
            Grid.SetRow(label, grid.RowDefinitions.Count - 1);
            grid.Children.Add(control);
            Grid.SetColumn(control, 1);
            Grid.SetRow(control, grid.RowDefinitions.Count - 1);
            _controlBindings.Add(control, member);
        }
示例#25
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        LabelAttribute a = attribute as LabelAttribute;

        EditorGUI.PropertyField(position, property, a.label);
    }
示例#26
0
        static public bool PropertyField(FieldInfo p_fieldInfo, Object p_object, IReferencable p_reference, FieldInfo p_parentInfo = null)
        //string p_name = null, bool p_drawLabel = true)
        {
            if (IsHidden(p_fieldInfo))
            {
                return(false);
            }

            if (!MeetsDependencies(p_fieldInfo, p_object))
            {
                return(false);
            }

            FieldInfo nameInfo = p_parentInfo != null ? p_parentInfo : p_fieldInfo;

            LabelAttribute labelAttribute = nameInfo.GetCustomAttribute <LabelAttribute>();
            string         nameString     = ObjectNames.NicifyVariableName(nameInfo.Name);

            nameString = labelAttribute == null
                ? nameString.Substring(0, 1).ToUpper() + nameString.Substring(1)
                : labelAttribute.Label;

            TooltipAttribute tooltipAttribute = nameInfo.GetCustomAttribute <TooltipAttribute>();
            var name = tooltipAttribute == null ? new GUIContent(nameString) : new GUIContent(nameString, tooltipAttribute.tooltip);

            if (IsParameterProperty(p_fieldInfo))
            {
                return(ParameterProperty(p_fieldInfo, p_object, name, p_reference));
            }

            if (p_parentInfo == null && IsExpressionProperty(p_fieldInfo))
            {
                return(ExpressionProperty(p_fieldInfo, p_object, name, p_reference));
            }

            if (IsPopupProperty(p_fieldInfo))
            {
                return(PopupProperty(p_fieldInfo, p_object, name));
            }

            if (p_fieldInfo.FieldType == typeof(Type))
            {
                return(SupportedTypeProperty(p_fieldInfo, p_object, name));
            }

            if (IsEnumProperty(p_fieldInfo))
            {
                return(EnumProperty(p_fieldInfo, p_object, name));
            }

            if (IsUnityObjectProperty(p_fieldInfo))
            {
                return(UnityObjectProperty(p_fieldInfo, p_object, name));
            }

            if (IsExposedReferenceProperty(p_fieldInfo))
            {
                return(ExposedReferenceProperty(p_fieldInfo, p_object, name, p_reference));
            }

            return(ValueProperty(p_fieldInfo, p_object, name, p_reference, p_parentInfo));
        }
示例#27
0
 public void IdAttribute_InitializingConstructorWithNull()
 {
     _labelAttribute = new LabelAttribute(null);
     Assert.IsNull(_labelAttribute.Value);
 }
示例#28
0
            public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
            {
                LabelAttribute labelAttrib = this.attribute as LabelAttribute;

                EditorGUI.PropertyField(position, property, new GUIContent(labelAttrib.label));
            }
示例#29
0
    protected void SetLabel(GUIContent label)
    {
        LabelAttribute labelAttribute = attribute as LabelAttribute;

        label.text = labelAttribute.label;
    }
示例#30
0
 public BudgetingTypeItem(BudgetingTypes value)
 {
     _value = value;
     _label = LabelAttribute.GetLabel(value);
 }