LuckyBoxNewDressView.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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_GUOSE:
  119. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_GS_012");
  120. _ui.m_comCard.m_holder.visible = true;
  121. break;
  122. case ConstDressRarity.Rarity_DIANCANG:
  123. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Purple_02");
  124. _ui.m_comCard.m_holder.visible = true;
  125. _effectUI6 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Purple_02_top");
  126. _ui.m_comCard.m_holder1.visible = true;
  127. break;
  128. case ConstDressRarity.Rarity_ZHENXI:
  129. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Bule_03");
  130. _ui.m_comCard.m_holder.visible = true;
  131. break;
  132. case ConstDressRarity.Rarity_FANPIN:
  133. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_grey_04");
  134. _ui.m_comCard.m_holder.visible = true;
  135. break;
  136. }
  137. _effectUI7 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder_get, "ui_LuckyBox", "CK_OneBigCard_end");
  138. _ui.m_comCard.m_loaType.url = ResPathUtil.GetCommonGameResPath("hz_bq_shuxing_" + itemCfg.rarity);
  139. _ui.m_comCard.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  140. _ui.m_comCard.m_loaProperty.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.mainScore);
  141. _ui.m_comCard.m_txtName.text = itemCfg.name;
  142. _ui.m_comCard.m_txtDiscribe.text = itemCfg.desc;
  143. if (itemCfg.itemType == ConstItemType.CARD)
  144. {
  145. _ui.m_t_open.Play(() =>
  146. {
  147. ViewManager.Show<LuckyBoxNewCardView>(itemCfg.id);
  148. });
  149. }
  150. else
  151. {
  152. _ui.m_t_open.Play();
  153. }
  154. if (LuckyBoxDataManager.Instance.FirstRewardList.ContainsKey(_rewardList.Count - 1) == true)
  155. {
  156. LuckyBoxDataManager.Instance.FirstRewardList.Remove(_rewardList.Count - 1);
  157. }
  158. _rewardList.RemoveAt(_rewardList.Count - 1);
  159. }
  160. private void OnClickBg()
  161. {
  162. //_ui.m_t_close.Play(() =>
  163. //{
  164. //_ui.m_comCard.m_holder.visible = false;
  165. //_ui.m_comCard.m_holder1.visible = false;
  166. //if (_newRewardList.Count == 0 && _oldRewardList.Count == 0)
  167. //{
  168. if (!GetSuitItemController.isAuto)
  169. {
  170. this.Hide();
  171. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_REWARD_SHOW);
  172. }
  173. // }
  174. // else {
  175. // _ui.m_t_open.Play();
  176. // UpdateView();
  177. // }
  178. //});
  179. }
  180. private int GetThisCount(int itemId, List<ItemData> rewards)
  181. {
  182. int count = 0;
  183. for (int i = 0; i < rewards.Count; i++)
  184. {
  185. if (rewards[i].id == itemId)
  186. {
  187. count++;
  188. }
  189. }
  190. return count;
  191. }
  192. private bool IsAddToNewRewardList(int itemId)
  193. {
  194. for (int i = 0; i < _newRewardList.Count; i++)
  195. {
  196. if (itemId == _newRewardList[i].id)
  197. {
  198. return true;
  199. }
  200. }
  201. return false;
  202. }
  203. protected override void OnHide()
  204. {
  205. EffectUIPool.Recycle(_effectUI5);
  206. _effectUI5 = null;
  207. EffectUIPool.Recycle(_effectUI6);
  208. _effectUI6 = null;
  209. _ui.m_t_close.Stop(true, false);
  210. _ui.m_t_open.Stop(true, false);
  211. _rewardList.Clear();
  212. base.OnHide();
  213. //ViewManager.Show<LuckyBoxBonusShowView>(_rewardParamList);
  214. }
  215. }
  216. }