示例#1
0
        public static object FromString(EditorPropertyType type, string value)
        {
            if (type == EditorPropertyType.String)
                return value;
            #if !(RELEASE && RELEASE_DISABLE_CHECKS)
            if (value == null)
                throw new System.ArgumentNullException("value");
            if (value.Length < 1)
                throw new System.ArgumentException("value string was empty");
            #endif

            switch (type)
            {
                case EditorPropertyType.Bool:
                    {
                        if (value == "0")
                            value = "false";
                        else if (value == "1")
                            value = "true";

                        return bool.Parse(value);
                    }
                case EditorPropertyType.Int:
                    return int.Parse(value);
                case EditorPropertyType.Float:
                    return float.Parse(value);
                case EditorPropertyType.Vec3:
                    return Vec3.Parse(value);
            }

            return null;
        }
示例#2
0
        public EditorProperty(string Name, string Desc, EditorPropertyType Type)
            : this()
        {
            name        = Name;
            description = Desc;

            type = Type;
        }
示例#3
0
        public EditorProperty(string Name, string Desc, EditorPropertyType Type)
            : this()
        {
            name = Name;
            description = Desc;

            type = Type;
        }
示例#4
0
        public EditorProperty(string Name, string Desc, string DefaultValue, EditorPropertyType Type)
            : this()
        {
            name = Name;
            description = Desc;
            defaultValue = DefaultValue;

            type = Type;
        }
示例#5
0
        /// <summary>
        /// Initializes new instance of type <see cref="EditorProperty" />.
        /// </summary>
        /// <param name="name">         Name of the property. </param>
        /// <param name="description">  Description of the property. </param>
        /// <param name="defaultValue"> Default value of the property. </param>
        /// <param name="type">         Type of the property. </param>
        public EditorProperty(string name, string description, string defaultValue, EditorPropertyType type)
            : this()
        {
            this.Name         = name;
            this.Description  = description;
            this.DefaultValue = defaultValue;

            this.Type = type;
        }
示例#6
0
        public EditorProperty(string Name, string Desc, string DefaultValue, EditorPropertyType Type)
            : this()
        {
            name         = Name;
            description  = Desc;
            defaultValue = DefaultValue;

            type = Type;
        }
示例#7
0
文件: Entity.cs 项目: yonder/CryMono
        public static EditorPropertyType GetEditorType(Type type, EditorPropertyType propertyType)
        {
            //If a special type is needed, do this here.
            switch (propertyType)
            {
            case EditorPropertyType.Object:
            case EditorPropertyType.Texture:
            case EditorPropertyType.File:
            case EditorPropertyType.Sound:
            case EditorPropertyType.Dialogue:
            case EditorPropertyType.Sequence:
            {
                if (type == typeof(string))
                {
                    return(propertyType);
                }

                throw new EntityException("File selector type was specified, but property was not a string.");
            }

            case EditorPropertyType.Color:
            {
                if (type == typeof(Vec3))
                {
                    return(propertyType);
                }

                throw new EntityException("Vector type was specified, but property was not a vector.");
            }
            }

            //OH PROGRAMMING GODS, FORGIVE ME
            if (type == typeof(string))
            {
                return(EditorPropertyType.String);
            }
            if (type == typeof(int))
            {
                return(EditorPropertyType.Int);
            }
            if (type == typeof(float) || type == typeof(double))
            {
                return(EditorPropertyType.Float);
            }
            if (type == typeof(bool))
            {
                return(EditorPropertyType.Bool);
            }
            if (type == typeof(Vec3))
            {
                return(EditorPropertyType.Vec3);
            }

            throw new EntityException("Invalid property type specified.");
        }
示例#8
0
        public EditorProperty(string Name, string Desc, string DefaultValue, EditorPropertyType Type, EditorPropertyLimits Limits, int Flags = 0)
            : this(Name, Desc, DefaultValue, Type)
        {
            if (Limits.max == 0 && Limits.min == 0)
            {
                limits.max = Sandbox.UIConstants.MAX_SLIDER_VALUE;
            }
            else
            {
                limits.max = Limits.max;
                limits.min = Limits.min;
            }

            flags = Flags;
        }
示例#9
0
        public EditorProperty(string Name, string Desc, string DefaultValue, EditorPropertyType Type, EditorPropertyLimits Limits, int Flags = 0)
            : this(Name, Desc, DefaultValue, Type)
        {
            if (Limits.max == 0 && Limits.min == 0)
            {
                limits.max = Sandbox.UIConstants.MAX_SLIDER_VALUE;
            }
            else
            {
                limits.max = Limits.max;
                limits.min = Limits.min;
            }

            flags = Flags;
        }
