少年修仙传客户端代码仓库
hch
3 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
using vnxbqy.UI;
 
 
public class MergeServerCollectWordsCell : ILBehaviour
{
    Button ExChangeBtn;
    Text ExChangeCnt;
    Transform CollectLayout;
    ItemCell itemCell;
    Image Img_Complete;
    LayoutGroup Layout;
    Transform CollectWord;
 
    int updateFrame = -1;
 
    MergeServerCollectWordsModel model = MergeServerCollectWordsModel.Instance;
 
    PackModel packModel
    {
        get { return ModelCenter.Instance.GetModelEx<PackModel>(); }
    }
 
    protected override void Awake()
    {
        base.Awake();
        ExChangeBtn = proxy.GetWidgtEx<Button>("ExChangeBtn");
        ExChangeCnt = proxy.GetWidgtEx<Text>("ExChangeCnt");
        CollectLayout = proxy.GetWidgtEx<Transform>("CollectLayout");
        itemCell = proxy.GetWidgtEx<ItemCell>("itemCell");
        Img_Complete = proxy.GetWidgtEx<Image>("Img_Complete");
        Layout = proxy.GetWidgtEx<LayoutGroup>("Layout");
        CollectWord = proxy.GetWidgtEx<Transform>("CollectWord");
    }
 
 
 
    //按钮
    //数量不足    按钮灰色不可点击 (0代表不限制兑换次数)
    //可兑换      按钮亮起可点击
    //达兑换上限  隐藏按钮显示上限
    public void Display(int index)
    {
        OperationBase operationBase = null;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(model.collectWordsType, out operationBase))
        {
            return;
        }
        OperationCollectWords operation = operationBase as OperationCollectWords;
        if (index >= operation.exchangeWords.Count)
        {
            return;
        }
 
        var exchangeNum = operation.exchangeWords[index].ExchangeNum; //编号
        var maxNum = operation.exchangeWords[index].ExchangeCountMax;
 
        bool isEnough = true; //是否能兑换
        //物品
        for (int i = 0; i < operation.exchangeWords[index].NeedItemCount; i++)
        {
            var itemID = (int)operation.exchangeWords[index].NeedItemList[i].ItemID;
            var itemCnt = operation.exchangeWords[index].NeedItemList[i].ItemCount;
            var isBind = operation.exchangeWords[index].NeedItemList[i].IsBind;
 
            GameObject go = null;
            if (i >= CollectLayout.childCount)
            {
                go = GameObject.Instantiate(CollectWord.gameObject);
                go.transform.SetParent(CollectLayout);
                go.transform.localScale = Vector3.one;
                Vector3 pos = go.transform.localPosition;
                go.transform.localPosition = pos.SetZ(0);
            }
            else
            {
                go = CollectLayout.GetChild(i).gameObject;
            }
            go.SetActive(true);
                
            RichText richText = go.GetComponentInChildren<RichText>();
            richText.text = Language.Get("GoToGet", itemID);
            ItemCell item = go.GetComponentInChildren<ItemCell>();
            var cnt = packModel.GetItemCountByID(PackType.Item, itemID);
            ItemCellModel cellModel = new ItemCellModel(itemID);
            item.Init(cellModel);
            item.countText.text = cnt + "/" + itemCnt;
            item.countText.SetActiveIL(true);
            if (cnt < itemCnt)
            {
                isEnough = false;
            }
            item.button.RemoveAllListeners();
            item.button.AddListener(() =>
            {
                ItemTipUtility.Show(itemID);
            });
        }
 
        // cell是共用的 拖拉之后 childCount产生变化,需要屏蔽
        for (int i = operation.exchangeWords[index].NeedItemCount; i < CollectLayout.childCount; i++)
        {
            CollectLayout.GetChild(i).SetActiveIL(false);
        }
 
        int exchangedCnt; //已兑换次数
        model.exchangeDict.TryGetValue(exchangeNum, out exchangedCnt);
 
        Img_Complete.SetActiveIL(maxNum != 0 && exchangedCnt >= maxNum);
        ExChangeBtn.SetActiveIL(maxNum == 0 || exchangedCnt < maxNum);
        ExChangeBtn.SetColorful(null, isEnough);
        ExChangeBtn.interactable = isEnough;
        ExChangeBtn.AddListener(() =>
        {
            model.SendExchangeWord(exchangeNum);
        });
 
        var tagItemID = (int)operation.exchangeWords[index].ItemID;
        ItemCellModel tagCellModel = new ItemCellModel(tagItemID, false, (ulong)operation.exchangeWords[index].ItemCount);
        itemCell.Init(tagCellModel);
        itemCell.button.RemoveAllListeners();
        itemCell.button.AddListener(() =>
        {
            ItemTipUtility.Show(tagItemID);
        });
 
        if (maxNum != 0)
            ExChangeCnt.text = Language.Get("CollectWordsLimit", exchangedCnt, maxNum);
        else
            ExChangeCnt.text = Language.Get("DailyQuest_NoLevelLimit");
 
        updateFrame = 0;
    }
 
 
    //layout contentsizefilter 镶嵌使用的情况下会发生位置未正常刷新的情况
    //调用 ForceRebuildLayoutImmediate强制刷新,必须先刷父物体再刷子物体
    //强制刷新在逻辑最后或者帧结束此处无效,故在update处理的下一帧刷新
    //仅供参考,未分析具体原因和其他测试,只在此界面测试的情况
    protected override void Update()
    {
        if (updateFrame < 0) return;
        if (updateFrame >= 0)
        {
            updateFrame++;
        }
        //在之后的帧刷新
        if (updateFrame != 1)
        {
            if (updateFrame > 2)
            { 
                updateFrame = -1;
            }
            return;
        }
        LayoutRebuilder.ForceRebuildLayoutImmediate(Layout.GetComponent<RectTransform>());
        for (int i = 0; i < Layout.transform.childCount; i++)
        {
            LayoutRebuilder.ForceRebuildLayoutImmediate(Layout.transform.GetChild(i).GetComponent<RectTransform>());
        }
 
    }
 
}