using CommonLang;
using System;
using System.Collections.Generic;
using System.Text;

namespace CommonAI.Zone.Attributes
{
    //-----------------------------------------------------------

    [AttributeUsage(AttributeTargets.Field)]
    public class ColorValueAttribute : System.Attribute
    {
        public static readonly int COLOR_GREEN = FromARGB(0xff, 0x00, 0xff, 0x00);
        public static readonly int COLOR_LIGHT_GREEN = FromARGB(0xff, 0x80, 0xff, 0x80);
        public static readonly int COLOR_DARK_GRAY = FromARGB(0xff, 0x40, 0x40, 0x40);
        public static readonly int COLOR_RED = FromARGB(0xff, 0xff, 0x00, 0x00);
        public static readonly int COLOR_LIGHT_BLUE = FromARGB(0xff, 0x80, 0x80, 0xff);

        public static int FromARGB(float a, float r, float g, float b)
        {
            int ARGB = 0;
            ARGB |= ((int)CMath.getInRange(a * 255, 0, 255)) << 24;
            ARGB |= ((int)CMath.getInRange(r * 255, 0, 255)) << 16;
            ARGB |= ((int)CMath.getInRange(g * 255, 0, 255)) << 8;
            ARGB |= ((int)CMath.getInRange(b * 255, 0, 255));
            return ARGB;
        }
        public static int FromARGB(int a, int r, int g, int b)
        {
            int ARGB = 0;
            ARGB |= ((int)CMath.getInRange(a, 0, 255)) << 24;
            ARGB |= ((int)CMath.getInRange(r, 0, 255)) << 16;
            ARGB |= ((int)CMath.getInRange(g, 0, 255)) << 8;
            ARGB |= ((int)CMath.getInRange(b, 0, 255));
            return ARGB;
        }
    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标识 Field Int32 字段为 类型的模板ID
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class TemplateIDAttribute : System.Attribute
    {
        private Type templateType;

        public TemplateIDAttribute(Type templateType)
        {
            this.templateType = templateType;
        }

        public Type TemplateType
        {
            get { return templateType; }
        }
    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标识 Field Int32 字段为 UnitInfo 模板ID的等级
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class TemplateLevelAttribute : System.Attribute
    {
        public TemplateLevelAttribute()
        {
        }
    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标识 Field 数组或List字段为 Int32 类型的模板ID
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class TemplatesIDAttribute : System.Attribute
    {
        private Type templateType;

        public TemplatesIDAttribute(Type templateType)
        {
            this.templateType = templateType;
        }

        public Type TemplateType
        {
            get { return templateType; }
        }
    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标识 Field 字段为资源文件
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class ResourceIDAttribute : System.Attribute
    {

    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标识 Field 字段为场景单位 Name
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class SceneObjectIDAttribute : System.Attribute
    {
        private Type objectType;

        public SceneObjectIDAttribute(Type objectType)
        {
            this.objectType = objectType;
        }

        public Type ObjectType
        {
            get { return objectType; }
        }
    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标识 Field 字段为场景事件触发 Name
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class SceneEventIDAttribute : System.Attribute
    {
    }
    //-----------------------------------------------------------
    /// <summary>
    /// 标识 Field 字段为场景环境变量 Key
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class SceneVarIDAttribute : System.Attribute
    {
        public readonly Type VarType;

        public SceneVarIDAttribute(Type varType)
        {
            this.VarType = varType;
        }
    }
    /// <summary>
    /// 标识 Field 字段为临时变量 Key
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class LocalVarIDAttribute : System.Attribute
    {
        public readonly Type VarType;
        public LocalVarIDAttribute(Type varType)
        {
            this.VarType = varType;
        }

    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标识 Field 字段为 脚本文件
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class SceneScriptIDAttribute : System.Attribute
    {
    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标识 UnitTrigger (单位被动系) 触发类型。
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class UnitTriggerEventTypeAttribute : System.Attribute
    {
        private Type[] delegateTypes;

        public UnitTriggerEventTypeAttribute(params Type[] delegateTypes)
        {
            this.delegateTypes = delegateTypes;
        }

        public Type[] DelegateTypes
        {
            get { return delegateTypes; }
        }
    }

    //-----------------------------------------------------------
    //-----------------------------------------------------------
    /// <summary>
    /// 标识 Field 字段为单位事件触发 Name
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class UnitEventIDAttribute : System.Attribute
    {
    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标记对象字段名字,用于AbstractValue取Field
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class ObjectMemberNameAttribute : System.Attribute
    {
        public readonly Type ObjectType;
        public readonly Type FieldType;
        public ObjectMemberNameAttribute(Type fieldType)
        {
            this.ObjectType = null;
            this.FieldType = fieldType;
        }
        public ObjectMemberNameAttribute(Type objType, Type fieldType)
        {
            this.ObjectType = objType;
            this.FieldType = fieldType;
        }
    }

    //-----------------------------------------------------------
    /// <summary>
    /// 标记对象字段名字,用于生成Language.csv
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class LocalizationTextAttribute : System.Attribute
    {
        public LocalizationTextAttribute()
        {
        }
    }



    //-----------------------------------------------------------
    /// <summary>
    /// 标记对象字段名字,用于AbstractValue取QuestID
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class QuestIDAttribute : System.Attribute
    {
        public QuestIDAttribute()
        {
        }
    }

    //-----------------------------------------------------------

    /// <summary>
    /// 标记 event 是否可以在编辑时反射成事件触发器
    /// </summary>
    [AttributeUsage(AttributeTargets.Event | AttributeTargets.Property | AttributeTargets.Field)]
    public class EventTriggerDescAttribute : System.Attribute
    {
        public string Description { get; private set; }
        public EventTriggerDescAttribute(string desc)
        {
            this.Description = desc;
        }
    }

    //-----------------------------------------------------------
    


    //-----------------------------------------------------------
}