LuckyBoxNewDressView.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UI.LuckyBox;
  5. using System.Collections.Generic;
  6. using FairyGUI;
  7. using System.Linq;
  8. using cfg.GfgCfg;
  9. using ET;
  10. namespace GFGGame
  11. {
  12. public class LuckyBoxNewDressView : BaseWindow
  13. {
  14. private UI_LuckyBoxNewDressUI _ui;
  15. private List<ItemData> _rewardList = new List<ItemData>();
  16. private List<ItemData> _rewardParamList = new List<ItemData>();
  17. private List<ItemData> _newRewardList = new List<ItemData>();
  18. private List<ItemData> _oldRewardList = new List<ItemData>();
  19. // private List<ItemData> _showRewardList = new List<ItemData>();
  20. // private int _type = 0;//弹窗类型:0可跳过,1:首次获得物品不可跳过,2首次获得物品不可跳过,不弹获得套装界面
  21. private EffectUI _effectUI1;
  22. private EffectUI _effectUI2;
  23. private EffectUI _effectUI3;
  24. private EffectUI _effectUI4;
  25. private EffectUI _effectUI5;
  26. private EffectUI _effectUI6;
  27. private EffectUI _effectUI7;
  28. public override void Dispose()
  29. {
  30. EffectUIPool.Recycle(_effectUI1);
  31. _effectUI1 = null;
  32. EffectUIPool.Recycle(_effectUI2);
  33. _effectUI2 = null;
  34. EffectUIPool.Recycle(_effectUI3);
  35. _effectUI3 = null;
  36. EffectUIPool.Recycle(_effectUI4);
  37. _effectUI4 = null;
  38. if (_ui != null)
  39. {
  40. _ui.Dispose();
  41. _ui = null;
  42. }
  43. base.Dispose();
  44. }
  45. protected override void OnInit()
  46. {
  47. try
  48. {
  49. base.OnInit();
  50. packageName = UI_LuckyBoxNewDressUI.PACKAGE_NAME;
  51. _ui = UI_LuckyBoxNewDressUI.Create();
  52. if (_ui == null)
  53. {
  54. Debug.LogError("Failed to create UI_LuckyBoxNewDressUI!");
  55. return;
  56. }
  57. this.viewCom = _ui.target;
  58. isfullScreen = true;
  59. this.modal = true;
  60. if (_ui.m_loaBg != null)
  61. {
  62. _ui.m_loaBg.onTouchBegin.Add(OnClickBg);
  63. }
  64. if (_ui.m_btnPass != null)
  65. {
  66. _ui.m_btnPass.onClick.Add(Hide);
  67. }
  68. if (_ui.m_loaBg != null)
  69. {
  70. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  71. }
  72. UpdateEffect();
  73. }
  74. catch (Exception e)
  75. {
  76. Debug.LogError(e);
  77. }
  78. }
  79. private void UpdateEffect()
  80. {
  81. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_ck", "ui_ck_zs");
  82. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holder_star, "ui_LuckyBox", "bg_liuxing");
  83. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holder_bg, "ui_LuckyBox", "CK_UI");
  84. _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_holder_cloud, "ui_LuckyBox", "bg_cloud");
  85. }
  86. protected override void OnShown()
  87. {
  88. try
  89. {
  90. base.OnShown();
  91. // 确保UI已经创建
  92. if (_ui == null || _ui.m_t_open == null)
  93. {
  94. Debug.LogError("UI components not initialized properly!");
  95. return;
  96. }
  97. _ui.m_loaBg.touchable = false;
  98. _rewardParamList.Clear();
  99. _rewardList.Clear();
  100. _rewardParamList.AddRange(this.viewData as List<ItemData>);
  101. _rewardList = this.viewData as List<ItemData>;
  102. _newRewardList.Clear();
  103. _oldRewardList.Clear();
  104. for (int i = 0; i < _rewardList.Count; i++)
  105. {
  106. long hasCount = ItemDataManager.GetItemNum(_rewardList[i].id);
  107. int thisCount = GetThisCount(_rewardList[i].id, _rewardList);
  108. bool isAddToNew = IsAddToNewRewardList(_rewardList[i].id);
  109. if (thisCount == Convert.ToInt32(hasCount) && !isAddToNew)
  110. {
  111. _newRewardList.Add(_rewardList[i]);
  112. }
  113. else
  114. {
  115. _oldRewardList.Add(_rewardList[i]);
  116. }
  117. }
  118. UpdateView();
  119. OnTimerClick(1);
  120. }
  121. catch (Exception e)
  122. {
  123. Debug.LogError(e);
  124. }
  125. //Timers.inst.Add((float)0.5, 1, OnTimerClick);
  126. }
  127. private void UpdateView()
  128. {
  129. // 确保UI组件存在
  130. if (_ui == null || _ui.m_comCard == null || _ui.m_comCard.m_holder == null ||
  131. _ui.m_comCard.m_holder1 == null || _ui.m_comCard.m_holder_get == null)
  132. {
  133. Debug.LogError("UI components not initialized properly!");
  134. return;
  135. }
  136. // 清理旧特效
  137. EffectUIPool.Recycle(_effectUI5);
  138. _effectUI5 = null;
  139. EffectUIPool.Recycle(_effectUI6);
  140. _effectUI6 = null;
  141. EffectUIPool.Recycle(_effectUI7);
  142. _effectUI7 = null;
  143. _rewardList = _newRewardList.Count > 0 ? _newRewardList : _oldRewardList;
  144. if (_rewardList.Count - 1 < 0)
  145. {
  146. Debug.LogWarning("No rewards to show");
  147. return;
  148. }
  149. ItemData itemdata = _rewardList[_rewardList.Count - 1];
  150. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemdata.id);
  151. if (itemCfg == null)
  152. {
  153. Debug.LogError($"Item config not found for id: {itemdata.id}");
  154. return;
  155. }
  156. // 根据稀有度创建特效
  157. switch (itemCfg.Rarity)
  158. {
  159. case ConstDressRarity.Rarity_TIANYI:
  160. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Yellow_01", 100,
  161. () => { _ui.m_comCard.m_holder.visible = true; });
  162. _effectUI6 =
  163. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Yellow_01_top", 100,
  164. () => { _ui.m_comCard.m_holder1.visible = true; });
  165. break;
  166. case ConstDressRarity.Rarity_GUOSE:
  167. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_GS_012", 100,
  168. () => { _ui.m_comCard.m_holder.visible = true; });
  169. break;
  170. case ConstDressRarity.Rarity_DIANCANG:
  171. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Purple_02", 100,
  172. () => { _ui.m_comCard.m_holder.visible = true; });
  173. _effectUI6 =
  174. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Purple_02_top", 100,
  175. () => { _ui.m_comCard.m_holder1.visible = true; });
  176. break;
  177. case ConstDressRarity.Rarity_ZHENXI:
  178. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Bule_03", 100,
  179. () => { _ui.m_comCard.m_holder.visible = true; });
  180. break;
  181. case ConstDressRarity.Rarity_FANPIN:
  182. _effectUI5 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_grey_04", 100,
  183. () => { _ui.m_comCard.m_holder.visible = true; });
  184. break;
  185. }
  186. _effectUI7 = EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder_get, "ui_LuckyBox", "CK_OneBigCard_end");
  187. // 更新UI显示
  188. _ui.m_comCard.m_loaType.url = ResPathUtil.GetCommonGameResPath("hz_bq_shuxing_" + itemCfg.Rarity);
  189. _ui.m_comCard.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  190. _ui.m_comCard.m_loaProperty.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.MainScore);
  191. _ui.m_comCard.m_txtName.text = itemCfg.Name;
  192. _ui.m_comCard.m_txtDiscribe.text = itemCfg.Desc;
  193. // 确保过渡动画对象存在
  194. if (_ui.m_t_open != null)
  195. {
  196. if (itemCfg.ItemType == ConstItemType.CARD)
  197. {
  198. //_ui.m_t_open.Play(() => { ViewManager.Show<LuckyBoxNewCardView>(itemCfg.Id); });
  199. ViewManager.Show<LuckyBoxNewCardView>(itemCfg.Id);
  200. }
  201. else
  202. {
  203. //_ui.m_t_open.Play();
  204. }
  205. }
  206. else
  207. {
  208. Debug.LogError("Transition m_t_open is null!");
  209. }
  210. if (LuckyBoxDataManager.Instance.FirstRewardList.ContainsKey(_rewardList.Count - 1))
  211. {
  212. LuckyBoxDataManager.Instance.FirstRewardList.Remove(_rewardList.Count - 1);
  213. }
  214. _rewardList.RemoveAt(_rewardList.Count - 1);
  215. }
  216. private void OnTimerClick(object param)
  217. {
  218. _ui.m_loaBg.touchable = true;
  219. }
  220. private void OnClickBg()
  221. {
  222. //_ui.m_t_close.Play(() =>
  223. //{
  224. //_ui.m_comCard.m_holder.visible = false;
  225. //_ui.m_comCard.m_holder1.visible = false;
  226. //if (_newRewardList.Count == 0 && _oldRewardList.Count == 0)
  227. //{
  228. if (!GetSuitItemController.isAuto)
  229. {
  230. this.Hide();
  231. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_REWARD_SHOW);
  232. }
  233. // }
  234. // else {
  235. // _ui.m_t_open.Play();
  236. // UpdateView();
  237. // }
  238. //});
  239. }
  240. private int GetThisCount(int itemId, List<ItemData> rewards)
  241. {
  242. int count = 0;
  243. for (int i = 0; i < rewards.Count; i++)
  244. {
  245. if (rewards[i].id == itemId)
  246. {
  247. count++;
  248. }
  249. }
  250. return count;
  251. }
  252. private bool IsAddToNewRewardList(int itemId)
  253. {
  254. for (int i = 0; i < _newRewardList.Count; i++)
  255. {
  256. if (itemId == _newRewardList[i].id)
  257. {
  258. return true;
  259. }
  260. }
  261. return false;
  262. }
  263. protected override void OnHide()
  264. {
  265. EffectUIPool.Recycle(_effectUI5);
  266. _effectUI5 = null;
  267. EffectUIPool.Recycle(_effectUI6);
  268. _effectUI6 = null;
  269. _ui.m_t_close.Stop(true, false);
  270. _ui.m_t_open.Stop(true, false);
  271. _rewardList.Clear();
  272. // Timers.inst.Remove(OnTimerClick);
  273. _ui.m_loaBg.touchable = true;
  274. base.OnHide();
  275. //ViewManager.Show<LuckyBoxBonusShowView>(_rewardParamList);
  276. }
  277. }
  278. }