LuckyBoxNewDressView.cs 8.4 KB

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