少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
 
 
namespace vnxbqy.UI
{
    
    public class LingShiChange : Window
    {
        // 1. 界面  2. 物品获得调整背包 3. 物品使用改兑换 4. 灵石名称和描述 5. 红点
        [SerializeField] Text Money;
        [SerializeField] Text ItemName;
        [SerializeField] Button sureBtn;
        [SerializeField] Button closeBtn;
        [SerializeField] Text m_Count;
        [SerializeField] Button m_Add;
        [SerializeField] Button m_Sub;
        [SerializeField] Button m_Max;
        [SerializeField] ItemCell m_Itemcell;
        [SerializeField] Text HaveCount;
        [SerializeField] Text baseMoneyText;
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        Coroutine m_Coroutine = null;
 
        bool isPointAdd = false;
        bool isPointSub = false;
        int point = 0;
 
        int m_itemId = 150;
        int m_haveCnt = 0;
        static WaitForSeconds waitSpeedSlow = new WaitForSeconds(0.2f);
 
        private void ShowMoney()
        {
            var Item = ItemConfig.Get(m_itemId);
            m_Count.text = point.ToString();
            Money.text = (int.Parse(m_Count.text) * Item.EffectValueA1).ToString();
        }
 
        private void ShowItem()
        {
            var Item = ItemConfig.Get(m_itemId);
            ItemCellModel cellModel = new ItemCellModel(m_itemId, true, 1);
            m_Itemcell.Init(cellModel);
            ItemName.text = Item.ItemName;
            baseMoneyText.text = Item.EffectValueA1.ToString();
        }
 
        private void UseItem()
        {
            var itemModels = packModel.GetItemsById(PackType.Item, m_itemId);
            if (itemModels != null && itemModels.Count > 0 && point > 0)
            {
                ItemOperateUtility.Instance.UseItem(itemModels[0].guid, point);
            }
            CloseClick();
        }
 
        private void ShowItemCount()
        {
            m_haveCnt = packModel.GetItemCountByID(PackType.Item, m_itemId);
            
            HaveCount.text = Language.Get("HasCount") + UIHelper.AppendColor(m_haveCnt == 0 ? TextColType.Red : TextColType.Green, m_haveCnt.ToString(), true);
            //SetColorful
            m_Add.SetInteractable(null, m_haveCnt > 0);
            m_Sub.SetInteractable(null, m_haveCnt > 0);
            m_Max.SetInteractable(null, m_haveCnt > 0);
        }
 
        #region Built-in
        protected override void BindController()
        {
 
        }
        protected override void AddListeners()
        {
            sureBtn.AddListener(UseItem);
            closeBtn.AddListener(CloseClick);
        }
        protected override void OnPreOpen()
        {
            packModel.refreshItemCountEvent += OnItemCountRefresh;
            UIEventTrigger.Get(m_Sub.gameObject).OnDown = OnSubDown;
            UIEventTrigger.Get(m_Sub.gameObject).OnUp = OnSubUp;
            UIEventTrigger.Get(m_Add.gameObject).OnDown = OnAddDown;
            UIEventTrigger.Get(m_Add.gameObject).OnUp = OnAddUp;
            m_Max.AddListener(OnMax);
            point = packModel.GetItemCountByID(PackType.Item, m_itemId);
            ShowItem();
            ShowItemCount();
            ShowMoney();
        }
        protected override void OnAfterOpen()
        {
 
        }
 
        protected override void OnPreClose()
        {
            point = 0;
            packModel.refreshItemCountEvent -= OnItemCountRefresh;
        }
 
        protected override void OnAfterClose()
        {
            
        }
        #endregion
 
        private void OnItemCountRefresh(PackType type, int index, int itemId)
        {
 
            if (type == PackType.Item && itemId == m_itemId)
            {
                ShowItemCount();
            }
        }
 
        public void Dispose()
        {
 
            if (m_Coroutine != null)
            {
                StopCoroutine(m_Coroutine);
            }
            isPointAdd = false;
            isPointSub = false;
        }
 
 
 
        private void OnAddDown(GameObject go)
        {
 
            isPointAdd = true;
            if (m_Coroutine != null)
            {
                StopCoroutine(m_Coroutine);
            }
            m_Coroutine = StartCoroutine(Co_PointRefresh(true));
        }
 
        private void OnAddUp(GameObject go)
        {
            isPointAdd = false;
            if (m_Coroutine != null)
            {
                StopCoroutine(m_Coroutine);
            }
        }
 
        private void OnSubDown(GameObject go)
        {
            if (m_Coroutine != null)
            {
                StopCoroutine(m_Coroutine);
            }
            isPointSub = true;
            m_Coroutine = StartCoroutine(Co_PointRefresh(false));
        }
 
        private void OnSubUp(GameObject go)
        {
            isPointSub = false;
            if (m_Coroutine != null)
            {
                StopCoroutine(m_Coroutine);
            }
        }
 
        private void OnMax()
        {
            point = m_haveCnt;
            ShowMoney();
        }
 
        IEnumerator Co_PointRefresh(bool pointUp)
        {
            while (pointUp ? isPointAdd : isPointSub)
            {
                if (pointUp && m_haveCnt > 0 && point < m_haveCnt)
                {
                    
                    point += 1;
                }
                else if (!pointUp && point > 0)
                {
                    point -= 1;
                }
                ShowMoney();
                yield return waitSpeedSlow;
            }
        }
    }
}