LuckyBoxCardView.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System.Collections;
  2. using UnityEngine;
  3. using UI.LuckyBox;
  4. using System.Collections.Generic;
  5. using FairyGUI;
  6. using System.Linq;
  7. namespace GFGGame
  8. {
  9. public class LuckyBoxCardView : BaseWindow
  10. {
  11. private UI_LuckyBoxCardUI _ui;
  12. private List<ItemData> _rewardList = new List<ItemData>();
  13. private List<ItemData> _newRewardList = new List<ItemData>();
  14. private List<ItemData> _oldRewardList = new List<ItemData>();
  15. private List<ItemData> _showRewardList = new List<ItemData>();
  16. // private int _type = 0;//弹窗类型:0可跳过,1:首次获得物品不可跳过,2首次获得物品不可跳过,不弹获得套装界面
  17. private GameObject gameObject;
  18. private GoWrapper wrapper;
  19. public override void Dispose()
  20. {
  21. base.Dispose();
  22. SceneController.DestroyObjectFromView(gameObject, wrapper);
  23. if (_ui != null)
  24. {
  25. _ui.Dispose();
  26. _ui = null;
  27. }
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. packageName = UI_LuckyBoxUI.PACKAGE_NAME;
  33. _ui = UI_LuckyBoxCardUI.Create();
  34. this.viewCom = _ui.target;
  35. isfullScreen = true;
  36. this.modal = true;
  37. _ui.m_bg.onTouchBegin.Add(OnClickBg);
  38. _ui.m_btnPass.onClick.Add(OnClickBtnPass);
  39. string resPath = ResPathUtil.GetViewEffectPath("ui_ck", "ui_ck_zs");
  40. SceneController.AddObjectToView(gameObject, null, _ui.m_comCard.m_holder, resPath, out gameObject, out wrapper);
  41. }
  42. protected override void OnShown()
  43. {
  44. base.OnShown();
  45. _rewardList = (this.viewData as object[])[0] as List<ItemData>;
  46. _newRewardList.Clear();
  47. _oldRewardList.Clear();
  48. for (int i = 0; i < _rewardList.Count; i++)
  49. {
  50. if (GetThisCount(_rewardList[i].id, _rewardList) == ItemDataManager.GetItemNum(_rewardList[i].id) && !IsAddToNewRewardList(_rewardList[i].id))
  51. {
  52. _newRewardList.Add(_rewardList[i]);
  53. }
  54. else
  55. {
  56. _oldRewardList.Add(_rewardList[i]);
  57. }
  58. }
  59. if (LuckyBoxDataManager.Instance.luckyBoxId > 0)//必展示必掉奖励
  60. {
  61. int[][] bonus = LuckyBoxCfgArray.Instance.GetCfg(LuckyBoxDataManager.Instance.luckyBoxId).bonusArr;
  62. List<ItemData> itemDatas = ItemUtil.CreateItemDataList(bonus, LuckyBoxDataManager.Instance.times);
  63. _newRewardList.AddRange(itemDatas);
  64. LuckyBoxDataManager.Instance.luckyBoxId = 0;
  65. }
  66. UpdateView();
  67. }
  68. private void UpdateView()
  69. {
  70. _ui.m_btnPass.visible = _newRewardList.Count <= 1;
  71. _showRewardList = _newRewardList.Count > 0 ? _newRewardList : _oldRewardList;
  72. if (_showRewardList.Count - 1 < 0) return;
  73. ItemData itemdata = _showRewardList[_showRewardList.Count - 1];
  74. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdata.id);
  75. _ui.m_comCard.m_loaType.url = ResPathUtil.GetCommonGameResPath("hd_sxicon_" + itemCfg.rarity);
  76. _ui.m_comCard.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  77. int mainScore = 0;
  78. int mainScoreValue = 0;
  79. ItemDataManager.GetMainScore(itemdata.id, out mainScore, out mainScoreValue);
  80. _ui.m_comCard.m_loaProperty.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + mainScore);
  81. _ui.m_comCard.m_txtName.text = itemCfg.name;
  82. _ui.m_comCard.m_txtDiscribe.text = itemCfg.desc;
  83. _ui.m_comCard.m_holder.visible = true;
  84. if (LuckyBoxDataManager.Instance.FirstRewardList.ContainsKey(_showRewardList.Count - 1) == true)
  85. {
  86. LuckyBoxDataManager.Instance.FirstRewardList.Remove(_showRewardList.Count - 1);
  87. }
  88. _showRewardList.RemoveAt(_showRewardList.Count - 1);
  89. }
  90. private void OnClickBg()
  91. {
  92. if (_newRewardList.Count == 0 && _oldRewardList.Count == 0)
  93. {
  94. // if (_type == (int)FirstGetCardViewType.JUMP)
  95. // {
  96. ViewManager.Show(ViewName.LUCKY_BOX_BONUS_VIEW, new object[] { (this.viewData as object[])[0] as List<ItemData>, _rewardList });
  97. // }
  98. // else if (_type == (int)FirstGetCardViewType.CANNOT_JUMP)
  99. // {
  100. // GetSuitItemController.TryShow(0);
  101. // }
  102. this.Hide();
  103. return;
  104. }
  105. _ui.m_t_close.Play(() =>
  106. {
  107. _ui.m_comCard.m_holder.visible = false;
  108. _ui.m_t_open.Play();
  109. UpdateView();
  110. });
  111. }
  112. private int GetThisCount(int itemId, List<ItemData> rewards)
  113. {
  114. int count = 0;
  115. for (int i = 0; i < rewards.Count; i++)
  116. {
  117. if (rewards[i].id == itemId)
  118. {
  119. count++;
  120. }
  121. }
  122. return count;
  123. }
  124. private bool IsAddToNewRewardList(int itemId)
  125. {
  126. for (int i = 0; i < _newRewardList.Count; i++)
  127. {
  128. if (itemId == _newRewardList[i].id)
  129. {
  130. return true;
  131. }
  132. }
  133. return false;
  134. }
  135. private void OnClickBtnPass()
  136. {
  137. ViewManager.Show(ViewName.LUCKY_BOX_BONUS_VIEW, new object[] { (this.viewData as object[])[0], _rewardList });
  138. this.Hide();
  139. }
  140. protected override void OnHide()
  141. {
  142. _ui.m_t_close.Stop(true, false);
  143. _ui.m_t_open.Stop(true, false);
  144. base.OnHide();
  145. }
  146. }
  147. }