using System.Collections;  
 | 
using System.Collections.Generic;  
 | 
using UnityEngine;  
 | 
using UnityEngine.UI;  
 | 
  
 | 
namespace vnxbqy.UI  
 | 
{  
 | 
    public class TipExchangesWidget : MonoBehaviour  
 | 
    {  
 | 
        [SerializeField] Text m_Title;  
 | 
        [SerializeField] ScrollRect m_Scroller;  
 | 
        [SerializeField] Button m_Goto;  
 | 
  
 | 
        int jumpId = 0;  
 | 
  
 | 
        string windowName;  
 | 
        List<TipExchangeItemBehaviour> items = new List<TipExchangeItemBehaviour>();  
 | 
  
 | 
        private void Awake()  
 | 
        {  
 | 
            m_Goto.AddListener(OnGoto);  
 | 
        }  
 | 
  
 | 
        public void Display(int itemId)  
 | 
        {  
 | 
            var config = ItemExchangeConfig.Get(itemId);  
 | 
            m_Title.text = config.title;  
 | 
            jumpId = config.jump;  
 | 
            CreateItemBehaviour(config.items.Length);  
 | 
            for (var i = 0; i < items.Count; i++)  
 | 
            {  
 | 
                var behaviour = items[i];  
 | 
                if (i < config.items.Length)  
 | 
                {  
 | 
                    var id = config.items[i];  
 | 
                    behaviour.SetActive(true);  
 | 
                    behaviour.Display(id);  
 | 
                    behaviour.SetListener(()=>   
 | 
                    {  
 | 
                        if (!string.IsNullOrEmpty(windowName))  
 | 
                        {  
 | 
                            WindowCenter.Instance.CloseImmediately(windowName);  
 | 
                        }  
 | 
                    });  
 | 
                }  
 | 
                else  
 | 
                {  
 | 
                    behaviour.SetActive(false);  
 | 
                }  
 | 
            }  
 | 
  
 | 
            m_Scroller.verticalNormalizedPosition = 1f;  
 | 
            m_Scroller.AddMissingComponent<RayAccepter>();  
 | 
        }  
 | 
  
 | 
        public void Bind(string windowName)  
 | 
        {  
 | 
            this.windowName = windowName;  
 | 
        }  
 | 
  
 | 
        private void OnGoto()  
 | 
        {  
 | 
            if (!string.IsNullOrEmpty(windowName))  
 | 
            {  
 | 
                WindowCenter.Instance.Close(windowName);  
 | 
                WindowJumpMgr.Instance.WindowJumpTo((JumpUIType)jumpId);  
 | 
            }  
 | 
        }  
 | 
  
 | 
        private void CreateItemBehaviour(int count)  
 | 
        {  
 | 
            var nowCount = items.Count;  
 | 
            var need = count - nowCount;  
 | 
            for (var i = 0; i < need; i++)  
 | 
            {  
 | 
                var instance = UIUtility.CreateWidget("TipExchangeItem", "TipExchangeItem");  
 | 
  
 | 
                instance.transform.SetParentEx(m_Scroller.content, Vector3.zero, Quaternion.identity, Vector3.one);  
 | 
                var item = instance.GetComponent<TipExchangeItemBehaviour>();  
 | 
                items.Add(item);  
 | 
            }  
 | 
        }  
 | 
    }  
 | 
}  
 | 
  
 |