LuckyBoxBonusShowView.cs 19 KB

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