LuckyBoxBonusShowView.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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 bool _handClick = false; //手动点击开启
  22. private bool _AnimationWait = true; //抽卡动画等待加载完毕
  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. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_ANIMATION_WAIT, SetAnimationWait);
  89. }
  90. protected override void RemoveEventListener()
  91. {
  92. base.RemoveEventListener();
  93. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_REWARD_SHOW, ReferNextShow);
  94. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_ANIMATION_WAIT, SetAnimationWait);
  95. }
  96. protected void ReferNextShow()
  97. {
  98. int suitId = 0;
  99. if(_itemIdList.ContainsKey(_chooseIndex))
  100. suitId = SuitCfgArray.Instance.GetSuitIdOfItem(_itemIdList[_chooseIndex]);
  101. if (_chooseIndex != -1 && suitId > 0)
  102. ClickItem(_chooseIndex);
  103. else
  104. {
  105. if (_handClick)
  106. {
  107. _handClick = false;
  108. Timers.inst.Remove(UpClickDataTime);
  109. _ui.m_touchFlipOpen.touchable = false;
  110. }
  111. }
  112. }
  113. protected override void OnShown()
  114. {
  115. base.OnShown();
  116. _rewardList.AddRange(this.viewData as List<ItemData>);
  117. _itemIdList.Clear();
  118. _itemObjList.Clear();
  119. _recordOpenIndex.Clear();
  120. _recordTurnIndex.Clear();
  121. _ui.m_BtnPass.visible = true;
  122. _ui.m_touchFlipOpen.touchable = false;
  123. if (_rewardList.Count == 1)
  124. {
  125. _ui.m_c1.selectedIndex = 0;
  126. UpdateItem(_ui.m_itemOne.target, 0, 1);
  127. }
  128. else
  129. {
  130. _ui.m_c1.selectedIndex = 1;
  131. for (int i = 0; i < _rewardList.Count; i++)
  132. {
  133. UpdateItem(_ui.target.GetChild("item" + i).asCom, i, 10);
  134. }
  135. }
  136. }
  137. protected override void OnHide()
  138. {
  139. _rewardList.Clear();
  140. base.OnHide();
  141. Timers.inst.Remove(UpDataTime);
  142. Timers.inst.Remove(UpClickDataTime);
  143. foreach (var v in _effectUIDic)
  144. {
  145. EffectUIPool.Recycle(v.Value);
  146. }
  147. _effectUIDic.Clear();
  148. }
  149. private void UpdateItem(GComponent com, int index, int countType)
  150. {
  151. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
  152. ItemData itemData = _rewardList[index];
  153. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  154. item.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
  155. item.m_comIcon.m_txtName.text = itemCfg.name;
  156. item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  157. item.m_comIcon.m_FlipOpenType.selectedIndex = 1;
  158. item.m_comIcon.m_t1.Play();
  159. // 圆盘出现时等待玩家点击的特效
  160. switch (itemCfg.rarity)
  161. {
  162. case 1:
  163. break;
  164. case 2:
  165. break;
  166. case 3:
  167. _effectUIDic.Add("CK_Loop_Wait_Chen" + index, EffectUIPool.CreateEffectUI(item.m_waitClick_eff, "ui_LuckyBox", "CK_Loop_Wait_Chen"));
  168. break;
  169. case 4:
  170. _effectUIDic.Add("CK_Loop_Wait_Jin" + index, EffectUIPool.CreateEffectUI(item.m_waitClick_eff, "ui_LuckyBox", "CK_Loop_Wait_Jin"));
  171. break;
  172. }
  173. //带特效的处理先注释
  174. //item.m_comIcon.m_holder.visible = false;
  175. //item.m_comIcon.m_holder1.visible = false;
  176. //if (itemCfg.rarity > 2) {
  177. // string resPath = itemCfg.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_01" : "CK_all_02";
  178. // GGraph holder = itemCfg.rarity == 3 ? item.m_comIcon.m_holder : item.m_comIcon.m_holder1;
  179. // holder.visible = true;
  180. // if (countType == 10 && (!_effListTen.ContainsKey(index) ||
  181. // ((itemCfg.rarity == 3 && !_effListTen[index].ContainsKey(0)) || (itemCfg.rarity == 4 && !_effListTen[index].ContainsKey(1)))))
  182. // {
  183. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  184. // if (!_effListTen.ContainsKey(index))
  185. // {
  186. // Dictionary<int, EffectUI> effectList = new Dictionary<int, EffectUI>();
  187. // if (itemCfg.rarity == 3)
  188. // effectList.Add(0, _effectUI);
  189. // else if (itemCfg.rarity == 4)
  190. // effectList.Add(1, _effectUI);
  191. // _effListTen.Add(index, effectList);
  192. // }
  193. // else {
  194. // if (itemCfg.rarity == 3)
  195. // _effListTen[index].Add(0, _effectUI);
  196. // else if (itemCfg.rarity == 4)
  197. // _effListTen[index].Add(1, _effectUI);
  198. // }
  199. // }
  200. // if (countType == 1 &&
  201. // ((itemCfg.rarity == 3 && !_effList.ContainsKey(0)) || (itemCfg.rarity == 4 && !_effList.ContainsKey(1))))
  202. // {
  203. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  204. // if (itemCfg.rarity == 3)
  205. // _effList.Add(0, _effectUI);
  206. // else if (itemCfg.rarity == 4)
  207. // _effList.Add(1, _effectUI);
  208. // }
  209. //}
  210. int count = 0;
  211. bool isFirst = false;
  212. for (int i = 0; i < _rewardList.Count; i++)
  213. {
  214. if (_rewardList[i].id == itemData.id) count++;
  215. if (count == 1 && i == index) isFirst = true;
  216. }
  217. item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
  218. item.m_t0.Play();
  219. if (item.target.data == null)
  220. {
  221. item.target.onClick.Add(ShowItemTips);
  222. }
  223. item.target.data = index;
  224. _itemIdList.Add(index, itemCfg.id);
  225. _itemObjList.Add(index, com);
  226. UI_LuckyBoxBonusShowItem.ProxyEnd();
  227. }
  228. private void ShowItemTips(EventContext context)
  229. {
  230. GObject obj = context.sender as GObject;
  231. int index = (int)obj.data;
  232. _chooseIndex = index;
  233. HandClickItem(index);
  234. }
  235. private void HandClickItem(int index)
  236. {
  237. _ui.m_touchFlipOpen.touchable = true;
  238. _handClick = true;
  239. ClickItem(index);
  240. //翻牌动画
  241. Timers.inst.Add(1f, 1, UpClickDataTime, index);
  242. }
  243. private void UpClickDataTime(object param = null)
  244. {
  245. int index = (int)param;
  246. if (_recordTurnIndex.Contains(index) && _recordOpenIndex.Contains(index))
  247. {
  248. Timers.inst.Remove(UpClickDataTime);
  249. HideOtherShowWindow();
  250. _ui.m_touchFlipOpen.touchable = false;
  251. }
  252. else
  253. ClickItem(index);
  254. }
  255. void ClickItem(int index)
  256. {
  257. if (_recordOpenIndex.Count >= _rewardList.Count)
  258. _ui.m_BtnPass.visible = false;
  259. if (!_recordOpenIndex.Contains(index))
  260. TurnItem(index);
  261. else
  262. {
  263. if (!_recordTurnIndex.Contains(index))
  264. ShowTurnItem(index);
  265. else
  266. GoodsItemTipsController.ShowItemTips(_itemIdList[index]);
  267. }
  268. }
  269. private void OnClickLoaBg()
  270. {
  271. if (_recordOpenIndex.Count >= _rewardList.Count)
  272. {
  273. _chooseIndex = -1;
  274. this.Hide();
  275. }
  276. else
  277. {
  278. for (int index = 0; index < _rewardList.Count; index++)
  279. {
  280. if (!_recordOpenIndex.Contains(index))
  281. {
  282. _chooseIndex = index;
  283. HandClickItem(index);
  284. break;
  285. }
  286. }
  287. }
  288. }
  289. private void OnClickBtnPass()
  290. {
  291. for (int index = 0; index < _rewardList.Count; index++)
  292. {
  293. if (!_recordOpenIndex.Contains(index))
  294. {
  295. int count = 0;
  296. bool isFirst = false;
  297. for (int i = 0; i < _rewardList.Count; i++)
  298. {
  299. if (_rewardList[i].id == _rewardList[index].id) count++;
  300. if (count == 1 && i == index) isFirst = true;
  301. }
  302. bool open = count == ItemDataManager.GetItemNum(_rewardList[index].id) && isFirst;
  303. if (!open)
  304. {
  305. _chooseIndex = -1;
  306. ClickItem(index);
  307. }
  308. }
  309. }
  310. ClickPass();
  311. }
  312. private void ClickPass()
  313. {
  314. GetSuitItemController.isAuto = true;
  315. _ui.m_touchFlipOpen.touchable = true;
  316. _ui.m_BtnPass.visible = false;
  317. for (int i = 0; i < _rewardList.Count; i++)
  318. {
  319. TurnItem(i);
  320. }
  321. //展示获得物品
  322. Timers.inst.Add(LuckyBoxDataManager.ANIMATION_TIME, 0, UpDataTime);
  323. }
  324. private void UpDataTime(object param = null)
  325. {
  326. _ui.m_touchFlipOpen.touchable = true;
  327. if (_recordTurnIndex.Count >= _rewardList.Count)
  328. {
  329. Timers.inst.Remove(UpDataTime);
  330. HideOtherShowWindow();
  331. _ui.m_touchFlipOpen.touchable = false;
  332. GetSuitItemController.isAuto = false;
  333. }
  334. for (int i = 0; i < _rewardList.Count; i++)
  335. {
  336. if (!_recordTurnIndex.Contains(i))
  337. {
  338. ShowTurnItem(i);
  339. break;
  340. }
  341. }
  342. }
  343. //控制展示获得物品界面
  344. private void ShowTurnItem(int index)
  345. {
  346. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]);
  347. if (!_AnimationWait)
  348. return;
  349. if (item.m_comIcon.m_imgNew.visible)
  350. {
  351. _countShow += 1;
  352. //判断是否有套装需要展示
  353. int suitId = SuitCfgArray.Instance.GetSuitIdOfItem(_itemIdList[index]);
  354. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemIdList[index]);
  355. if (suitId > 0 && itemCfg.itemType != ConstItemType.CARD)
  356. {
  357. if (_countShow == 1)
  358. {
  359. ViewManager.Hide<SuitItemView>();
  360. ViewManager.Hide<LuckyBoxNewCardView>();
  361. ViewManager.Hide<GetSuitItemVIew>();
  362. _rewardItemList.Clear();
  363. _rewardItemList.Add(_rewardList[index]);
  364. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  365. }
  366. else
  367. {
  368. ViewManager.Hide<LuckyBoxNewDressView>();
  369. ViewManager.Hide<LuckyBoxNewCardView>();
  370. int count = 0;
  371. int totalCount = 0;
  372. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  373. if (_countShow == 2) //展示进度条界面
  374. {
  375. int countSuitId = 0;
  376. for (int i = index + 1; i < _rewardList.Count; i++)
  377. {
  378. int itemSuitId = SuitCfgArray.Instance.GetSuitIdOfItem(_rewardList[i].id);
  379. if (itemSuitId == suitId)
  380. countSuitId++;
  381. }
  382. count = count - countSuitId;
  383. ViewManager.Show<SuitItemView>(new object[] { suitId, countSuitId });
  384. }
  385. else if (_countShow == 3) //展示集齐套装界面
  386. {
  387. ViewManager.Hide<SuitItemView>();
  388. ViewManager.Show<GetSuitItemVIew>(suitId);
  389. _AnimationWait = false;
  390. }
  391. //判断是否需要显示集齐套装界面(需要的时候晚一个定时器时间)
  392. if (count < totalCount || (count >= totalCount && _countShow > 3))
  393. {
  394. _recordTurnIndex.Add(index);
  395. _countShow = 0;
  396. if (_handClick)
  397. {
  398. _handClick = false;
  399. Timers.inst.Remove(UpClickDataTime);
  400. _ui.m_touchFlipOpen.touchable = false;
  401. }
  402. }
  403. }
  404. }
  405. else
  406. {
  407. //词牌和不是套装进这里
  408. ViewManager.Hide<SuitItemView>();
  409. ViewManager.Hide<LuckyBoxNewCardView>();
  410. ViewManager.Hide<GetSuitItemVIew>();
  411. _rewardItemList.Clear();
  412. _rewardItemList.Add(_rewardList[index]);
  413. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  414. _recordTurnIndex.Add(index);
  415. _countShow = 0;
  416. _ui.m_touchFlipOpen.touchable = false;
  417. }
  418. }
  419. else
  420. {
  421. _recordTurnIndex.Add(index);
  422. _ui.m_touchFlipOpen.touchable = false;
  423. }
  424. UI_LuckyBoxBonusShowItem.ProxyEnd();
  425. }
  426. private void TurnItem(int index)
  427. {
  428. if (!_recordOpenIndex.Contains(index))
  429. {
  430. // 删除 “等待翻开” 的特效
  431. if (_effectUIDic.ContainsKey("CK_Loop_Wait_Chen" + index))
  432. {
  433. EffectUIPool.Recycle(_effectUIDic["CK_Loop_Wait_Chen" + index]);
  434. _effectUIDic.Remove("CK_Loop_Wait_Chen" + index);
  435. }
  436. if (_effectUIDic.ContainsKey("CK_Loop_Wait_Jin" + index))
  437. {
  438. EffectUIPool.Recycle(_effectUIDic["CK_Loop_Wait_Jin" + index]);
  439. _effectUIDic.Remove("CK_Loop_Wait_Jin" + index);
  440. }
  441. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]);
  442. if (!item.m_comIcon.m_imgNew.visible)
  443. _recordTurnIndex.Add(index);
  444. //先翻开牌面
  445. item.m_comIcon.m_FlipOpenType.selectedIndex = 0;
  446. //item.m_t1.Play();
  447. item.m_t2.Play();
  448. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(_itemIdList[index]);
  449. // 点击特效
  450. _effectUIDic.Add("CK_Cirle_DJ" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_click_eff, "ui_LuckyBox", "CK_Cirle_DJ"));
  451. // 翻开特效
  452. switch (itemCfg.rarity)
  453. {
  454. case 1:
  455. _effectUIDic.Add("CK_OpenAfter_LanHui_UI" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_HuiLan_UI"));
  456. _effectUIDic.Add("CK_OpenAfter_LanHui_TX" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_LanHui_TX"));
  457. break;
  458. case 2:
  459. _effectUIDic.Add("CK_OpenAfter_LanHui_UI" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_LanHui_UI"));
  460. _effectUIDic.Add("CK_OpenAfter_LanHui_TX" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_LanHui_TX"));
  461. break;
  462. case 3:
  463. _effectUIDic.Add("CK_OpenAfter_Chen_UI" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_Chen_UI"));
  464. _effectUIDic.Add("CK_OpenAfter_Chen_TX" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_Chen_TX"));
  465. break;
  466. case 4:
  467. _effectUIDic.Add("CK_OpenAfter_Jin_UI" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_ui_eff, "ui_LuckyBox", "CK_OpenAfter_Jin_UI"));
  468. _effectUIDic.Add("CK_OpenAfter_Jin_TX" + index, EffectUIPool.CreateEffectUI(item.m_comIcon.m_flip_eff, "ui_LuckyBox", "CK_OpenAfter_Jin_TX"));
  469. break;
  470. }
  471. item.m_comIcon.m_t0.Play();
  472. _recordOpenIndex.Add(index);
  473. UI_LuckyBoxBonusShowItem.ProxyEnd();
  474. }
  475. }
  476. private void HideOtherShowWindow()
  477. {
  478. ViewManager.Hide<SuitItemView>();
  479. ViewManager.Hide<GetSuitItemVIew>();
  480. ViewManager.Hide<LuckyBoxNewDressView>();
  481. ViewManager.Hide<LuckyBoxNewCardView>();
  482. }
  483. private void SetAnimationWait()
  484. {
  485. _AnimationWait = true;
  486. }
  487. }
  488. }