LuckyBoxNewDressView.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 LuckyBoxNewDressView : BaseWindow
  10. {
  11. private UI_LuckyBoxNewDressUI _ui;
  12. private List<ItemData> _rewardList = new List<ItemData>();
  13. private List<ItemData> _rewardParamList = new List<ItemData>();
  14. private List<ItemData> _newRewardList = new List<ItemData>();
  15. private List<ItemData> _oldRewardList = new List<ItemData>();
  16. // private List<ItemData> _showRewardList = new List<ItemData>();
  17. // private int _type = 0;//弹窗类型:0可跳过,1:首次获得物品不可跳过,2首次获得物品不可跳过,不弹获得套装界面
  18. private EffectUI _effectUI1;
  19. private EffectUI _effectUI2;
  20. private EffectUI _effectUI3;
  21. private EffectUI _effectUI4;
  22. private EffectUI _effectUI5;
  23. private EffectUI _effectUI6;
  24. public override void Dispose()
  25. {
  26. EffectUIPool.Recycle(_effectUI1);
  27. _effectUI1 = null;
  28. EffectUIPool.Recycle(_effectUI2);
  29. _effectUI2 = null;
  30. EffectUIPool.Recycle(_effectUI3);
  31. _effectUI3 = null;
  32. EffectUIPool.Recycle(_effectUI4);
  33. _effectUI4 = null;
  34. if (_ui != null)
  35. {
  36. _ui.Dispose();
  37. _ui = null;
  38. }
  39. base.Dispose();
  40. }
  41. protected override void OnInit()
  42. {
  43. base.OnInit();
  44. packageName = UI_LuckyBoxNewDressUI.PACKAGE_NAME;
  45. _ui = UI_LuckyBoxNewDressUI.Create();
  46. this.viewCom = _ui.target;
  47. isfullScreen = true;
  48. this.modal = true;
  49. _ui.m_loaBg.onTouchBegin.Add(OnClickBg);
  50. _ui.m_btnPass.onClick.Add(Hide);
  51. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  52. UpdateEffect();
  53. }
  54. private void UpdateEffect()
  55. {
  56. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_ck", "ui_ck_zs");
  57. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holder_star, "ui_LuckyBox", "bg_liuxing");
  58. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holder_bg, "ui_LuckyBox", "CK_UI");
  59. _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_holder_cloud, "ui_LuckyBox", "bg_cloud");
  60. }
  61. protected override void OnShown()
  62. {
  63. base.OnShown();
  64. _rewardParamList.Clear();
  65. _rewardList.Clear();
  66. _rewardParamList.AddRange(this.viewData as List<ItemData>);
  67. _rewardList = this.viewData as List<ItemData>;
  68. _ui.m_btnPass.visible = false;
  69. _newRewardList.Clear();
  70. _oldRewardList.Clear();
  71. for (int i = 0; i < _rewardList.Count; i++)
  72. {
  73. long hasCount = ItemDataManager.GetItemNum(_rewardList[i].id);
  74. int thisCount = GetThisCount(_rewardList[i].id, _rewardList);
  75. bool isAddToNew = IsAddToNewRewardList(_rewardList[i].id);
  76. if (thisCount == hasCount && !isAddToNew)
  77. {
  78. _newRewardList.Add(_rewardList[i]);
  79. }
  80. else
  81. {
  82. _oldRewardList.Add(_rewardList[i]);
  83. }
  84. }
  85. UpdateView();
  86. }
  87. private void UpdateView()
  88. {
  89. if (_effectUI5 != null)
  90. {
  91. EffectUIPool.Recycle(_effectUI5);
  92. _effectUI5 = null;
  93. }
  94. if (_effectUI6 != null)
  95. {
  96. EffectUIPool.Recycle(_effectUI6);
  97. _effectUI6 = null;
  98. }
  99. _ui.m_btnPass.visible = _newRewardList.Count <= 1;
  100. _rewardList = _newRewardList.Count > 0 ? _newRewardList : _oldRewardList;
  101. if (_rewardList.Count - 1 < 0) return;
  102. ItemData itemdata = _rewardList[_rewardList.Count - 1];
  103. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdata.id);
  104. switch (itemCfg.rarity)
  105. {
  106. case ConstDressRarity.Rarity_TIANYI:
  107. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Yellow_01");
  108. _ui.m_comCard.m_holder.visible = true;
  109. _effectUI6 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Yellow_01_top");
  110. _ui.m_comCard.m_holder1.visible = true;
  111. break;
  112. case ConstDressRarity.Rarity_DIANCANG:
  113. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Purple_02");
  114. _ui.m_comCard.m_holder.visible = true;
  115. _effectUI6 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Purple_02_top");
  116. _ui.m_comCard.m_holder1.visible = true;
  117. break;
  118. case ConstDressRarity.Rarity_ZHENXI:
  119. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Bule_03");
  120. _ui.m_comCard.m_holder.visible = true;
  121. break;
  122. case ConstDressRarity.Rarity_FANPIN:
  123. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_grey_04");
  124. _ui.m_comCard.m_holder.visible = true;
  125. break;
  126. }
  127. _ui.m_comCard.m_loaType.url = ResPathUtil.GetCommonGameResPath("hd_sxicon_" + itemCfg.rarity);
  128. _ui.m_comCard.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  129. _ui.m_comCard.m_loaProperty.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.mainScore);
  130. _ui.m_comCard.m_txtName.text = itemCfg.name;
  131. _ui.m_comCard.m_txtDiscribe.text = itemCfg.desc;
  132. if (itemCfg.itemType == ConstItemType.CARD)
  133. {
  134. _ui.m_t_open.Play(() =>
  135. {
  136. ViewManager.Show<LuckyBoxNewCardView>(itemCfg.id);
  137. });
  138. }
  139. else
  140. {
  141. _ui.m_t_open.Play();
  142. }
  143. if (LuckyBoxDataManager.Instance.FirstRewardList.ContainsKey(_rewardList.Count - 1) == true)
  144. {
  145. LuckyBoxDataManager.Instance.FirstRewardList.Remove(_rewardList.Count - 1);
  146. }
  147. _rewardList.RemoveAt(_rewardList.Count - 1);
  148. }
  149. private void OnClickBg()
  150. {
  151. _ui.m_t_close.Play(() =>
  152. {
  153. _ui.m_comCard.m_holder.visible = false;
  154. _ui.m_comCard.m_holder1.visible = false;
  155. if (_newRewardList.Count == 0 && _oldRewardList.Count == 0)
  156. {
  157. this.Hide();
  158. }
  159. else {
  160. _ui.m_t_open.Play();
  161. UpdateView();
  162. }
  163. });
  164. }
  165. private int GetThisCount(int itemId, List<ItemData> rewards)
  166. {
  167. int count = 0;
  168. for (int i = 0; i < rewards.Count; i++)
  169. {
  170. if (rewards[i].id == itemId)
  171. {
  172. count++;
  173. }
  174. }
  175. return count;
  176. }
  177. private bool IsAddToNewRewardList(int itemId)
  178. {
  179. for (int i = 0; i < _newRewardList.Count; i++)
  180. {
  181. if (itemId == _newRewardList[i].id)
  182. {
  183. return true;
  184. }
  185. }
  186. return false;
  187. }
  188. protected override void OnHide()
  189. {
  190. EffectUIPool.Recycle(_effectUI5);
  191. _effectUI5 = null;
  192. EffectUIPool.Recycle(_effectUI6);
  193. _effectUI6 = null;
  194. _ui.m_t_close.Stop(true, false);
  195. _ui.m_t_open.Stop(true, false);
  196. _rewardList.Clear();
  197. base.OnHide();
  198. ViewManager.Show<LuckyBoxBonusShowView>(_rewardParamList);
  199. }
  200. }
  201. }