//-------------------------------------------------------- 
 | 
//    [Author]:           第二世界 
 | 
//    [  Date ]:           Tuesday, March 12, 2019 
 | 
//-------------------------------------------------------- 
 | 
using UnityEngine; 
 | 
using System.Collections; 
 | 
using UnityEngine.UI; 
 | 
using UnityEngine.Events; 
 | 
  
 | 
namespace vnxbqy.UI 
 | 
{ 
 | 
  
 | 
    public class TipSuitPropertyWidget : MonoBehaviour 
 | 
    { 
 | 
        [SerializeField] Text m_SuitName; 
 | 
        [SerializeField] RectTransform m_StarsContainer; 
 | 
        [SerializeField] StarToggle[] m_StarToggles; 
 | 
        [SerializeField] Text[] m_SuitEquipNames; 
 | 
  
 | 
        [SerializeField] EquipSuitPropertyBar m_TwoSuit; 
 | 
        [SerializeField] EquipSuitPropertyBar m_FiveSuit; 
 | 
        [SerializeField] Text m_EightSuitTitle; 
 | 
        [SerializeField] Text m_EightSuitDescription; 
 | 
  
 | 
        ItemTipUtility.SuitInfo suitInfo; 
 | 
        public void Display(ItemTipUtility.SuitInfo suitInfo) 
 | 
        { 
 | 
            this.suitInfo = suitInfo; 
 | 
  
 | 
            m_SuitName.text = suitInfo.name; 
 | 
  
 | 
            var highestEightSuitLevel = 0; 
 | 
            foreach (var item in suitInfo.eightSuits) 
 | 
            { 
 | 
                if (item.Value && item.Key > highestEightSuitLevel) 
 | 
                { 
 | 
                    highestEightSuitLevel = item.Key; 
 | 
                } 
 | 
            } 
 | 
  
 | 
            var maxLevel = suitInfo.maxSuitLevel; 
 | 
            m_StarsContainer.SetActive(maxLevel >= 0); 
 | 
            if (maxLevel >= 0) 
 | 
            { 
 | 
                for (int i = 0; i < m_StarToggles.Length; i++) 
 | 
                { 
 | 
                    m_StarToggles[i].SetActive(m_StarToggles[i].star <= maxLevel, DisplaySuitInfo); 
 | 
                    m_StarToggles[i].toggle.isOn = i == highestEightSuitLevel / 3; 
 | 
                } 
 | 
            } 
 | 
  
 | 
            DisplaySuitInfo(highestEightSuitLevel); 
 | 
        } 
 | 
  
 | 
        void DisplaySuitInfo(int star) 
 | 
        { 
 | 
            DisplayCollectInfo(star); 
 | 
            DisplaySuitProperty(star); 
 | 
        } 
 | 
  
 | 
        void DisplayCollectInfo(int star) 
 | 
        { 
 | 
            var setName = EquipModel.GetSuitName(suitInfo.level); 
 | 
            for (int i = 0; i < m_SuitEquipNames.Length; i++) 
 | 
            { 
 | 
                var place = i + 1; 
 | 
                m_SuitEquipNames[i].text = Language.Get("Z100" + (i + 1).ToString()); 
 | 
                var hasSuit = suitInfo.places.Contains(place) 
 | 
                    && suitInfo.placeStars.ContainsKey(place) && suitInfo.placeStars[place] >= star; 
 | 
                m_SuitEquipNames[i].color = hasSuit ? UIHelper.GetUIColor(TextColType.Green, false) : UIHelper.GetUIColor(TextColType.White, true); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        void DisplaySuitProperty(int star) 
 | 
        { 
 | 
            m_TwoSuit.Display(suitInfo.twoSuitProperties[star], false); 
 | 
            m_FiveSuit.Display(suitInfo.fiveSuitProperties[star], false); 
 | 
            m_EightSuitDescription.text = GetEightSuitDescription(suitInfo.job, suitInfo.level, star); 
 | 
            var eightSuitActive = suitInfo.eightSuits[star]; 
 | 
            var color = eightSuitActive ? UIHelper.GetUIColor(TextColType.Green, false) : UIHelper.GetUIColor(TextColType.White, true); 
 | 
            m_EightSuitTitle.color = color; 
 | 
            m_EightSuitDescription.color = color; 
 | 
        } 
 | 
  
 | 
        public void Dispose() 
 | 
        { 
 | 
  
 | 
        } 
 | 
  
 | 
        private string GetEightSuitDescription(int job, int level, int star) 
 | 
        { 
 | 
            var configs = EquipSuitConfig.GetConfigs(job, level, EquipSuitType.EightSuit); 
 | 
            for (int i = 0; i < configs.Count; i++) 
 | 
            { 
 | 
                var config = configs[i]; 
 | 
                if (config.star == star) 
 | 
                { 
 | 
                    var description = string.Empty; 
 | 
                    if (config.skillID > 0) 
 | 
                    { 
 | 
                        description = config.description; 
 | 
                    } 
 | 
                    else 
 | 
                    { 
 | 
                        var propertyConfig = PlayerPropertyConfig.Get(config.attr[0].x); 
 | 
                        var propertyDescription = PlayerPropertyConfig.GetValueDescription(config.attr[0].x, config.attr[0].y); 
 | 
                        description = StringUtility.Contact(propertyConfig.Name, " +", propertyDescription); 
 | 
                    } 
 | 
  
 | 
                    return description; 
 | 
                } 
 | 
            } 
 | 
  
 | 
            return string.Empty; 
 | 
        } 
 | 
  
 | 
        [System.Serializable] 
 | 
        public class StarToggle 
 | 
        { 
 | 
            public RectTransform root; 
 | 
            public int star; 
 | 
            public Text title; 
 | 
            public Toggle toggle; 
 | 
  
 | 
            UnityAction<int> action; 
 | 
  
 | 
            public void SetActive(bool active, UnityAction<int> action) 
 | 
            { 
 | 
                root.SetActive(active); 
 | 
                toggle.isOn = false; 
 | 
                toggle.interactable = active; 
 | 
                this.action = action; 
 | 
  
 | 
                if (active) 
 | 
                { 
 | 
                    toggle.SetListener(OnValueChange); 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    toggle.RemoveAllListeners(); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            private void OnValueChange(bool value) 
 | 
            { 
 | 
                if (value) 
 | 
                { 
 | 
                    if (action != null) 
 | 
                    { 
 | 
                        action(star); 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
  
 | 
        } 
 | 
  
 | 
  
 | 
    } 
 | 
  
 | 
} 
 |