lcy
7 天以前 485db99b5c51a971c173664cf6e808dc8424b0a0
Main/System/HeroUI/GiftBaseCell.cs
@@ -45,6 +45,19 @@
        }
    }
    OutlineEx m_TextOutline;
    OutlineEx textOutline
    {
        get
        {
            if (m_TextOutline == null)
            {
                m_TextOutline = this.transform.GetComponent<OutlineEx>("Container_GiftCell/name");
            }
            return m_TextOutline;
        }
    }
    Transform m_LvRect;
    Transform lvRect
    {
@@ -65,7 +78,7 @@
        {
            if (m_LvText == null)
            {
                m_LvText = this.transform.GetComponent<Text>("Container_GiftCell/lv");
                m_LvText = this.transform.GetComponent<Text>("Container_GiftCell/lvrect/lv");
            }
            return m_LvText;
        }
@@ -84,39 +97,99 @@
        }
    }
    Image m_AwakeLockImg;   //重生降低觉醒等级锁定的图片
    Image awakeLockImg
    {
        get
        {
            if (m_AwakeLockImg == null)
            {
                m_AwakeLockImg = this.transform.GetComponent<Image>("Container_GiftCell/lock");
            }
            return m_AwakeLockImg;
        }
    }
    void Awake()
    {
        LoadPrefab();
    }
    //showState 0:不显示 1:新增 2:提升
    //giftID 0 :代表未激活灰色 -1:代表不能激活 棕色,其他根据配表
    private void Init(int giftID, int lv, UnityAction onclick = null, int showState = 0)
    //giftID 0 :代表灰色需升星激活 -1:代表棕色需觉醒激活,其他根据配表,没有天赋的外层控制显隐
    public void Init(int giftID, int lv, int showState = 0, int heroID = 0, int index = 0, int awakeLevel = 0)
    {
        LoadPrefab();   //存在被卸载的可能,重新加载
        if (HeroTalentConfig.HasKey(giftID))
        {
            var config = HeroTalentConfig.Get(giftID);
            qualityBG.SetSprite("GiftQualityBG" + config.Quality);
            giftBtn.AddListener(onclick);
            giftName.text = config.Name;
            giftName.color = GetColor(config.Quality);
            textOutline.OutlineColor = GetOutlineColor(config.Quality);
            lvText.text = lv.ToString();
            lvText.color = GetColor(1);
            Outline textOutline = lvText.GetComponent<Outline>();
            textOutline.effectColor = GetOutlineColor(config.Quality);
            lvRect.SetActive(lv > 0);
            stateImg.SetActive(showState > 0);
            stateImg.SetSprite("GiftState" + showState);
            stateImg.SetNativeSize();
            //特殊处理重生降低觉醒等级锁定的天赋
            if (index >= HeroUIManager.Instance.normalGiftMaxCnt)
            {
                awakeLockImg.SetActive(HeroAwakeConfig.GetAwakeLVByUnLockGiftIndex(heroID, index) > awakeLevel);
            }
            else
            {
                awakeLockImg.SetActive(false);
            }
        }
        else
        {
            qualityBG.SetSprite("GiftQualityBG" + giftID);
            giftBtn.RemoveAllListeners();
            giftName.text = string.Empty;
            lvRect.SetActive(false);
            stateImg.SetActive(false);
            awakeLockImg.SetActive(false);
        }
        giftBtn.AddListener(() => { ShowSmallTip(giftID, lv, heroID, index, awakeLevel); });
    }
    void ShowSmallTip(int giftID, int giftLV, int heroID, int index, int awakeLevel)
    {
        SmallTipWin.worldPos = CameraManager.uiCamera.ScreenToWorldPoint(Input.mousePosition);
        if (giftID > 0)
        {
            var giftConfig = HeroTalentConfig.Get(giftID);
            SmallTipWin.showText = Language.Get("SmallTipFomat", giftConfig.Name + " " + Language.Get("L1113", giftLV),
            Language.Get("HeroGift5", PlayerPropertyConfig.Get(giftConfig.AttrID).Name, PlayerPropertyConfig.GetValueDescription(giftConfig.AttrID, giftConfig.AttrValue*giftLV)));
            if (index >= HeroUIManager.Instance.normalGiftMaxCnt)
            {
                int needAwakeLV = HeroAwakeConfig.GetAwakeLVByUnLockGiftIndex(heroID, index);
                if (needAwakeLV > awakeLevel)
                {
                    SmallTipWin.showText += "\n" + Language.Get("HeroAwake18", needAwakeLV);
                }
            }
            UIManager.Instance.OpenWindow<SmallTipWin>();
        }
        else if (giftID == 0)
        {
            SmallTipWin.showText = Language.Get("HeroGift1");
            UIManager.Instance.OpenWindow<SmallTipWin>();
        }
        else if (giftID == -1)
        {
            SmallTipWin.showText = Language.Get("HeroGift2", HeroAwakeConfig.GetAwakeLVByUnLockGiftIndex(heroID, index));
            UIManager.Instance.OpenWindow<SmallTipWin>();
        }
    }
    Color32 GetColor(int quality)
    {
@@ -148,24 +221,24 @@
        if (quality == 1)
        {
            //692088
            return new Color32(105, 32, 136, 255);
            return new Color32(105, 32, 136, 128);
        }
        else if (quality == 2)
        {
            //886220
            return new Color32(136, 98, 32, 255);
            return new Color32(136, 98, 32, 128);
        }
        else if (quality == 3)
        {
            //884a20
            return new Color32(136, 74, 32, 255);
            return new Color32(136, 74, 32, 128);
        }
        else if (quality == 4)
        {
            //882020
            return new Color32(136, 32, 32, 255);
            return new Color32(136, 32, 32, 128);
        }
        return new Color32(255, 255, 255, 255);
        return new Color32(0, 0, 0, 128);
    }
    GameObject cellContainer;
@@ -174,7 +247,7 @@
        if (cellContainer != null)
            return;
        
        var tmp = transform.Find("Container_SkillCell");
        var tmp = transform.Find("Container_GiftCell");
        if (tmp != null)
        {
            cellContainer = tmp.gameObject;
@@ -182,7 +255,7 @@
        }
        if (cellContainer == null)
        {
            cellContainer = UIUtility.CreateWidget("SkillBaseCell", "Container_SkillCell");
            cellContainer = UIUtility.CreateWidget("GiftBaseCell", "Container_GiftCell");
            if (cellContainer != null)
            {
@@ -190,6 +263,24 @@
                cellContainer.transform.SetAsFirstSibling();
            }
        }
        //缩放到和父rect一样大
        var scale = 1f;
        var rect = cellContainer.GetComponent<RectTransform>();
        var parentRect = transform.GetComponent<RectTransform>();
        float width = parentRect.sizeDelta.x;
        if (width <= 0f)
        {
            //外部控制了尺寸获取为0
            GridLayoutGroup grid = GetComponentInParent<GridLayoutGroup>();
            if (grid != null)
            {
                width = grid.cellSize.x;
            }
        }
        scale = width / rect.sizeDelta.x;
        cellContainer.transform.localScale = cellContainer.transform.localScale * scale;
    }
}