hch
2 天以前 df03c997716c6f5fbd4b87c01caef1d2e75165fc
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
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
 
 
/// <summary>
/// 淘金刷新界面
/// </summary>
public class GoldRushRefreshWin : UIBase
{
    [SerializeField] ItemCell itemCell;
    [SerializeField] Text nameText;
    [SerializeField] CountControler countControler;
 
    [SerializeField] Text timeText;
    [SerializeField] Text moneyText;
    [SerializeField] Image iconImg;
 
    [SerializeField] Transform refreshRect;
    [SerializeField] ButtonEx refreshBtn;
    [SerializeField] ButtonEx workBtn;
    [SerializeField] ButtonEx callBackBtn;
    [SerializeField] Text callBackText;
    [SerializeField] Text workingText;
 
    GoldRushItemConfig config;
    int workerCount;
 
    protected override void InitComponent()
    {
        workBtn.AddListener(DoingWork);
        refreshBtn.AddListener(RefreshItem);
        callBackBtn.AddListener(CallBackWorker);
    }
 
 
 
    protected override void OnPreOpen()
    {
        GoldRushManager.Instance.OnGoldRushCampEvent += OnGoldRushCampEvent;
        GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
        var goldID = GoldRushManager.Instance.GetCampGoldID(GoldRushManager.Instance.selectCampID);
        if (goldID == 0)
        {
            DelayCloseWindow().Forget();
            return;
        }
        
 
        Display();
    }
 
    protected override void OnPreClose()
    {
        GoldRushManager.Instance.OnGoldRushCampEvent -= OnGoldRushCampEvent;
        GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
    }
 
 
    void Display()
    {
        var goldID = GoldRushManager.Instance.GetCampGoldID(GoldRushManager.Instance.selectCampID);
        config = GoldRushItemConfig.Get(goldID);
        int emptyCnt = GoldRushManager.Instance.GetEmptyWorkerCount();
 
        int itemID = config.ItemID;
        itemCell.Init(new ItemCellModel(itemID, false, config.ItemCount));
        itemCell.button.AddListener(()=>
        {
            ItemTipUtility.Show(itemID);
        });
        nameText.text = GoldRushManager.Instance.GetCampItemName(config);
        var endTime = GoldRushManager.Instance.GetCampEndTime(GoldRushManager.Instance.selectCampID);
        if (endTime == 0)
        {
            //未开始
            timeText.text = TimeUtility.SecondsToMS(config.NeedSeconds);
            refreshRect.SetActive(true);
            callBackBtn.SetActive(false);
 
            iconImg.SetIconWithMoneyType(GoldRushManager.Instance.refreshMoneyType);
            moneyText.text = UIHelper.ShowUseMoney(GoldRushManager.Instance.refreshMoneyType,
            GoldRushManager.Instance.GetRefreshMoney(GoldRushManager.Instance.selectCampID));
            workBtn.SetInteractable(emptyCnt != 0);
            workerCount = Math.Min(emptyCnt, 1);
        }
        else
        {
            timeText.text = TimeUtility.SecondsToMS(endTime - TimeUtility.AllSeconds);
            refreshRect.SetActive(false);
            callBackBtn.SetActive(true);
            RefreshCallBackBtn();
            workerCount = GoldRushManager.Instance.GetCampWorkerCnt(GoldRushManager.Instance.selectCampID);
        }
        countControler.Init(ChangeWorkerCount, config.WorkerMax, workerCount, AddWorker, DecWorker);
    }
 
    void RefreshCallBackBtn()
    {
        var realCnt = GoldRushManager.Instance.GetCampWorkerCnt(GoldRushManager.Instance.selectCampID);
        if (workerCount == 0)
        {
            callBackBtn.SetInteractable(true);
            callBackText.text = Language.Get("GoldRush33"); //撤回监工
        }
        else if (realCnt == workerCount)
        {
            callBackBtn.SetInteractable(false);
            callBackText.text = Language.Get("GoldRush14"); //调整监工
        }
        else
        { 
            callBackBtn.SetInteractable(true);
            callBackText.text = Language.Get("GoldRush14"); //调整监工
        }
    }
 
    void OnSecondEvent()
    { 
        var endTime = GoldRushManager.Instance.GetCampEndTime(GoldRushManager.Instance.selectCampID);
        if (endTime != 0)
        {
            timeText.text = TimeUtility.SecondsToMS(endTime - TimeUtility.AllSeconds);
 
            var addStr = new string('.', (int)Time.time % 4);
            workingText.text = Language.Get("GoldRush37") + addStr;
        }
    }
 
 
 
