LuckyBoxBonusShowView.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.LuckyBox;
  4. using System.Collections.Generic;
  5. using System.Collections;
  6. namespace GFGGame
  7. {
  8. public class LuckyBoxBonusShowView : BaseWindow
  9. {
  10. private UI_LuckBoxBonusShowUI _ui;
  11. private List<ItemData> _rewardList = new List<ItemData>();
  12. private List<ItemData> _rewardItemList = new List<ItemData>();
  13. private Dictionary<int, Dictionary<int, EffectUI>> _effListTen = new Dictionary<int, Dictionary<int, EffectUI>>();
  14. private Dictionary<int, EffectUI> _effList = new Dictionary<int, EffectUI>();
  15. private Dictionary<int, int> _itemIdList = new Dictionary<int, int>();
  16. private Dictionary<int, GComponent> _itemObjList = new Dictionary<int, GComponent>();
  17. private List<int> _recordOpenIndex = new List<int>(); //记录打开过得item位置
  18. private List<int> _recordTurnIndex = new List<int>(); //记录播放过item位置
  19. private int _chooseIndex = -1; //当前选中的index
  20. private int _countShow = 0; //第几次展示
  21. private int _countNewRecord = 0; //展示步骤
  22. private bool _handClick = false; //手动点击开启
  23. private EffectUI _effectUI1;
  24. private EffectUI _effectUI2;
  25. private EffectUI _effectUI3;
  26. private Dictionary<string, EffectUI> _effectUIDic = new Dictionary<string, EffectUI>();
  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. for (int key = 0; key < _effListTen.Count; key++)
  36. {
  37. if (_effListTen.ContainsKey(key))
  38. {
  39. for (int key1 = 0; key1 < _effListTen[key].Count; key1++)
  40. {
  41. if (_effListTen[key].ContainsKey(key1))
  42. {
  43. EffectUIPool.Recycle(_effListTen[key][key1]);
  44. _effListTen[key][key1] = null;
  45. }
  46. }
  47. }
  48. }
  49. _effListTen.Clear();
  50. for (int key = 0; key < _effList.Count; key++)
  51. {
  52. if (_effList.ContainsKey(key))
  53. {
  54. EffectUIPool.Recycle(_effList[key]);
  55. _effList[key] = null;
  56. }
  57. }
  58. _effList.Clear();
  59. if (_ui != null)
  60. {
  61. _ui.Dispose();
  62. _ui = null;
  63. }
  64. base.Dispose();
  65. }
  66. protected override void OnInit()
  67. {
  68. base.OnInit();
  69. packageName = UI_LuckBoxBonusShowUI.PACKAGE_NAME;
  70. _ui = UI_LuckBoxBonusShowUI.Create();
  71. this.viewCom = _ui.target;
  72. isfullScreen = true;
  73. _ui.m_loaBg.onClick.Add(OnClickLoaBg);
  74. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  75. _ui.m_BtnPass.onClick.Add(OnClickBtnPass);
  76. UpdateEffect();
  77. }
  78. private void UpdateEffect()
  79. {
  80. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder_star, "ui_LuckyBox", "bg_liuxing");
  81. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holder_bg, "ui_LuckyBox", "CK_UI");
  82. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holder_cloud, "ui_LuckyBox", "bg_cloud");
  83. }
  84. protected override void AddEventListener()
  85. {
  86. base.AddEventListener();
  87. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_REWARD_SHOW, ReferNextShow);
  88. }
  89. protected override void RemoveEventListener()
  90. {
  91. base.RemoveEventListener();
  92. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_REWARD_SHOW, ReferNextShow);
  93. }
  94. protected void ReferNextShow()
  95. {
  96. if (_chooseIndex != -1 && GetSuitItemController.GetSuitWaitingToId(_itemIdList[_chooseIndex]))
  97. ClickItem(_chooseIndex);
  98. else
  99. {
  100. if (_handClick)
  101. {
  102. _handClick = false;
  103. Timers.inst.Remove(UpClickDataTime);
  104. _ui.m_touchFlipOpen.touchable = false;
  105. }
  106. }
  107. }
  108. protected override void OnShown()
  109. {
  110. base.OnShown();
  111. _rewardList.AddRange(this.viewData as List<ItemData>);
  112. _itemIdList.Clear();
  113. _itemObjList.Clear();
  114. _recordOpenIndex.Clear();
  115. _recordTurnIndex.Clear();
  116. _ui.m_BtnPass.visible = true;
  117. _ui.m_touchFlipOpen.touchable = false;
  118. if (_rewardList.Count == 1)
  119. {
  120. _ui.m_c1.selectedIndex = 0;
  121. UpdateItem(_ui.m_itemOne.target, 0, 1);
  122. }
  123. else
  124. {
  125. _ui.m_c1.selectedIndex = 1;
  126. for (int i = 0; i < _rewardList.Count; i++)
  127. {
  128. UpdateItem(_ui.target.GetChild("item" + i).asCom, i, 10);
  129. }
  130. }
  131. }
  132. protected override void OnHide()
  133. {
  134. _rewardList.Clear();
  135. base.OnHide();
  136. Timers.inst.Remove(UpDataTime);
  137. Timers.inst.Remove(UpClickDataTime);
  138. foreach (var v in _effectUIDic)
  139. {
  140. EffectUIPool.Recycle(v.Value);
  141. }
  142. _effectUIDic.Clear();
  143. }
  144. private void UpdateItem(GComponent com, int index, int countType)
  145. {
  146. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
  147. ItemData itemData = _rewardList[index];
  148. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  149. item.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
  150. item.m_comIcon.m_txtName.text = itemCfg.name;
  151. item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  152. item.m_comIcon.m_FlipOpenType.selectedIndex = 1;
  153. item.m_comIcon.m_t1.Play();
  154. switch (itemCfg.rarity)
  155. {
  156. case 1:
  157. break;
  158. case 2:
  159. break;
  160. case 3:
  161. _effectUIDic.Add("CK_Loop_Wait_Chen" + index, EffectUIPool.CreateEffectUI(item.m_waitClick_eff, "ui_LuckyBox", "CK_Loop_Wait_Chen"));
  162. break;
  163. case 4:
  164. _effectUIDic.Add("CK_Loop_Wait_Jin" + index, EffectUIPool.CreateEffectUI(item.m_waitClick_eff, "ui_LuckyBox", "CK_Loop_Wait_Jin"));
  165. break;
  166. }
  167. //带特效的处理先注释
  168. //item.m_comIcon.m_holder.visible = false;
  169. //item.m_comIcon.m_holder1.visible = false;
  170. //if (itemCfg.rarity > 2) {
  171. // string resPath = itemCfg.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_01" : "CK_all_02";
  172. // GGraph holder = itemCfg.rarity == 3 ? item.m_comIcon.m_holder : item.m_comIcon.m_holder1;
  173. // holder.visible = true;
  174. // if (countType == 10 && (!_effListTen.ContainsKey(index) ||
  175. // ((itemCfg.rarity == 3 && !_effListTen[index].ContainsKey(0)) || (itemCfg.rarity == 4 && !_effListTen[index].ContainsKey(1)))))
  176. // {
  177. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  178. // if (!_effListTen.ContainsKey(index))
  179. // {
  180. // Dictionary<int, EffectUI> effectList = new Dictionary<int, EffectUI>();
  181. // if (itemCfg.rarity == 3)
  182. // effectList.Add(0, _effectUI);
  183. // else if (itemCfg.rarity == 4)
  184. // effectList.Add(1, _effectUI);
  185. // _effListTen.Add(index, effectList);
  186. // }
  187. // else {
  188. // if (itemCfg.rarity == 3)
  189. // _effListTen[index].Add(0, _effectUI);
  190. // else if (itemCfg.rarity == 4)
  191. // _effListTen[index].Add(1, _effectUI);
  192. // }
  193. // }
  194. // if (countType == 1 &&
  195. // ((itemCfg.rarity == 3 && !_effList.ContainsKey(0)) || (itemCfg.rarity == 4 && !_effList.ContainsKey(1))))
  196. // {
  197. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  198. // if (itemCfg.rarity == 3)
  199. // _effList.Add(0, _effectUI);
  200. // else if (itemCfg.rarity == 4)
  201. // _effList.Add(1, _effectUI);
  202. // }
  203. //}
  204. int count = 0;
  205. bool isFirst = false;
  206. for (int i = 0; i < _rewardList.Count; i++)
  207. {
  208. if (_rewardList[i].id == itemData.id) count++;
  209. if (count == 1 && i == index) isFirst = true;
  210. }
  211. item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
  212. item.m_t0.Play();
  213. if (item.target.data == null)
  214. {
  215. item.target.onClick.Add(ShowItemTips);
  216. }
  217. item.target.data = index;
  218. _itemIdList.Add(index, itemCfg.id);
  219. _itemObjList.Add(index, com);
  220. UI_LuckyBoxBonusShowItem.ProxyEnd();
  221. }
  222. private void ShowItemTips(EventContext context)
  223. {
  224. GObject obj = context.sender as GObject;
  225. int index = (int)obj.data;
  226. _chooseIndex = index;
  227. HandClickItem(index);
  228. }
  229. private void HandClickItem(int index)
  230. {
  231. _ui.m_touchFlipOpen.touchable = true;
  232. _handClick = true;
  233. ClickItem(index);
  234. Timers.inst.Add(1f, 1, UpClickDataTime, index);
  235. }
  236. private void UpClickDataTime(object param = null)
  237. {
  238. int index = (int)param;
  239. if (_recordTurnIndex.Contains(index) && _recordOpenIndex.Contains(index))
  240. {
  241. Timers.inst.Remove(UpClickDataTime);
  242. HideOtherShowWindow();
  243. _ui.m_touchFlipOpen.touchable = false;
  244. }
  245. else
  246. ClickItem(index);
  247. }
  248. void ClickItem(int index)
  249. {
  250. if (_recordOpenIndex.Count >= _rewardList.Count)
  251. _ui.m_BtnPass.visible = false;
  252. if (!_recordOpenIndex.Contains(index))
  253. TurnItem(index);
  254. else
  255. {
  256. if (!_recordTurnIndex.Contains(index))
  257. ShowTurnItem(index);
  258. else
  259. GoodsItemTipsController.ShowItemTips(_itemIdList[index]);
  260. }
  261. }
  262. private void OnClickLoaBg()
  263. {
  264. if (_recordOpenIndex.Count >= _rewardList.Count)
  265. {
  266. _chooseIndex = -1;
  267. this.Hide();
  268. }
  269. else
  270. {
  271. for (int index = 0; index < _rewardList.Count; index++)
  272. {
  273. if (!_recordOpenIndex.Contains(index))
  274. {
  275. _chooseIndex = index;
  276. HandClickItem(index);
  277. break;
  278. }
  279. }
  280. }
  281. }
  282. private void OnClickBtnPass()
  283. {
  284. for (int index = 0; index < _rewardList.Count; index++)
  285. {
  286. if (!_recordOpenIndex.Contains(index))
  287. {
  288. int count = 0;
  289. bool isFirst = false;
  290. for (int i = 0; i < _rewardList.Count; i++)
  291. {
  292. if (_rewardList[i].id == _rewardList[index].id) count++;
  293. if (count == 1 && i == index) isFirst = true;
  294. }
  295. bool open = count == ItemDataManager.GetItemNum(_rewardList[index].id) && isFirst;
  296. if (!open)
  297. {
  298. _chooseIndex = -1;
  299. ClickItem(index);
  300. }
  301. }
  302. }
  303. ClickPass();
  304. }
  305. private void ClickPass()
  306. {
  307. _ui.m_touchFlipOpen.touchable = true;
  308. _ui.m_BtnPass.visible = false;
  309. for (int i = 0; i < _rewardList.Count; i++)
  310. {
  311. TurnItem(i);
  312. }
  313. Timers.inst.Add(1f, 0, UpDataTime);
  314. }
  315. private void UpDataTime(object param = null)
  316. {
  317. _ui.m_touchFlipOpen.touchable = true;
  318. for (int i = 0; i < _rewardList.Count; i++)
  319. {
  320. if (!_recordTurnIndex.Contains(i))
  321. {
  322. ShowTurnItem(i);
  323. break;
  324. }
  325. }
  326. if (_recordTurnIndex.Count >= _rewardList.Count)
  327. {
  328. Timers.inst.Remove(UpDataTime);
  329. HideOtherShowWindow();
  330. _ui.m_touchFlipOpen.touchable = false;
  331. }
  332. }
  333. private void ShowTurnItem(int index)
  334. {
  335. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]);
  336. if (item.m_comIcon.m_imgNew.visible)
  337. {
  338. //判断是否有套装需要展示
  339. if (GetSuitItemController.GetSuitWaitingToId(_itemIdList[index]))
  340. {
  341. if (_countShow < 1)
  342. {
  343. _countShow += 1;
  344. ViewManager.Hide<GetSuitItemVIew>();
  345. _rewardItemList.Clear();
  346. _rewardItemList.Add(_rewardList[index]);
  347. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  348. }
  349. else
  350. {
  351. ViewManager.Hide<LuckyBoxNewDressView>();
  352. ViewManager.Hide<LuckyBoxNewCardView>();
  353. GetSuitItemController.TryShow(_itemIdList[index]);
  354. _recordTurnIndex.Add(index);
  355. _countShow = 0;
  356. if (_handClick)
  357. {
  358. _handClick = false;
  359. Timers.inst.Remove(UpClickDataTime);
  360. _ui.m_touchFlipOpen.touchable = false;
  361. }
  362. }
  363. }
  364. else
  365. {
  366. ViewManager.Hide<GetSuitItemVIew>();
  367. _rewardItemList.Clear();
  368. _rewardItemList.Add(_rewardList[index]);
  369. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  370. _recordTurnIndex.Add(index);
  371. _ui.m_touchFlipOpen.touchable = false;
  372. }
  373. }
  374. else
  375. {
  376. _recordTurnIndex.Add(index);
  377. _ui.m_touchFlipOpen.touchable = false;
  378. }
  379. UI_LuckyBoxBonusShowItem.ProxyEnd();
  380. }
  381. private void TurnItem(int index)
  382. {
  383. if (!_recordOpenIndex.Contains(index))
  384. {
  385. // 删除 “等待翻开” 的特效
  386. if (_effectUIDic.ContainsKey("CK_Loop_Wait_Chen" + index))
  387. {
  388. EffectUIPool.Recycle(_effectUIDic["CK_Loop_Wait_Chen" + index]);
  389. _effectUIDic.Remove("CK_Loop_Wait_Chen" + index);
  390. }
  391. if (_effectUIDic.ContainsKey("CK_Loop_Wait_Jin" + index))
  392. {
  393. EffectUIPool.Recycle(_effectUIDic["CK_Loop_Wait_Jin" + index]);
  394. _effectUIDic.Remove("CK_Loop_Wait_Jin" + index);
  395. }
  396. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]);
  397. if (!item.m_comIcon.m_imgNew.visible)
  398. _recordTurnIndex.Add(index);
  399. //先翻开牌面
  400. item.m_comIcon.m_FlipOpenType.selectedIndex = 0;
  401. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemIdList[index]);
  402. item.m_t2.Play();
  403. // 点击特效
  404. _effectUIDic.Add("CK_Cirle_DJ" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_click_eff, "ui_LuckyBox", "CK_Cirle_DJ"));
  405. // 翻开特效
  406. switch (itemCfg.rarity)
  407. {
  408. case 1:
  409. case 2:
  410. _effectUIDic.Add("CK_OpenAfter_LanHui_UI" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_LanHui_UI"));
  411. _effectUIDic.Add("CK_OpenAfter_LanHui_TX" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_LanHui_TX"));
  412. break;
  413. case 3:
  414. _effectUIDic.Add("CK_OpenAfter_Chen_UI" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_Chen_UI"));
  415. _effectUIDic.Add("CK_OpenAfter_Chen_TX" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_Chen_TX"));
  416. break;
  417. case 4:
  418. _effectUIDic.Add("CK_OpenAfter_Jin_UI" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_Jin_UI"));
  419. _effectUIDic.Add("CK_OpenAfter_Jin_TX" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_Jin_TX"));
  420. break;
  421. }
  422. item.m_comIcon.m_flip_eff.visible = false;
  423. item.m_comIcon.m_t0.Play();
  424. _recordOpenIndex.Add(index);
  425. UI_LuckyBoxBonusShowItem.ProxyEnd();
  426. }
  427. }
  428. private void HideOtherShowWindow()
  429. {
  430. ViewManager.Hide<GetSuitItemVIew>();
  431. ViewManager.Hide<LuckyBoxNewDressView>();
  432. ViewManager.Hide<LuckyBoxNewCardView>();
  433. }
  434. }
  435. }