yyl
8 天以前 bb5909bcd36b48b919366c95b4248a3754452698
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
 
public class GiftBaseCell : MonoBehaviour
{
 
    Image m_QualityBG;
    Image qualityBG
    {
        get
        {
            if (m_QualityBG == null)
            {
                m_QualityBG = this.transform.GetComponent<Image>("Container_GiftCell/qualityIcon");
            }
            return m_QualityBG;
        }
    }
 
    Button m_GiftBtn;
    Button giftBtn
    {
        get
        {
            if (m_GiftBtn == null)
            {
                m_GiftBtn = this.transform.GetComponent<Button>("Container_GiftCell");
            }
            return m_GiftBtn;
        }
    }
 
 
    Text m_GiftName;
    Text giftName
    {
        get
        {
            if (m_GiftName == null)
            {
                m_GiftName = this.transform.GetComponent<Text>("Container_GiftCell/name");
            }
            return m_GiftName;
        }
    }
 
    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
    {
        get
        {
            if (m_LvRect == null)
            {
                m_LvRect = this.transform.Find("Container_GiftCell/lvrect");
            }
            return m_LvRect;
        }
    }
 
    Text m_LvText;
    Text lvText
    {
        get
        {
            if (m_LvText == null)
            {
                m_LvText = this.transform.GetComponent<Text>("Container_GiftCell/lvrect/lv");
            }
            return m_LvText;
        }
    }
 
    Image m_StateImg;
    Image stateImg
    {
        get
        {
            if (m_StateImg == null)
            {
                m_StateImg = this.transform.GetComponent<Image>("Container_GiftCell/state");
            }
            return m_StateImg;
        }
    }
 
    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:代表棕色需觉醒激活,其他根据配表,没有天赋的外层控制显隐
    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);
            giftName.text = config.Name;
            giftName.color = GetColor(config.Quality);
            textOutline.OutlineColor = GetOutlineColor(config.Quality);
            lvText.text = lv.ToString();
            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);
            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)
    {
        if (quality == 1)
        {
            //D196FF
            return new Color32(209, 150, 255, 255);
        }
        else if (quality == 2)
        {
            //ffda8c
            return new Color32(255, 218, 140, 255);
        }
        else if (quality == 3)
        {
            //ffbd88
            return new Color32(255, 189, 136, 255);
        }
        else if (quality == 4)
        {
            //ff8888
            return new Color32(255, 136, 136, 255);
        }
        return new Color32(255, 255, 255, 255);
    }
 
    Color32 GetOutlineColor(int quality)
    {
        if (quality == 1)
        {
            //692088
            return new Color32(105, 32, 136, 128);
        }
        else if (quality == 2)
        {
            //886220
            return new Color32(136, 98, 32, 128);
        }
        else if (quality == 3)
        {
            //884a20
            return new Color32(136, 74, 32, 128);
        }
        else if (quality == 4)
        {
            //882020
            return new Color32(136, 32, 32, 128);
        }
        return new Color32(0, 0, 0, 128);
    }
 
    GameObject cellContainer;
    protected void LoadPrefab()
    {
        if (cellContainer != null)
            return;
        
        var tmp = transform.Find("Container_GiftCell");
        if (tmp != null)
        {
            cellContainer = tmp.gameObject;
            return;
        }
        if (cellContainer == null)
        {
            cellContainer = UIUtility.CreateWidget("GiftBaseCell", "Container_GiftCell");
 
            if (cellContainer != null)
            {
                cellContainer.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
                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;
    }
}