示例#10
0
        /// <summary>
        /// Initializes new instance of type <see cref="EditorProperty" />.
        /// </summary>
        /// <param name="name">         Name of the property. </param>
        /// <param name="description">  Description of the property. </param>
        /// <param name="defaultValue"> Default value of the property. </param>
        /// <param name="type">         Type of the property. </param>
        /// <param name="limits">       Limitations applied to the property. </param>
        /// <param name="flags">        Flags assigned to the property. </param>
        public EditorProperty(string name, string description, string defaultValue, EditorPropertyType type,
                              EditorPropertyLimits limits, int flags = 0)
            : this(name, description, defaultValue, type)
        {
            if (Math.Abs(limits.Max) < MathHelpers.ZeroTolerance &&
                Math.Abs(limits.Min) < MathHelpers.ZeroTolerance)
            {
                this.Limits.Max = Sandbox.UserInterfaceConstants.MaxSliderValue;
            }
            else
            {
                this.Limits.Max = limits.Max;
                this.Limits.Min = limits.Min;
            }

            this.Flags = flags;
        }
示例#11
0
文件: Convert.cs 项目: yonder/CryMono
        public static object FromString(EditorPropertyType type, string value)
        {
            if (type == EditorPropertyType.String)
            {
                return(value);
            }
#if !(RELEASE && RELEASE_DISABLE_CHECKS)
            if (value == null)
            {
                throw new System.ArgumentNullException("value");
            }
            if (value.Length < 1)
            {
                throw new System.ArgumentException("value string was empty");
            }
#endif

            switch (type)
            {
            case EditorPropertyType.Bool:
            {
                if (value == "0")
                {
                    value = "false";
                }
                else if (value == "1")
                {
                    value = "true";
                }

                return(bool.Parse(value));
            }

            case EditorPropertyType.Int:
                return(int.Parse(value));

            case EditorPropertyType.Float:
                return(float.Parse(value));

            case EditorPropertyType.Vec3:
                return(Vec3.Parse(value));
            }

            return(null);
        }
示例#12
0
文件: Entity.cs 项目: iniside/CryCIL
        internal virtual void SetPropertyValue(string propertyName, EditorPropertyType propertyType, string valueString)
        {
#if !((RELEASE && RELEASE_DISABLE_CHECKS))
            if (valueString == null)
            {
                throw new ArgumentNullException("valueString");
            }
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }
            if (valueString.Length < 1 && propertyType != EditorPropertyType.String)
            {
                throw new ArgumentException("value was empty!");
            }
            if (propertyName.Length < 1)
            {
                throw new ArgumentException("propertyName was empty!");
            }
#endif

            var value = ConvertExtension.FromString(propertyType, valueString);

            var member =
                this.GetType()
                .GetMember(propertyName)
                .FirstOrDefault(x => x.MemberType == MemberTypes.Field || x.MemberType == MemberTypes.Property);
            if (member == null)
            {
                throw new ArgumentException(string.Format("member {0} could not be located", propertyName));
            }

            if (member.MemberType == MemberTypes.Property)
            {
                (member as PropertyInfo).SetValue(this, value, null);
            }
            else
            {
                (member as FieldInfo).SetValue(this, value);
            }

            this.OnPropertyChanged(member, propertyType, value);
        }
示例#13
0
        public static EditorPropertyType GetEditorType(Type type, EditorPropertyType propertyType)
        {
            //If a special type is needed, do this here.
            switch (propertyType)
            {
                case EditorPropertyType.Object:
                case EditorPropertyType.Texture:
                case EditorPropertyType.File:
                case EditorPropertyType.Sound:
                case EditorPropertyType.Dialogue:
                case EditorPropertyType.Sequence:
                    {
                        if (type == typeof(string))
                            return propertyType;

                        throw new EntityException("File selector type was specified, but property was not a string.");
                    }
                case EditorPropertyType.Color:
                    {
                        if (type == typeof(Vec3))
                            return propertyType;

                        throw new EntityException("Vector type was specified, but property was not a vector.");
                    }
            }

            //OH PROGRAMMING GODS, FORGIVE ME
            if (type == typeof(string))
                return EditorPropertyType.String;
            if (type == typeof(int))
                return EditorPropertyType.Int;
            if (type == typeof(float) || type == typeof(double))
                return EditorPropertyType.Float;
            if (type == typeof(bool))
                return EditorPropertyType.Bool;
            if (type == typeof(Vec3))
                return EditorPropertyType.Vec3;

            throw new EntityException("Invalid property type specified.");
        }
示例#14
0
 /// <summary>
 /// Called when the user changes a property from within the Editor.
 /// </summary>
 /// <param name="memberInfo"></param>
 /// <param name="propertyType"></param>
 /// <param name="newValue"></param>
 protected virtual void OnPropertyChanged(MemberInfo memberInfo, EditorPropertyType propertyType, object newValue)
 {
 }
