using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using GCGame.Table;
using Games.Mission;
using Games.Events;
using Games.Item;
using GCGame;
using Games.GlobeDefine;

public class BossBookInfoItem : UIItemBase
{
    public Text _Name;
    public Image _Icon;
    public Text _Attr;
    public Slider _ExpProcess;
    public Text _ExpText;
    public GameObject _BtnGO;
    public GameObject _RedDot;

    #region 

    HandbookBossInfo _BossInfo;
    Tab_BossHandBook _CurTab;
    Tab_BossHandBook _NextTab;

    public Tab_BossHandBook CurTab
    {
        get
        {
            return _CurTab;
        }
    }

    public override void Show(Hashtable hash)
    {
        base.Show(hash);

        var bossInfo = (HandbookBossInfo)hash["InitObj"];
        ShowLevelItem(bossInfo);
    }

    public void ShowLevelItem(HandbookBossInfo bossInfo)
    {
        _BossInfo = bossInfo;
        _CurTab = null;
        _NextTab = null;
        var bossTables = TableManager.GetBossHandBook();
        foreach (var bossTab in bossTables)
        {
            if (bossTab.Value.BossId == bossInfo.BossId && bossTab.Value.Level == bossInfo.Level)
            {
                _CurTab = bossTab.Value;
            }
            if (bossTab.Value.BossId == bossInfo.BossId && bossTab.Value.Level == bossInfo.Level + 1)
            {
                _NextTab = bossTab.Value;
            }

        }

        //0级时,显示1级属性
        if (_CurTab == null && _NextTab != null)
        {
            _Name.text = StrDictionary.GetClientDictionaryString("#{8113}", 0) + "-" + _NextTab.Name;
            LoadAssetBundle.Instance.SetImageSprite(_Icon, _NextTab.Icon);
            var attrName = PropID.GetAttrName((PropID.PropertyID)_NextTab.PropId[0], -1, _NextTab.PropVal[0]);
            _Attr.text = attrName + "+" + _NextTab.PropVal[0];

            UIGrayImage.SetImageGray(_Icon, true);
        }
        else
        {
            _Name.text = StrDictionary.GetClientDictionaryString("#{8113}", _CurTab.Level) + "-" + _CurTab.Name;
            LoadAssetBundle.Instance.SetImageSprite(_Icon, _CurTab.Icon);
            var attrName = PropID.GetAttrName((PropID.PropertyID)_CurTab.PropId[0], -1, _CurTab.PropVal[0]);
            _Attr.text = attrName + "+" + _CurTab.PropVal[0];

            UIGrayImage.SetImageGray(_Icon, false);
        }

        if (_NextTab != null)
        {
            int nowExp = bossInfo.Exp - (_NextTab.CostExpTotal - _NextTab.CostExp);

            _ExpProcess.value = (float)nowExp / _NextTab.CostExp;
            _ExpText.text = nowExp + "/" + _NextTab.CostExp;

            if (nowExp >= _NextTab.CostExp)
            {
                _BtnGO.SetActive(true);
            }
            else
            {
                _BtnGO.SetActive(false);
            }
        }
        else //满级
        {
            _ExpProcess.value = 1;
            _BtnGO.SetActive(false);
            _ExpText.text = StrDictionary.GetClientDictionaryString("#{49200}");
        }

        _RedDot.SetActive(BossBookPanel.IsBossBookCanLevelUp(bossInfo));
    }

    public void OnBtnLevelUp()
    {
        BossBookLvUpTips.ShowBossLvUpStatic(_BossInfo, _CurTab, _NextTab);
    }

    
    #endregion


}