using FairyGUI;
namespace GFGGame
{
    public class ItemView
    {
        private GComponent _obj;
        private GLoader _loaIcon;
        private GLoader _loaRarity;
        private GTextField _txtName;
        private GTextField _txtCount;
        private GTextField _txtHasCount;
        private GImage _imgGot;
        private GLoader _loaShouTongRewardVisble;
        private GGroup _grpCount;
        private ItemData _itemData;
        public ItemView(GComponent obj)
        {
            _obj = obj;
            _loaIcon = obj.GetChild("loaIcon") as GLoader;
            _loaRarity = obj.GetChild("loaRarity") as GLoader;
            _txtName = obj.GetChild("txtName") as GTextField;
            _txtCount = obj.GetChild("txtCount") as GTextField;
            _txtHasCount = obj.GetChild("txtHasCount") as GTextField;
            _imgGot = obj.GetChild("imgGot") as GImage;
            _loaShouTongRewardVisble = obj.GetChild("loaShouTongReward") as GLoader;
            _grpCount = obj.GetChild("grpCount") as GGroup;
            AddClickListener();
        }
        private void AddClickListener()
        {
            _obj.onClick.Add(() =>
            {
                if (!ShowTips) return;
                GoodsItemTipsController.ShowItemTips(_itemData.id);
            });
        }
        public void SetData(ItemData itemData)
        {
            _itemData = itemData;
            UpdateView();
        }
        private void UpdateView()
        {
            ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemData.id);
            _loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
            RarityIconController.UpdateRarityIcon(_loaRarity, _itemData.id, false);
            _imgGot.visible = false;
            _loaShouTongRewardVisble.visible = false;
            _grpCount.visible = true;
            _showTips = true;
            _txtName.text = itemCfg.name;
            _txtCount.SetVar("count", _itemData.num.ToString()).FlushVars();
            _txtHasCount.SetVar("count", "" + ItemDataManager.GetItemNum(_itemData.id)).FlushVars();
        }
        /// 
        /// “已领取”显示状态
        /// 
        /// 
        public bool ImgGotVisible
        {
            get
            {
                return _imgGot.visible;
            }
            set
            {
                _imgGot.visible = value;
            }
        }
        /// 
        /// "已拥有"显示状态
        /// 
        /// 
        public bool TxtHasCountVisble
        {
            get
            {
                return _txtHasCount.visible;
            }
            set
            {
                _txtHasCount.visible = value;
            }
        }
        public bool LoaShouTongRewardVisble
        {
            get
            {
                return _loaShouTongRewardVisble.visible;
            }
            set
            {
                _loaShouTongRewardVisble.visible = value;
            }
        }
        /// 
        /// 显示数量
        /// 
        /// 
        public bool ShowCount
        {
            set
            {
                _grpCount.visible = value;
            }
        }
        private bool _showTips = true;
        public bool ShowTips
        {
            get
            {
                return _showTips;
            }
            set
            {
                _showTips = value;
            }
        }
    }
}