LuckyBoxNewDressView.cs 9.0 KB

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