示例#15
0
        internal virtual void SetPropertyValue(string propertyName, EditorPropertyType propertyType, string valueString)
        {
            #if !((RELEASE && RELEASE_DISABLE_CHECKS))
            if (valueString == null)
                throw new ArgumentNullException("valueString");
            if (propertyName == null)
                throw new ArgumentNullException("propertyName");
            if (valueString.Length < 1 && propertyType != EditorPropertyType.String)
                throw new ArgumentException("value was empty!");
            if (propertyName.Length < 1)
                throw new ArgumentException("propertyName was empty!");
            #endif

            var value = Convert.FromString(propertyType, valueString);

            var member = GetType().GetMember(propertyName).First(x => x.MemberType == MemberTypes.Field || x.MemberType == MemberTypes.Property);
            if (member == null)
                throw new ArgumentException(string.Format("member {0} could not be located", propertyName));

            if (member.MemberType == MemberTypes.Property)
                (member as PropertyInfo).SetValue(this, value, null);
            else
                (member as FieldInfo).SetValue(this, value);

            OnPropertyChanged(member, propertyType, value);
        }
示例#16
0
文件: Entity.cs 项目: yonder/CryMono
 /// <summary>
 /// Called when the user changes a property from within the Editor.
 /// </summary>
 /// <param name="memberInfo"></param>
 /// <param name="propertyType"></param>
 /// <param name="newValue"></param>
 protected virtual void OnPropertyChanged(MemberInfo memberInfo, EditorPropertyType propertyType, object newValue)
 {
 }
示例#17
0
        /// <summary>
        /// Initializes new instance of type <see cref="EditorProperty" />.
        /// </summary>
        /// <param name="name">         Name of the property. </param>
        /// <param name="description">  Description of the property. </param>
        /// <param name="defaultValue"> Default value of the property. </param>
        /// <param name="type">         Type of the property. </param>
        /// <param name="limits">       Limitations applied to the property. </param>
        /// <param name="flags">        Flags assigned to the property. </param>
        public EditorProperty(string name, string description, string defaultValue, EditorPropertyType type,
            EditorPropertyLimits limits, int flags = 0)
            : this(name, description, defaultValue, type)
        {
            if (Math.Abs(limits.Max) < MathHelpers.ZeroTolerance &&
                Math.Abs(limits.Min) < MathHelpers.ZeroTolerance)
            {
                this.Limits.Max = Sandbox.UserInterfaceConstants.MaxSliderValue;
            }
            else
            {
                this.Limits.Max = limits.Max;
                this.Limits.Min = limits.Min;
            }

            this.Flags = flags;
        }
示例#18
0
        /// <summary>
        /// Initializes new instance of type <see cref="EditorProperty" />.
        /// </summary>
        /// <param name="name">         Name of the property. </param>
        /// <param name="description">  Description of the property. </param>
        /// <param name="defaultValue"> Default value of the property. </param>
        /// <param name="type">         Type of the property. </param>
        public EditorProperty(string name, string description, string defaultValue, EditorPropertyType type)
            : this()
        {
            this.Name = name;
            this.Description = description;
            this.DefaultValue = defaultValue;

            this.Type = type;
        }
示例#19
0
        private static object[] GetProperties(IReflect type)
        {
            SortedList <string, List <EditorProperty> > folders = new SortedList <string, List <EditorProperty> >();
            // Get all public and not so public fields and properties with EditorProperty
            // attribute.
            var members =
                type.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                .Where(member => member.ContainsAttribute <EditorPropertyAttribute>());

            foreach (MemberInfo member in members)
            {
                EditorPropertyAttribute attribute = member.GetAttribute <EditorPropertyAttribute>();
                // Validate the type.
                EditorPropertyType propType = Entity.GetEditorType(member.GetAssociatedType(), attribute.Type);
                // Use default folder, if it is not specified.
                string folderName = attribute.Folder ?? "Default";
                // Register new folder, if there is a need for that.
                if (!folders.ContainsKey(folderName))
                {
                    folders.Add(folderName, new List <EditorProperty>());
                }
                // Add the property to the folder.
                folders[folderName].Add
                (
                    new EditorProperty
                    (
                        attribute.Name ?? member.Name,
                        attribute.Description,
                        attribute.DefaultValue ?? new Func <string>
                        (
                            delegate
                {
                    switch (propType)
                    {
                    case EditorPropertyType.Bool:
                        return("false");

                    case EditorPropertyType.Int:
                    case EditorPropertyType.Float:
                        return("0");

                    case EditorPropertyType.Vector3:
                    case EditorPropertyType.Color:
                        return("0,0,0");

                    default:
                        return("");
                    }
                }
                        ).Invoke(),
                        propType,
                        new EditorPropertyLimits
                {
                    Min = attribute.Min,
                    Max = attribute.Max
                },
                        attribute.Flags
                    )
                );
            }
            // Now lets create the array of properties.
            List <object> properties = new List <object>();

            foreach (KeyValuePair <string, List <EditorProperty> > folder in folders)
            {
                if (folder.Key == "Default")
                {
                    properties.AddRange(folder.Value.Cast <object>());
                }
                else
                {
                    properties.Add(new EditorProperty(folder.Key, "", "", EditorPropertyType.FolderBegin));
                    properties.AddRange(folder.Value.Cast <object>());
                    properties.Add(new EditorProperty(folder.Key, "", "", EditorPropertyType.FolderEnd));
                }
            }
            return(properties.ToArray());
        }