LuckyBoxNewDressView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_ck", "ui_ck_zs",
  82. onComplete: (effect) =>
  83. {
  84. if (effect != null)
  85. {
  86. _effectUI1 = effect;
  87. }
  88. });
  89. EffectUIPool.CreateEffectUI(_ui.m_holder_star, "ui_LuckyBox", "bg_liuxing",
  90. onComplete: (effect) =>
  91. {
  92. if (effect != null)
  93. {
  94. _effectUI2 = effect;
  95. }
  96. });
  97. EffectUIPool.CreateEffectUI(_ui.m_holder_bg, "ui_LuckyBox", "CK_UI",
  98. onComplete: (effect) =>
  99. {
  100. if (effect != null)
  101. {
  102. _effectUI3 = effect;
  103. }
  104. });
  105. EffectUIPool.CreateEffectUI(_ui.m_holder_cloud, "ui_LuckyBox", "bg_cloud",
  106. onComplete: (effect) =>
  107. {
  108. if (effect != null)
  109. {
  110. _effectUI4 = effect;
  111. }
  112. });
  113. }
  114. protected override void OnShown()
  115. {
  116. try
  117. {
  118. base.OnShown();
  119. // 确保UI已经创建
  120. if (_ui == null || _ui.m_t_open == null)
  121. {
  122. Debug.LogError("UI components not initialized properly!");
  123. return;
  124. }
  125. _ui.m_loaBg.touchable = false;
  126. _rewardParamList.Clear();
  127. _rewardList.Clear();
  128. _rewardParamList.AddRange(this.viewData as List<ItemData>);
  129. _rewardList = this.viewData as List<ItemData>;
  130. _newRewardList.Clear();
  131. _oldRewardList.Clear();
  132. for (int i = 0; i < _rewardList.Count; i++)
  133. {
  134. long hasCount = ItemDataManager.GetItemNum(_rewardList[i].id);
  135. int thisCount = GetThisCount(_rewardList[i].id, _rewardList);
  136. bool isAddToNew = IsAddToNewRewardList(_rewardList[i].id);
  137. if (thisCount == Convert.ToInt32(hasCount) && !isAddToNew)
  138. {
  139. _newRewardList.Add(_rewardList[i]);
  140. }
  141. else
  142. {
  143. _oldRewardList.Add(_rewardList[i]);
  144. }
  145. }
  146. UpdateView();
  147. OnTimerClick(1);
  148. }
  149. catch (Exception e)
  150. {
  151. Debug.LogError(e);
  152. }
  153. //Timers.inst.Add((float)0.5, 1, OnTimerClick);
  154. }
  155. private void UpdateView()
  156. {
  157. // 确保UI组件存在
  158. if (_ui == null || _ui.m_comCard == null || _ui.m_comCard.m_holder == null ||
  159. _ui.m_comCard.m_holder1 == null || _ui.m_comCard.m_holder_get == null)
  160. {
  161. Debug.LogError("UI components not initialized properly!");
  162. return;
  163. }
  164. // 清理旧特效
  165. EffectUIPool.Recycle(_effectUI5);
  166. _effectUI5 = null;
  167. EffectUIPool.Recycle(_effectUI6);
  168. _effectUI6 = null;
  169. EffectUIPool.Recycle(_effectUI7);
  170. _effectUI7 = null;
  171. _rewardList = _newRewardList.Count > 0 ? _newRewardList : _oldRewardList;
  172. if (_rewardList.Count - 1 < 0)
  173. {
  174. Debug.LogWarning("No rewards to show");
  175. return;
  176. }
  177. ItemData itemdata = _rewardList[_rewardList.Count - 1];
  178. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemdata.id);
  179. if (itemCfg == null)
  180. {
  181. Debug.LogError($"Item config not found for id: {itemdata.id}");
  182. return;
  183. }
  184. // 根据稀有度创建特效
  185. switch (itemCfg.Rarity)
  186. {
  187. case ConstDressRarity.Rarity_TIANYI:
  188. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Yellow_01", 100,
  189. (effect) =>
  190. {
  191. _effectUI5 = effect;
  192. _ui.m_comCard.m_holder.visible = true;
  193. });
  194. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Yellow_01_top", 100,
  195. (effect) =>
  196. {
  197. _effectUI6 = effect;
  198. _ui.m_comCard.m_holder1.visible = true;
  199. });
  200. break;
  201. case ConstDressRarity.Rarity_GUOSE:
  202. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_GS_012", 100,
  203. (effect) =>
  204. {
  205. _effectUI5 = effect;
  206. _ui.m_comCard.m_holder.visible = true;
  207. });
  208. break;
  209. case ConstDressRarity.Rarity_DIANCANG:
  210. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Purple_02", 100,
  211. (effect) =>
  212. {
  213. _effectUI5 = effect;
  214. _ui.m_comCard.m_holder.visible = true;
  215. });
  216. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder1, "ui_LuckyBox", "CK_Purple_02_top", 100,
  217. (effect) =>
  218. {
  219. _effectUI6 = effect;
  220. _ui.m_comCard.m_holder1.visible = true;
  221. });
  222. break;
  223. case ConstDressRarity.Rarity_ZHENXI:
  224. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_Bule_03", 100,
  225. (effect) =>
  226. {
  227. _effectUI5 = effect;
  228. _ui.m_comCard.m_holder.visible = true;
  229. });
  230. break;
  231. case ConstDressRarity.Rarity_FANPIN:
  232. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder, "ui_LuckyBox", "CK_grey_04", 100,
  233. (effect) =>
  234. {
  235. _effectUI5 = effect;
  236. _ui.m_comCard.m_holder.visible = true;
  237. });
  238. break;
  239. }
  240. EffectUIPool.CreateEffectUI(_ui.m_comCard.m_holder_get, "ui_LuckyBox", "CK_OneBigCard_end",
  241. onComplete: (effect) =>
  242. {
  243. if (effect != null)
  244. {
  245. _effectUI7 = effect;
  246. }
  247. });
  248. // 更新UI显示
  249. _ui.m_comCard.m_loaType.url = ResPathUtil.GetCommonGameResPath("hz_bq_shuxing_" + itemCfg.Rarity);
  250. _ui.m_comCard.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  251. _ui.m_comCard.m_loaProperty.url = ResPathUtil.GetCommonGameResPath("kp_sx_" + itemCfg.MainScore);
  252. _ui.m_comCard.m_txtName.text = itemCfg.Name;
  253. _ui.m_comCard.m_txtDiscribe.text = itemCfg.Desc;
  254. // 确保过渡动画对象存在
  255. if (_ui.m_t_open != null)
  256. {
  257. if (itemCfg.ItemType == ConstItemType.CARD)
  258. {
  259. //_ui.m_t_open.Play(() => { ViewManager.Show<LuckyBoxNewCardView>(itemCfg.Id); });
  260. ViewManager.Show<LuckyBoxNewCardView>(itemCfg.Id);
  261. }
  262. else
  263. {
  264. //_ui.m_t_open.Play();
  265. }
  266. }
  267. else
  268. {
  269. Debug.LogError("Transition m_t_open is null!");
  270. }
  271. if (LuckyBoxDataManager.Instance.FirstRewardList.ContainsKey(_rewardList.Count - 1))
  272. {
  273. LuckyBoxDataManager.Instance.FirstRewardList.Remove(_rewardList.Count - 1);
  274. }
  275. _rewardList.RemoveAt(_rewardList.Count - 1);
  276. }
  277. private void OnTimerClick(object param)
  278. {
  279. _ui.m_loaBg.touchable = true;
  280. }
  281. private void OnClickBg()
  282. {
  283. //_ui.m_t_close.Play(() =>
  284. //{
  285. //_ui.m_comCard.m_holder.visible = false;
  286. //_ui.m_comCard.m_holder1.visible = false;
  287. //if (_newRewardList.Count == 0 && _oldRewardList.Count == 0)
  288. //{
  289. if (!GetSuitItemController.isAuto)
  290. {
  291. this.Hide();
  292. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_REWARD_SHOW);
  293. }
  294. // }
  295. // else {
  296. // _ui.m_t_open.Play();
  297. // UpdateView();
  298. // }
  299. //});
  300. }
  301. private int GetThisCount(int itemId, List<ItemData> rewards)
  302. {
  303. int count = 0;
  304. for (int i = 0; i < rewards.Count; i++)
  305. {
  306. if (rewards[i].id == itemId)
  307. {
  308. count++;
  309. }
  310. }
  311. return count;
  312. }
  313. private bool IsAddToNewRewardList(int itemId)
  314. {
  315. for (int i = 0; i < _newRewardList.Count; i++)
  316. {
  317. if (itemId == _newRewardList[i].id)
  318. {
  319. return true;
  320. }
  321. }
  322. return false;
  323. }
  324. protected override void OnHide()
  325. {
  326. EffectUIPool.Recycle(_effectUI5);
  327. _effectUI5 = null;
  328. EffectUIPool.Recycle(_effectUI6);
  329. _effectUI6 = null;
  330. _ui.m_t_close.Stop(true, false);
  331. _ui.m_t_open.Stop(true, false);
  332. _rewardList.Clear();
  333. // Timers.inst.Remove(OnTimerClick);
  334. _ui.m_loaBg.touchable = true;
  335. base.OnHide();
  336. //ViewManager.Show<LuckyBoxBonusShowView>(_rewardParamList);
  337. }
  338. }
  339. }