    void OnGoldRushCampEvent(int campID)
    {
        if (campID != GoldRushManager.Instance.selectCampID)
        {
            return;
        }
        var goldID = GoldRushManager.Instance.GetCampGoldID(GoldRushManager.Instance.selectCampID);
        if (goldID == 0)
        {
            //已完成
            CloseWindow();
            return;
        }
        Display();
    }
 
    void ChangeWorkerCount(int count)
    {
        workerCount = count;
        var endTime = GoldRushManager.Instance.GetCampEndTime(GoldRushManager.Instance.selectCampID);
        if (endTime == 0)
        {
            //未开始
            timeText.text = TimeUtility.SecondsToMS(config.NeedSeconds / Math.Max(1, count));
        }
        else
        {
            timeText.text = TimeUtility.SecondsToMS(endTime - TimeUtility.AllSeconds);
            RefreshCallBackBtn();
        }
    }
 
    bool AddWorker(int count)
    {
        if (count >= config.WorkerMax)
        {
            return false;
        }
 
        //可派遣的监工: 空闲监工数+当前监工数
        if (count + 1 > GoldRushManager.Instance.GetEmptyWorkerCount() + GoldRushManager.Instance.GetCampWorkerCnt(GoldRushManager.Instance.selectCampID))
        { 
            SysNotifyMgr.Instance.ShowTip("GoldRush2");
            return false;
        }
 
        return true;
    }
 
    bool DecWorker(int count)
    {
        if (count <= 0)
            return false;
        return true;
    }
 
    void DoingWork()
    {
        var endTime = GoldRushManager.Instance.GetCampEndTime(GoldRushManager.Instance.selectCampID);
        if (endTime != 0)
            return;
 
        int emptyCnt = GoldRushManager.Instance.GetEmptyWorkerCount();
        if (emptyCnt == 0 || workerCount > emptyCnt)
        {
            SysNotifyMgr.Instance.ShowTip("GoldRush2");
            return;
        }
 
        if (workerCount == 0)
        {
            SysNotifyMgr.Instance.ShowTip("GoldRush5");
            return;
        }
 
        if (workerCount > config.WorkerMax)
        {
            return;
        }
 
        //仓库容量已达上限
        if (GoldRushManager.Instance.GetWarehouseCnt() >= GoldRushManager.Instance.warehouseMaxCnt)
        {
            SysNotifyMgr.Instance.ShowTip("GoldRush3");
            return;
        }
 
        GoldRushManager.Instance.SendGoldRushOP(2, GoldRushManager.Instance.selectCampID, workerCount);
        SysNotifyMgr.Instance.ShowTip("GoldRush6");
        CloseWindow();
    }
 
    void RefreshItem()
    {
        var endTime = GoldRushManager.Instance.GetCampEndTime(GoldRushManager.Instance.selectCampID);
        if (endTime != 0)
            return;
 
 
        if (!UIHelper.CheckMoneyCount(GoldRushManager.Instance.refreshMoneyType,
        GoldRushManager.Instance.GetRefreshMoney(GoldRushManager.Instance.selectCampID), 2))
        {
            return;
        }
 
        GoldRushManager.Instance.SendGoldRushOP(1, GoldRushManager.Instance.selectCampID, 0);
 
        SysNotifyMgr.Instance.ShowTip("GoldRush4");
    }
 
    void CallBackWorker()
    {
         var endTime = GoldRushManager.Instance.GetCampEndTime(GoldRushManager.Instance.selectCampID);
        if (endTime == 0)
            return;
 
        var realCnt = GoldRushManager.Instance.GetCampWorkerCnt(GoldRushManager.Instance.selectCampID);
        if (workerCount == 0)
        {
            ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
            Language.Get("GoldRush38"), (bool isOK) =>
                {
                    if (isOK)
                    {
                        //撤回监工
                        GoldRushManager.Instance.SendGoldRushOP(3, GoldRushManager.Instance.selectCampID, 0);
                        CloseWindow();
                    }
                });
        }
        else if (realCnt == workerCount)
        {
            return;
        }
        else
        {
            //调整监工
            GoldRushManager.Instance.SendGoldRushOP(2, GoldRushManager.Instance.selectCampID, workerCount);
            SysNotifyMgr.Instance.ShowTip("GoldRush1");
            CloseWindow();
        }
    }
}