LuckyBoxNewDressView.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. _ui.m_loaBg.touchable = false;
  66. _rewardParamList.Clear();
  67. _rewardList.Clear();
  68. _rewardParamList.AddRange(this.viewData as List<ItemData>);
  69. _rewardList = this.viewData as List<ItemData>;
  70. //_ui.m_btnPass.visible = false;
  71. _newRewardList.Clear();
  72. _oldRewardList.Clear();
  73. for (int i = 0; i < _rewardList.Count; i++)
  74. {
  75. long hasCount = ItemDataManager.GetItemNum(_rewardList[i].id);
  76. int thisCount = GetThisCount(_rewardList[i].id, _rewardList);
  77. bool isAddToNew = IsAddToNewRewardList(_rewardList[i].id);
  78. if (thisCount == hasCount && !isAddToNew)
  79. {
  80. _newRewardList.Add(_rewardList[i]);
  81. }
  82. else
  83. {
  84. _oldRewardList.Add(_rewardList[i]);
  85. }
  86. }
  87. UpdateView();
  88. Timers.inst.Add(0.5f, 1, OnTimerClick);
  89. }
  90. private void UpdateView()
  91. {
  92. if (_effectUI5 != null)
  93. {
  94. EffectUIPool.Recycle(_effectUI5);
  95. _effectUI5 = null;
  96. }
  97. if (_effectUI6 != null)
  98. {
  99. EffectUIPool.Recycle(_effectUI6);
  100. _effectUI6 = null;
  101. }
  102. if (_effectUI7 != null)
  103. {
  104. EffectUIPool.Recycle(_effectUI7);
  105. _effectUI7 = null;
  106. }
  107. //_ui.m_btnPass.visible = _newRewardList.Count <= 1;
  108. _rewardList = _newRewardList.Count > 0 ? _newRewardList : _oldRewardList;
  109. if (_rewardList.Count - 1 < 0) return;
  110. ItemData itemdata = _rewardList[_rewardList.Count - 1];
  111. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemdata.id);
  112. switch (itemCfg.rarity)
  113. {
  114. case ConstDressRarity.Rarity_TIANYI:
  115. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Yellow_01");
  116. _ui.m_comCard.m_holder.visible = true;
  117. _effectUI6 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Yellow_01_top");
  118. _ui.m_comCard.m_holder1.visible = true;
  119. break;
  120. case ConstDressRarity.Rarity_GUOSE:
  121. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_GS_012");
  122. _ui.m_comCard.m_holder.visible = true;
  123. break;
  124. case ConstDressRarity.Rarity_DIANCANG:
  125. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Purple_02");
  126. _ui.m_comCard.m_holder.visible = true;
  127. _effectUI6 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Purple_02_top");
  128. _ui.m_comCard.m_holder1.visible = true;
  129. break;
  130. case ConstDressRarity.Rarity_ZHENXI:
  131. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Bule_03");
  132. _ui.m_comCard.m_holder.visible = true;
  133. break;
  134. case ConstDressRarity.Rarity_FANPIN:
  135. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_grey_04");
  136. _ui.m_comCard.m_holder.visible = true;
  137. break;
  138. }
  139. _effectUI7 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder_get, "ui_LuckyBox", "CK_OneBigCard_end");
  140. _ui.m_comCard.m_loaType.url = ResPathUtil.GetCommonGameResPath("hz_bq_shuxing_" + itemCfg.rarity);
  141. _ui.m_comCard.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  142. _ui.m_comCard.m_loaProperty.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.mainScore);
  143. _ui.m_comCard.m_txtName.text = itemCfg.name;
  144. _ui.m_comCard.m_txtDiscribe.text = itemCfg.desc;
  145. if (itemCfg.itemType == ConstItemType.CARD)
  146. {
  147. _ui.m_t_open.Play(() =>
  148. {
  149. ViewManager.Show<LuckyBoxNewCardView>(itemCfg.id);
  150. });
  151. }
  152. else
  153. {
  154. _ui.m_t_open.Play();
  155. }
  156. if (LuckyBoxDataManager.Instance.FirstRewardList.ContainsKey(_rewardList.Count - 1) == true)
  157. {
  158. LuckyBoxDataManager.Instance.FirstRewardList.Remove(_rewardList.Count - 1);
  159. }
  160. _rewardList.RemoveAt(_rewardList.Count - 1);
  161. }
  162. private void OnTimerClick(object param)
  163. {
  164. _ui.m_loaBg.touchable = true;
  165. }
  166. private void OnClickBg()
  167. {
  168. //_ui.m_t_close.Play(() =>
  169. //{
  170. //_ui.m_comCard.m_holder.visible = false;
  171. //_ui.m_comCard.m_holder1.visible = false;
  172. //if (_newRewardList.Count == 0 && _oldRewardList.Count == 0)
  173. //{
  174. if (!GetSuitItemController.isAuto)
  175. {
  176. this.Hide();
  177. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_REWARD_SHOW);
  178. }
  179. // }
  180. // else {
  181. // _ui.m_t_open.Play();
  182. // UpdateView();
  183. // }
  184. //});
  185. }
  186. private int GetThisCount(int itemId, List<ItemData> rewards)
  187. {
  188. int count = 0;
  189. for (int i = 0; i < rewards.Count; i++)
  190. {
  191. if (rewards[i].id == itemId)
  192. {
  193. count++;
  194. }
  195. }
  196. return count;
  197. }
  198. private bool IsAddToNewRewardList(int itemId)
  199. {
  200. for (int i = 0; i < _newRewardList.Count; i++)
  201. {
  202. if (itemId == _newRewardList[i].id)
  203. {
  204. return true;
  205. }
  206. }
  207. return false;
  208. }
  209. protected override void OnHide()
  210. {
  211. EffectUIPool.Recycle(_effectUI5);
  212. _effectUI5 = null;
  213. EffectUIPool.Recycle(_effectUI6);
  214. _effectUI6 = null;
  215. _ui.m_t_close.Stop(true, false);
  216. _ui.m_t_open.Stop(true, false);
  217. _rewardList.Clear();
  218. Timers.inst.Remove(OnTimerClick);
  219. _ui.m_loaBg.touchable = true;
  220. base.OnHide();
  221. //ViewManager.Show<LuckyBoxBonusShowView>(_rewardParamList);
  222. }
  223. }
  224. }