少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    [XLua.Hotfix]
    public class GatherSoulItemBehaviour : MonoBehaviour
    {
        [SerializeField] RectTransform m_ContainerItem;
        [SerializeField] Image m_Icon;
        [SerializeField] RectTransform m_ContainerLevel;
        [SerializeField] Text m_Level;
        [SerializeField] Text m_ItemName;
        [SerializeField] Text m_Count;
        [SerializeField] Button m_Func;
        [SerializeField] RectTransform m_Select;
        [SerializeField] UIEffect m_Effect;
 
        VirtualPackModel model
        {
            get { return ModelCenter.Instance.GetModel<VirtualPackModel>(); }
        }
 
        GatherSoulComposeModel composeModel
        {
            get { return ModelCenter.Instance.GetModel<GatherSoulComposeModel>(); }
        }
 
        GatheringSoulModel soulModel
        {
            get { return ModelCenter.Instance.GetModel<GatheringSoulModel>(); }
        }
 
        VirtualItem displayItem;
 
        bool requireResolveEffect = false;
 
        public static event Action<Transform> alreadyResolveEvent;
 
        private void Awake()
        {
            if (m_Func != null)
            {
                m_Func.onClick.AddListener(OnFunc);
            }
        }
 
        private void OnEnable()
        {
            soulModel.prepareResolveEvent += PrepareResolveEvent;
            DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerDataInitializeEvent;
            DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent += MakeItemAnswerEvent;
            RedpointCenter.Instance.redpointValueChangeEvent += RedpointValueChangeEvent;
        }
 
        private void OnDisable()
        {
            soulModel.prepareResolveEvent -= PrepareResolveEvent;
            DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= BeforePlayerDataInitializeEvent;
            DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent -= MakeItemAnswerEvent;
            RedpointCenter.Instance.redpointValueChangeEvent -= RedpointValueChangeEvent;
            requireResolveEffect = false;
        }
 
        private void RedpointValueChangeEvent(int id)
        {
            if(id== soulModel.equipRedpoint.id
                || id == soulModel.replaceRedpoint.id)
            {
                DisplayEffect();
            }
        }
 
        /// <summary>
        /// 背包位置索引
        /// </summary>
        /// <param name="packType"></param>
        /// <param name="index"></param>
        public void Display(int index)
        {
            displayItem = default(VirtualItem);
            GatherSoulItem item;
            bool exist = model.TryGetItem(PackType.GatherSoul, index, out item) && index != -1;
            m_ContainerItem.gameObject.SetActive(exist);
            if (exist)
            {
                displayItem = new VirtualItem()
                {
                    packType = PackType.GatherSoul,
                    index = index,
                    itemId = item.id,
                    level = item.level,
                };
                Display();
            }
        }
 
        public void Display(int id, int level)
        {
            if (id == 0)
            {
                m_ContainerItem.gameObject.SetActive(false);
                return;
            }
            displayItem = new VirtualItem()
            {
                packType = (PackType)0,
                itemId = id,
                level = level,
            };
            m_ContainerItem.gameObject.SetActive(true);
            Display();
        }
 
        void Display()
        {
            var config = ItemConfig.Get(displayItem.itemId);
            if (config != null)
            {
                m_Icon.SetSprite(config.IconKey);
                if (m_ContainerLevel != null)
                {
                    m_ContainerLevel.gameObject.SetActive(config.Type != GatheringSoulModel.GATHERSOUL_ESSENCE_TYPE);
                }
                if (m_Level != null)
                {
                    m_Level.text = displayItem.level.ToString();
                }
                if (m_ItemName != null)
                {
                    m_ItemName.text = config.ItemName;
                    m_ItemName.color = UIHelper.GetUIColor(config.ItemColor);
                }
            }
            DisplayEffect();
        }
 
        public void DisplayCount(int count, int requireCount = 0)
        {
            if (m_Count != null)
            {
                if (requireCount == 0)
                {
                    m_Count.text = count.ToString();
                    m_Count.color = UIHelper.GetUIColor(TextColType.LightYellow);
                }
                else
                {
                    m_Count.text = StringUtility.Contact(
                        UIHelper.AppendColor(count >= requireCount ? TextColType.LightYellow : TextColType.Red, count.ToString())
                        , "/", requireCount.ToString());
                }
            }
        }
 
        void DisplayEffect()
        {
            if (m_Select != null)
            {
                var requireSelect = displayItem.packType == PackType.GatherSoul
                    && soulModel.topBestSoulIndexs.Contains(displayItem.index);
                m_Select.gameObject.SetActive(requireSelect);
                if (requireSelect)
                {
                    if (m_Effect.target != null)
                    {
                        var animator = m_Effect.target.GetAnimator();
                        if (animator != null)
                        {
                            animator.Play(0, 0, GatherSoulWin.sync_topsoul_normalized);
                        }
                    }
                }
            }
        }
 
        private void PrepareResolveEvent(PackType packType, int index)
        {
            if (displayItem.packType == packType && displayItem.index == index)
            {
                requireResolveEffect = true;
            }
        }
 
        private void BeforePlayerDataInitializeEvent()
        {
            requireResolveEffect = false;
        }
 
        private void MakeItemAnswerEvent(H0721_tagMakeItemAnswer package)
        {
            if (package.MakeType == (int)MakeType.GatherSoulDecompose)
            {
                if (requireResolveEffect)
                {
                    if (alreadyResolveEvent != null)
                    {
                        alreadyResolveEvent(transform);
                    }
                    requireResolveEffect = false;
                }
            }
        }
 
        void OnFunc()
        {
            if (displayItem.packType == PackType.GatherSoul)
            {
                GatherSoulItem item;
                if (model.TryGetItem(displayItem.packType, displayItem.index, out item))
                {
                    ItemTipUtility.ShowGatherSoul(displayItem.packType, displayItem.index);
                }
            }
            else
            {
                if (displayItem.itemId != 0)
                {
                    ItemTipUtility.ShowGatherSoul(displayItem.itemId, displayItem.level);
                }
            }
        }
    }
}