/********************************************************************************
游戏中红点统一管理
*********************************************************************************/

using UnityEngine;
using System.Collections.Generic;

public class RedTipPoint : MonoBehaviour
{
    public enum PointType
    {
        WorldBoss,
        PrivateBoss,
        Boss,
        HomeBoss,
        PetBook,
        PetBookLevel,
        GuildXiulian,

        //FunctionEx上的红点
        Equip,              // 锻造
        Skill,              // 技能
        Pet,                //宠物
        Marry,              // 婚姻
        MeridiaSoul,        // 境界
        Magic,              // 法宝
        Ride,               //坐骑
        Piano,            // 竖琴
        Wing,               // 翅膀
        Qilinbi,            //麒麟臂
        Soul,              // 魂器
        Mask,               // 面具
        Huopao,           //火炮
        GuildApply,
        None,
    }
    private static List<RedTipPoint> Static_RedTipPoints = new List<RedTipPoint>();
    private static Dictionary<PointType, int> Static_PointStates = new Dictionary<PointType, int>();
    public static void RedPointStateChange(PointType pointType, bool state)
    {
        if (state == false && Static_PointStates.ContainsKey(pointType) == false)
            return;
        if (state && Static_PointStates.ContainsKey(pointType))
            return;

        if (state)
            Static_PointStates[pointType] = 1;
        else if (Static_PointStates.ContainsKey(pointType))
            Static_PointStates.Remove(pointType);
        for(int i=0;i< Static_RedTipPoints.Count;i++)
        {
            Static_RedTipPoints[i].StateChange();
        }
    }

    //FunctionEx上的进阶红点特殊判断一下
    /// <summary>
    /// 设置进阶项Icon红点状态
    /// </summary>
    /// <param name="advanceType">进阶类型:AdvanceBase.AdvanceType</param>
    /// <param name="state">状态</param>
    public static void SetAdvanceRedTipState(AdvanceBase.AdvanceType advanceType, bool state)
    {
        PointType realType = PointType.None;
        switch (advanceType)
        {
            case AdvanceBase.AdvanceType.Ride: realType = PointType.Ride; break;
            case AdvanceBase.AdvanceType.Piano: realType = PointType.Piano; break;
            case AdvanceBase.AdvanceType.Wing: realType = PointType.Wing; break;
            case AdvanceBase.AdvanceType.Qilinbi: realType = PointType.Qilinbi; break;
            case AdvanceBase.AdvanceType.Soul: realType = PointType.Soul; break;
            case AdvanceBase.AdvanceType.Mask: realType = PointType.Mask; break;
            case AdvanceBase.AdvanceType.Huopao: realType = PointType.Huopao; break;
        }

        if (realType != PointType.None)
        {
            RedPointStateChange(realType, state);
        }
    }

    public static void DelResScript(RedTipPoint red)
    {
        if (Static_RedTipPoints.Contains(red))
            Static_RedTipPoints.Remove(red);
    }

    public static void AddResScript(RedTipPoint red)
    {
        if (Static_RedTipPoints.Contains(red) == false)
            Static_RedTipPoints.Add(red);
    }

    public PointType _Type;

    public PointType[] _Types;

    public void StateChange()
    {
        if (gameObject == null)
            return;

        bool isShow = false;
        if (Static_PointStates.ContainsKey(_Type))
            isShow = true;
        if(isShow==false)
        {
            for(int i=0;i<_Types.Length;i++)
            {
                if(Static_PointStates.ContainsKey(_Types[i]))
                {
                    isShow = true;
                    break;
                }
            }
        }
        gameObject.SetActive(isShow);
    }

    public void Init()
    {
        Awake();
    }

    private void Awake()
    {
        StateChange();
        AddResScript(this);
    }

    private void OnDestroy()
    {
        DelResScript(this);
    }
}