少年修仙传客户端代码仓库
提交 | 用户 | age
463e5e 1 using DG.Tweening;
L 2 using System.Collections.Generic;
3 using System.Linq;
4 using UnityEngine;
5 using UnityEngine.UI;
6
7 namespace vnxbqy.UI
8 {
9     public class YunShiXBActWin : Window
10     {
11         [SerializeField] List<Transform> startItems;//所有气泡起始坐标
12         [SerializeField] Transform transStartQianTong;//签筒起始坐标
13         [SerializeField] List<Transform> transStartQian;//所有签子起始坐标
14
15         [SerializeField] List<YunShiXBItem> yunShiXBItems;//所有气泡
16         [SerializeField] Transform transQianTong;//ǩͲ
17         [SerializeField] List<Transform> transQian;//所有签子
18
19         [SerializeField] Transform oneEnd;//单抽气泡目的地坐标
20         [SerializeField] List<Transform> manyEnds;//多抽气泡目的地坐标
21
22         [SerializeField] Transform transItemMissEnd;//所有气泡消失点目的地坐标
23         [SerializeField] Transform transQianTongMissEnd;//签筒目的地坐标
24
25         [SerializeField] List<PositionTween> qianPositionTweens = new List<PositionTween>();
26         [SerializeField] RotationTween qianTongRotationTween;
27         [SerializeField] UIEffect qianTongUIEffect;
28         [SerializeField] List<UIEffect> haveUIEffects;
29
30         [SerializeField] TextEx actTime;
31         [SerializeField] ButtonEx btnXBOne;
32         [SerializeField] ButtonEx btnXBMany;
33         [SerializeField] ButtonEx btnRate;
34         [SerializeField] TextEx txtXBOne;
35         [SerializeField] TextEx txtXBMany;
36         [SerializeField] TextEx txtXBOneCount;
37         [SerializeField] TextEx txtXBManyCount;
38         [SerializeField] ButtonEx btnSkip;
39         [SerializeField] ImageEx imgSkip;
40
41         [SerializeField] TextEx txtHasCnt;
42         [SerializeField] List<Slider> sliders = new List<Slider>();
43         [SerializeField] List<ItemCell> itemCells = new List<ItemCell>();
44         [SerializeField] List<ImageEx> imgGreys = new List<ImageEx>();
45         [SerializeField] List<ImageEx> imgHaves = new List<ImageEx>();
46         [SerializeField] List<TextEx> needCnts = new List<TextEx>();
47         [SerializeField] List<RotationTween> awardRotationTweens = new List<RotationTween>();
48
49         int type;
50         HappyXBModel happyXBModel { get { return ModelCenter.Instance.GetModelEx<HappyXBModel>(); } }
51         YunShiXBActModel model { get { return ModelCenter.Instance.GetModelEx<YunShiXBActModel>(); } }
52         PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
53
54         protected override void AddListeners()
55         {
56             btnSkip.SetListener(() =>
57             {
58                 model.isSkipXB = !model.isSkipXB;
59                 RefreshSkipUI();
60             });
61
62             btnRate.SetListener(() =>
63             {
64                 WindowCenter.Instance.Open<YunShiXBProbabilityWin>();
65             });
66
67             btnXBOne.SetListener(() =>
68             {
69                 if (!happyXBModel.IsHaveOneXBTool(type))
70                 {
71                     SysNotifyMgr.Instance.ShowTip("YunShiXBAct01");
72                     return;
73                 }
74
75                 if (!model.isSkipXB)
76                 {
77                     MoveAndDisappear();
78                 }
79
80                 happyXBModel.SendXBQuest(type, 0, 2);
81             });
82
83             btnXBMany.SetListener(() =>
84             {
85                 int toolCnt = 0;
86                 int needToolCnt = 0;
87                 if (!happyXBModel.IsHaveManyXBTool(type, out toolCnt, out needToolCnt) || toolCnt < needToolCnt)
88                 {
89                     SysNotifyMgr.Instance.ShowTip("YunShiXBAct01");
90                     return;
91                 }
92
93                 if (!model.isSkipXB)
94                 {
95                     MoveAndDisappear();
96                 }
97                 happyXBModel.CheckXBManyLimit(0, type, 2);
98             });
99         }
100
101         protected override void BindController()
102         {
103         }
104
105         protected override void OnPreOpen()
106         {
107             WindowCenter.Instance.uiRoot.eventSystem.enabled = true;
108             happyXBModel.RefreshXBTypeInfoAct += OnRefreshXBTypeInfoAct;
109             model.PlayAnimationSync += OnPlaySyncAnimation;
110             packModel.refreshItemCountEvent += OnRefreshItemCountEvent;
111             happyXBModel.RefreshXBResultAct += RefreshXBResult;
112
113             OperationYunShi act;
114             OperationTimeHepler.Instance.TryGetOperation(YunShiXBActModel.operaType, out act);
115             if (act == null)
116                 return;
117
118             type = act.treasureType;
119             var xbInfo = happyXBModel.GetXBInfoByType(type);
120             if (xbInfo == null)
121                 return;
122
123             if (type == 105)
124             {
125                 happyXBModel.title = HappXBTitle.YunShi1;
126             }
127             else if (type == 106)
128             {
129                 happyXBModel.title = HappXBTitle.YunShi2;
130             }
131             else if (type == 107)
132             {
133                 happyXBModel.title = HappXBTitle.YunShi3;
134             }
135             else if (type == 108)
136             {
137                 happyXBModel.title = HappXBTitle.YunShi4;
138             }
139
140             Display();
141             actTime.text = StringUtility.Contact(Language.Get("RidingPetBossQuestTime", act.ToDisplayTime()), Language.Get("YunShi04"));
142         }
143
144         protected override void OnPreClose()
145         {
146             happyXBModel.RefreshXBTypeInfoAct -= OnRefreshXBTypeInfoAct;
147             model.PlayAnimationSync -= OnPlaySyncAnimation;
148             packModel.refreshItemCountEvent -= OnRefreshItemCountEvent;
149             happyXBModel.RefreshXBResultAct -= RefreshXBResult;
150         }
151
152         private void RefreshXBResult()
153         {
154             if (model.isSkipXB)
155             {
156                 ShowGetItem();
157             }
158         }
159
160         private void OnRefreshItemCountEvent(PackType type, int arg2, int arg3)
161         {
162             Display();
163             model.IsPlayAnimation = true;
164         }
165
166         private void OnRefreshXBTypeInfoAct()
167         {
168             Display();
169             model.IsPlayAnimation = true;
170         }
171
172         protected override void OnAfterOpen()
173         {
174             Reset();
175             for (int i = 0; i < awardRotationTweens.Count; i++)
176             {
177                 awardRotationTweens[i].Stop();
178                 awardRotationTweens[i].SetStartState();
179             }
180             var xbInfo = happyXBModel.GetXBInfoByType(type);
181             if (xbInfo == null)
182                 return;
183
184             var award = TreasureCntAwardConfig.GetAwardIndexDict(type);
185             if (award == null)
186                 return;
187
188             var list = award.Keys.ToList();
189             list.Sort();
190             if (list == null)
191                 return;
192
193             for (int i = 0; i < model.AwardCellCount; i++)
194             {
195                 if (i < list.Count)
196                 {
197                     int id = award[list[i]];
198                     if (!TreasureCntAwardConfig.Has(id))
199                         continue;
200                     TreasureCntAwardConfig config = TreasureCntAwardConfig.Get(id);
201                     int state = model.GetAwardState(xbInfo.treasureCount, config.NeedTreasureCnt, xbInfo.treasureCntAward, config.AwardIndex);
202                     if (state == 1)
203                     {
204                         awardRotationTweens[i].Play();
205                     }
206                 }
207                 else
208                 {
209                     awardRotationTweens[i].Stop();
210                     awardRotationTweens[i].SetStartState();
211                 }
212             }
213         }
214
215         protected override void OnAfterClose()
216         {
217             StopAllCoroutines();
218         }
219
220         private void OnPlaySyncAnimation()
221         {
222             for (int i = 0; i < awardRotationTweens.Count; i++)
223             {
224                 awardRotationTweens[i].Stop();
225                 awardRotationTweens[i].SetStartState();
226             }
227             var xbInfo = happyXBModel.GetXBInfoByType(type);
228             if (xbInfo == null)
229                 return;
230
231             var award = TreasureCntAwardConfig.GetAwardIndexDict(type);
232             if (award == null)
233                 return;
234
235             var list = award.Keys.ToList();
236             list.Sort();
237             if (list == null)
238                 return;
239             for (int i = 0; i < model.AwardCellCount; i++)
240             {
241                 if (i < list.Count)
242                 {
243                     int id = award[list[i]];
244                     if (!TreasureCntAwardConfig.Has(id))
245                         continue;
246                     TreasureCntAwardConfig config = TreasureCntAwardConfig.Get(id);
247                     int state = model.GetAwardState(xbInfo.treasureCount, config.NeedTreasureCnt, xbInfo.treasureCntAward, config.AwardIndex);
248                     if (awardRotationTweens[i].isActiveAndEnabled && state == 1)
249                     {
250                         awardRotationTweens[i].Play();
251                     }
252                 }
253                 else
254                 {
255                     awardRotationTweens[i].Stop();
256                     awardRotationTweens[i].SetStartState();
257                 }
258             }
259         }
260
261         private void Reset()
262         {
263             qianTongUIEffect.Stop();
264
265             for (int i = 0; i < haveUIEffects.Count; i++)
266             {
267                 haveUIEffects[i].Stop();
268             }
269
270             for (int i = 0; i < yunShiXBItems.Count; i++)
271             {
272                 int gridIndex = i + 1;
273                 yunShiXBItems[i].transform.position = startItems[i].position;
274                 yunShiXBItems[i].SetActive(true);
275                 yunShiXBItems[i].Display(gridIndex);
276             }
277             qianTongRotationTween.Stop();
278
279             for (int i = 0; i < qianPositionTweens.Count; i++)
280             {
281                 qianPositionTweens[i].Stop();
282             }
283
284             transQianTong.transform.position = transStartQianTong.transform.position;
285             transQianTong.transform.rotation = transStartQianTong.transform.rotation;
286
287             for (int i = 0; i < transStartQian.Count; i++)
288             {
289                 transQian[i].transform.position = transStartQian[i].transform.position;
290                 transQian[i].transform.rotation = transStartQian[i].transform.rotation;
291             }
292         }
293
294         public void MoveAndDisappear()
295         {
296             WindowCenter.Instance.uiRoot.eventSystem.enabled = false;
297             Sequence sequence = DOTween.Sequence();
298             foreach (YunShiXBItem item in yunShiXBItems)
299             {
9e9b35 300                 sequence.Join(item.transform.DOMove(transItemMissEnd.position, 0.22f).SetEase(Ease.InOutSine).OnComplete(() => { item.SetActive(false); }));
463e5e 301             }
L 302             sequence.Join(transQianTong.transform.DORotate(new Vector3(0, 0, -5), 0.3f).SetEase(Ease.InOutSine).OnComplete(() => { qianTongUIEffect.Play(); }));
303             sequence.Join(transQianTong.transform.DOMove(transQianTongMissEnd.position, 0.5f).SetEase(Ease.InOutSine));
304             sequence.OnComplete(() => { ShakeQianTong(); });
305         }
306
307         private void ShowGetItem()
308         {
5e0fb1 309             if (happyXBModel.title == HappXBTitle.YunShi1 || happyXBModel.title == HappXBTitle.YunShi2 || happyXBModel.title == HappXBTitle.YunShi3 || happyXBModel.title == HappXBTitle.YunShi4)
463e5e 310             {
5e0fb1 311                 var xbItemlist = happyXBModel.rangelist;
L 312                 List<Item> itemList = new List<Item>();
9e9b35 313
5e0fb1 314                 for (int i = 0; i < xbItemlist.Count; i++)
L 315                 {
316                     XBGetItem xbItem = xbItemlist[i];
317
318                     itemList.Add(new Item(xbItem.itemId, (ulong)xbItem.count));
319                 }
15c37f 320                 ItemLogicUtility.Instance.ShowGetItem(itemList, seconds: 0, func: () =>{ happyXBModel.rangelist.Clear(); });
5e0fb1 321                 Reset();
L 322                 WindowCenter.Instance.uiRoot.eventSystem.enabled = true;
463e5e 323             }
L 324         }
325
326         public void ShakeQianTong()
327         {
328             qianTongRotationTween.Play();
329
330             for (int i = 0; i < qianPositionTweens.Count; i++)
331             {
332                 qianPositionTweens[i].duration = 0.3f;
333                 qianPositionTweens[i].Play();
334             }
335
336             var xbItemlist = happyXBModel.rangelist;
337             if (xbItemlist.IsNullOrEmpty())
338             {
339                 Reset();
340                 WindowCenter.Instance.uiRoot.eventSystem.enabled = true;
341                 return;
342             }
343             for (int i = 0; i < qianPositionTweens.Count; i++)
344             {
345                 qianPositionTweens[i].duration = 0.3f;
346             }
347             Sequence moveSequence = DOTween.Sequence();
348             moveSequence.AppendInterval(1.5f);
349
350             if (xbItemlist.Count == 1)
351             {
352                 YunShiXBItem item = yunShiXBItems[0];
353                 yunShiXBItems[0].transform.position = haveUIEffects[0].transform.position;
354                 Vector3 targetPosition = oneEnd.position;
355                 XBGetItem xbItem = happyXBModel.rangelist[0];
356                 DG.Tweening.Tween tween = item.transform.DOMove(targetPosition, 0.05f).SetDelay(0.05f).SetEase(Ease.InOutSine)
357                     .OnStart(() =>
358                     {
359                         haveUIEffects[0].Play();
360                         yunShiXBItems[0].Display(xbItem.itemId, xbItem.count);
361                         yunShiXBItems[0].SetActive(true);
362                         for (int i = 0; i < qianPositionTweens.Count; i++)
363                         {
364                             qianPositionTweens[i].duration = 0.1f;
365                         }
366                     });
367                 moveSequence.Append(tween);
368             }
369             else
370             {
371                 for (int i = 0; i < yunShiXBItems.Count; i++)
372                 {
373                     if (i < xbItemlist.Count)
374                     {
375                         int index = i;
376                         YunShiXBItem item = yunShiXBItems[i];
377                         yunShiXBItems[i].transform.position = haveUIEffects[i].transform.position;
378                         Vector3 targetPosition = manyEnds[i].position;
379                         XBGetItem xbItem = happyXBModel.rangelist[i];
380                         DG.Tweening.Tween tween = item.transform.DOMove(targetPosition, 0.1f).SetDelay(0.1f).SetEase(Ease.InOutSine)
381                             .OnStart(() =>
382                             {
383                                 haveUIEffects[index].Play();
384                                 yunShiXBItems[index].Display(xbItem.itemId, xbItem.count);
385                                 yunShiXBItems[index].SetActive(true);
386                                 for (int i = 0; i < qianPositionTweens.Count; i++)
387                                 {
388                                     qianPositionTweens[i].duration = 0.1f;
389                                 }
390                             });
391                         moveSequence.Append(tween);
392                     }
393                 }
394             }
395
396             moveSequence.OnComplete(() =>
397             {
398                 for (int i = 0; i < qianPositionTweens.Count; i++)
399                 {
400                     qianPositionTweens[i].duration = 0.3f;
401                 }
402                 Sequence sequence = DOTween.Sequence();
403                 sequence.Join(transQianTong.transform.DORotate(new Vector3(0, 0, 0), 0.2f).SetEase(Ease.InOutSine));
404                 sequence.Join(transQianTong.transform.DOMove(transStartQianTong.position, 0.2f).SetEase(Ease.InOutSine));
405                 sequence.OnComplete(() =>
406                 {
407                     qianTongRotationTween.Stop();
408                     for (int i = 0; i < qianPositionTweens.Count; i++)
409                     {
410                         qianPositionTweens[i].Stop();
411                         qianPositionTweens[i].SetStartState();
412                     }
413                     Clock.AlarmAfter(0.5, ShowGetItem);
414                 });
415             });
416         }
417
418         private void RefreshSkipUI()
419         {
420             imgSkip.SetActive(model.isSkipXB);
421         }
422
423         private void HaveAllAward()
424         {
425             var xbInfo = happyXBModel.GetXBInfoByType(type);
426             if (xbInfo == null)
427                 return;
428
429             var award = TreasureCntAwardConfig.GetAwardIndexDict(type);
430             if (award == null)
431                 return;
432
433             var list = award.Keys.ToList();
434             list.Sort();
435             if (list == null)
436                 return;
437             for (int i = 0; i < model.AwardCellCount; i++)
438             {
439                 if (i < list.Count)
440                 {
441                     int id = award[list[i]];
442                     if (!TreasureCntAwardConfig.Has(id))
443                         continue;
444                     TreasureCntAwardConfig config = TreasureCntAwardConfig.Get(id);
445                     int state = model.GetAwardState(xbInfo.treasureCount, config.NeedTreasureCnt, xbInfo.treasureCntAward, config.AwardIndex);
446                     if (state == 1)
447                     {
448                         model.SendGetAward(type, config.NeedTreasureCnt);
449                     }
450                 }
451             }
452         }
453
454         private void Display()
455         {
456             var xbInfo = happyXBModel.GetXBInfoByType(type);
457             if (xbInfo == null)
458                 return;
459
460             var award = TreasureCntAwardConfig.GetAwardIndexDict(type);
461             if (award == null)
462                 return;
463
464             var list = award.Keys.ToList();
465             list.Sort();
466             if (list == null)
467                 return;
468
469             var funcSet = happyXBModel.GetXBFuncSet(type);
470             if (funcSet == null)
471                 return;
472             int toolCnt0 = packModel.GetItemCountByID(PackType.Item, funcSet.costToolIds[0]);
473             int toolCnt1 = packModel.GetItemCountByID(PackType.Item, funcSet.costToolIds[1]);
474             txtXBOneCount.text = StringUtility.Contact(toolCnt0, "/", funcSet.xbNums[0]);
475             txtXBManyCount.text = StringUtility.Contact(toolCnt1, "/", funcSet.xbNums[1]);
5e0fb1 476             txtXBOne.text = Language.Get("YunShi07", funcSet.xbNums[0]);
L 477             txtXBMany.text = Language.Get("YunShi07", funcSet.xbNums[1]);
463e5e 478             RefreshSkipUI();
L 479             txtHasCnt.text = xbInfo.treasureCount.ToString();
480             for (int i = 0; i < model.AwardCellCount; i++)
481             {
482                 if (i < list.Count)
483                 {
484                     int id = award[list[i]];
485                     if (!TreasureCntAwardConfig.Has(id))
486                         continue;
487                     TreasureCntAwardConfig config = TreasureCntAwardConfig.Get(id);
488                     int state = model.GetAwardState(xbInfo.treasureCount, config.NeedTreasureCnt, xbInfo.treasureCntAward, config.AwardIndex);
489                     int[][] awardItemArr = config.AwardItemList;
490                     int itemID = awardItemArr[0][0];
491                     int itemCount = awardItemArr[0][1];
492                     ItemCellModel cellModel = new ItemCellModel(itemID, false, (ulong)itemCount);
493                     itemCells[i].Init(cellModel);
494                     itemCells[i].SetActive(true);
495                     itemCells[i].button.SetListener(() =>
496                     {
497                         if (state == 1)
498                         {
499                             HaveAllAward();
500                         }
501                         else
502                         {
503                             ItemTipUtility.Show(itemID);
504                         }
505                     });
506
507                     imgGreys[i].SetActive(state == 2);
508                     imgHaves[i].SetActive(state == 2);
509
510                     needCnts[i].SetActive(true);
511                     needCnts[i].text = config.NeedTreasureCnt.ToString();
512
513                     if (state != 0)
514                     {
515                         sliders[i].value = 1;
516                     }
517                     else
518                     {
519                         if (i == 0)
520                         {
521                             float value = Mathf.Floor((xbInfo.treasureCount / (float)config.NeedTreasureCnt) * 1000f) / 1000f;
522                             sliders[i].value = value;
523                         }
524                         else
525                         {
526                             int lastId = award[list[i - 1]];
527                             if (!TreasureCntAwardConfig.Has(lastId))
528                                 continue;
529                             TreasureCntAwardConfig lastIdConfig = TreasureCntAwardConfig.Get(lastId);
530                             float value = Mathf.Floor(((xbInfo.treasureCount - lastIdConfig.NeedTreasureCnt) / (float)(config.NeedTreasureCnt - lastIdConfig.NeedTreasureCnt)) * 1000f) / 1000f;
531                             sliders[i].value = Mathf.Min(value, 1);
532                         }
533                     }
534                 }
535                 else
536                 {
537                     itemCells[i].SetActive(false);
538                     needCnts[i].SetActive(false);
539                     sliders[i].SetActive(false);
540                     imgGreys[i].SetActive(false);
541                     imgHaves[i].SetActive(false);
542                 }
543             }
544         }
545     }
546 }