LuckyBoxCardView.cs 5.9 KB

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