LuckyBoxNewDressView.cs 7.7 KB

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