using System.Collections.Generic; 
 | 
using System.Linq; 
 | 
using UnityEngine; 
 | 
using UnityEngine.UI; 
 | 
  
 | 
  
 | 
/// <summary> 
 | 
/// 武将属性界面: functionOrder 用来传递武将背包索引 
 | 
/// </summary> 
 | 
public class HeroAllAttrWin : UIBase 
 | 
{ 
 | 
    [SerializeField] GameObject baseAttrGroup;  
 | 
    [SerializeField] GameObject fightAttrGroup;  
 | 
    [SerializeField] GameObject fightAntiAttrGroup;  
 | 
    [SerializeField] GameObject specialAttrGroup;  
 | 
     
 | 
  
 | 
  
 | 
    Dictionary<int, Button> attrBtns = new Dictionary<int, Button>(); 
 | 
  
 | 
    protected override void InitComponent() 
 | 
    { 
 | 
        //找出所有子组件名字为attr的GameObject 
 | 
        Button[] attrComponents = baseAttrGroup.GetComponentsInChildren<Button>(true) 
 | 
        .Where(c => c.gameObject.name == "attr").ToArray(); 
 | 
  
 | 
        var attrIDList = PlayerPropertyConfig.playerPropertyDict[PlayerPropertyConfig.baseType]; 
 | 
        for (int i = 0; i < attrComponents.Length; i++) 
 | 
        { 
 | 
            if (i < attrIDList.Count) 
 | 
            { 
 | 
                attrComponents[i].SetActive(true); 
 | 
                attrBtns.Add(attrIDList[i], attrComponents[i]); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                attrComponents[i].SetActive(false); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        attrComponents = fightAttrGroup.GetComponentsInChildren<Button>(true) 
 | 
            .Where(c => c.gameObject.name == "attr").ToArray(); 
 | 
        attrIDList = PlayerPropertyConfig.playerPropertyDict[PlayerPropertyConfig.fightType]; 
 | 
        for (int i = 0; i < attrComponents.Length; i++) 
 | 
        { 
 | 
            if (i < attrIDList.Count) 
 | 
            { 
 | 
                attrComponents[i].SetActive(true); 
 | 
                attrBtns.Add(attrIDList[i], attrComponents[i]); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                attrComponents[i].SetActive(false); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        attrComponents = fightAntiAttrGroup.GetComponentsInChildren<Button>(true) 
 | 
            .Where(c => c.gameObject.name == "attr").ToArray(); 
 | 
        attrIDList = PlayerPropertyConfig.playerPropertyDict[PlayerPropertyConfig.fightAntiType]; 
 | 
        for (int i = 0; i < attrComponents.Length; i++) 
 | 
        { 
 | 
            if (i < attrIDList.Count) 
 | 
            { 
 | 
                attrComponents[i].SetActive(true); 
 | 
                attrBtns.Add(attrIDList[i], attrComponents[i]); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                attrComponents[i].SetActive(false); 
 | 
            } 
 | 
        } 
 | 
        attrComponents = specialAttrGroup.GetComponentsInChildren<Button>(true) 
 | 
            .Where(c => c.gameObject.name == "attr").ToArray(); 
 | 
        attrIDList = PlayerPropertyConfig.playerPropertyDict[PlayerPropertyConfig.specialType]; 
 | 
        for (int i = 0; i < attrComponents.Length; i++) 
 | 
        { 
 | 
            if (i < attrIDList.Count) 
 | 
            { 
 | 
                attrComponents[i].SetActive(true); 
 | 
                attrBtns.Add(attrIDList[i], attrComponents[i]); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                attrComponents[i].SetActive(false); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        //设置回调 
 | 
        foreach (var kv in attrBtns) 
 | 
        { 
 | 
            int id = kv.Key; 
 | 
            kv.Value.AddListener(() => 
 | 
            { 
 | 
                SmallTipWin.showText = PlayerPropertyConfig.Get(id).desc; 
 | 
                SmallTipWin.worldPos = CameraManager.uiCamera.ScreenToWorldPoint(Input.mousePosition); 
 | 
                UIManager.Instance.OpenWindow<SmallTipWin>();     
 | 
            }); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    protected override void OnPreOpen() 
 | 
    { 
 | 
        var item = PackManager.Instance.GetItemByIndex(PackType.Hero, functionOrder); 
 | 
        if (item == null) 
 | 
            return; 
 | 
        var hero = HeroManager.Instance.GetHero(item.guid); 
 | 
        if (hero == null) 
 | 
            return; 
 | 
        var dict = FightPowerManager.Instance.GetHeroTotalAttr(hero); 
 | 
        foreach (var kv in attrBtns) 
 | 
        { 
 | 
            //每个按钮下有两个Text:name 和 value 
 | 
            var id = kv.Key; 
 | 
            var button = kv.Value; 
 | 
            Text nameText = button.transform.Find("name").GetComponent<Text>(); 
 | 
            Text valueText = button.transform.Find("value").GetComponent<Text>(); 
 | 
  
 | 
            nameText.text = PlayerPropertyConfig.Get(id).ShowName; 
 | 
            var value = dict.TryGetValue(id, out long v) ? v : 0; 
 | 
            valueText.text = PlayerPropertyConfig.GetValueDescription(id, value); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |