少年修仙传客户端代码仓库
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, June 03, 2019
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
 
    public class AlchemyBatchWin : Window
    {
        [SerializeField] ItemCell m_Item;
        [SerializeField] Text m_ItemName;
        [SerializeField] Slider m_Slider;
        [SerializeField] Text m_Number;
        [SerializeField] Text m_Time;
        [SerializeField] Text m_Remind;
        [SerializeField] Button m_Add;
        [SerializeField] Button m_Reduce;
        [SerializeField] Button m_Alchemy;
        [SerializeField] Button m_Close;
 
        public static int alchemyId = 0;
 
        PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        AlchemyModel model { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_Slider.SetListener((float value) => { OnValueChange(); });
            m_Add.SetListener(OnAdd);
            m_Reduce.SetListener(OnReduce);
            m_Alchemy.SetListener(TryAlchemy);
            m_Close.SetListener(CloseClick);
        }
 
        protected override void OnPreOpen()
        {
            Display();
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        void Display()
        {
            var config = AlchemyConfig.Get(alchemyId);
            var itemId = config.AlchemItemID;
 
            var itemConfig = ItemConfig.Get(itemId);
            var itemData = new ItemCellModel(itemId, true, 1);
            m_Item.Init(itemData);
            m_ItemName.text = itemConfig.ItemName;
            m_ItemName.color = UIHelper.GetUIColor(itemConfig.ItemColor, true);
 
            var canAlchemyCount = model.GetCanAlchemyCount(alchemyId);
            int maxValue = Mathf.Min(model.maxBatchAlchemyCount, canAlchemyCount);
 
            var recommandCount = maxValue;
            AlchemyDrugUseLimit drugUseLimit;
            var itemCount = playerPack.GetItemCountByID(PackType.Item, itemId);
            if (model.TryGetAlchemyUseLimit(itemId, out drugUseLimit))
            {
                var canEatCount = drugUseLimit.GetUseLimit() - drugUseLimit.eatTimes - itemCount;
                recommandCount = Mathf.Max(1, Mathf.Min(maxValue, canEatCount));
                m_Remind.SetActive(true);
                m_Remind.text = Language.Get("AlchemyBatchRecommand", canEatCount);
            }
            else
            {
                m_Remind.SetActive(false);
            }
 
            m_Slider.minValue = maxValue == 1 ? 0 : 1;
            m_Slider.maxValue = maxValue;
            m_Slider.value = recommandCount;
 
            m_Slider.interactable = maxValue > 1;
 
            m_Number.text = recommandCount.ToString();
 
            DisplayTime();
        }
 
        void DisplayTime()
        {
            var config = AlchemyConfig.Get(alchemyId);
            var seconds = config.NeedTime * Mathf.FloorToInt(m_Slider.value);
            m_Time.text = TimeUtility.SecondsToDHMSCHS(seconds);
        }
 
        private void OnAdd()
        {
            if (m_Slider.value < m_Slider.maxValue)
            {
                m_Slider.value++;
            }
        }
 
        private void OnReduce()
        {
            if (m_Slider.value > m_Slider.minValue && m_Slider.minValue != 0)
            {
                m_Slider.value--;
            }
        }
 
        private void OnValueChange()
        {
            m_Number.text = Mathf.FloorToInt(m_Slider.value).ToString();
            DisplayTime();
        }
 
        private void TryAlchemy()
        {
            if (model.selectAlchemyType == AlchemyType.Normal)
            {
                AlchemyDrugUseLimit drugUseLimit;
                var itemId = AlchemyConfig.Get(alchemyId).AlchemItemID;
                var itemCount = playerPack.GetItemCountByID(PackType.Item, itemId);
                if (model.TryGetAlchemyUseLimit(itemId, out drugUseLimit))
                {
                    var canEatCount = drugUseLimit.GetUseLimit() - drugUseLimit.eatTimes - itemCount;
                    if (Mathf.FloorToInt(m_Slider.value) > canEatCount)
                    {
                        string title = Language.Get("L1003");
                        string info = Language.Get("MaximumMumberOfPills");
                        ConfirmCancel.ShowPopConfirm(title, info, (bool isOk) =>
                        {
                            if (isOk)
                            {
                                Alchemy();
                            }
                        });
                        return;
                    }
                }
                Alchemy();
            }
            else
            {
                Alchemy();
            }
            
        }
 
        private void Alchemy()
        {
            var pak = new CA576_tagCMPlayerRefine();
            pak.AlchemyID = (uint)model.selectAlchemy;
            pak.AlchemyTimes = (ushort)Mathf.FloorToInt(m_Slider.value);
            pak.DoType = 1;
            GameNetSystem.Instance.SendInfo(pak);
            CloseImmediately();
        }
 
    }
 
}