LuckyBoxNewDressView.cs 9.0 KB

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