LuckyBoxBonusShowView.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. 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. if (_effListTen.ContainsKey(key))
  37. {
  38. for (int key1 = 0; key1 < _effListTen[key].Count; key1++)
  39. {
  40. if (_effListTen[key].ContainsKey(key1))
  41. {
  42. EffectUIPool.Recycle(_effListTen[key][key1]);
  43. _effListTen[key][key1] = null;
  44. }
  45. }
  46. }
  47. }
  48. _effListTen.Clear();
  49. for (int key = 0; key < _effList.Count; key++)
  50. {
  51. if (_effList.ContainsKey(key))
  52. {
  53. EffectUIPool.Recycle(_effList[key]);
  54. _effList[key] = null;
  55. }
  56. }
  57. _effList.Clear();
  58. if (_ui != null)
  59. {
  60. _ui.Dispose();
  61. _ui = null;
  62. }
  63. base.Dispose();
  64. }
  65. protected override void OnInit()
  66. {
  67. base.OnInit();
  68. packageName = UI_LuckBoxBonusShowUI.PACKAGE_NAME;
  69. _ui = UI_LuckBoxBonusShowUI.Create();
  70. this.viewCom = _ui.target;
  71. isfullScreen = true;
  72. _ui.m_loaBg.onClick.Add(OnClickLoaBg);
  73. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  74. _ui.m_BtnPass.onClick.Add(OnClickBtnPass);
  75. UpdateEffect();
  76. }
  77. private void UpdateEffect()
  78. {
  79. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder_star, "ui_LuckyBox", "bg_liuxing");
  80. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holder_bg, "ui_LuckyBox", "CK_UI");
  81. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holder_cloud, "ui_LuckyBox", "bg_cloud");
  82. }
  83. protected override void AddEventListener()
  84. {
  85. base.AddEventListener();
  86. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_REWARD_SHOW, ReferNextShow);
  87. EventAgent.AddEventListener(ConstMessage.LUCKY_BOX_ANIMATION_WAIT, SetAnimationWait);
  88. }
  89. protected override void RemoveEventListener()
  90. {
  91. base.RemoveEventListener();
  92. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_REWARD_SHOW, ReferNextShow);
  93. EventAgent.RemoveEventListener(ConstMessage.LUCKY_BOX_ANIMATION_WAIT, SetAnimationWait);
  94. }
  95. protected void ReferNextShow()
  96. {
  97. if (_chooseIndex != -1 && GetSuitItemController.GetSuitWaitingToId(_itemIdList[_chooseIndex]))
  98. ClickItem(_chooseIndex);
  99. else {
  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. }
  139. private void UpdateItem(GComponent com, int index, int countType)
  140. {
  141. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
  142. ItemData itemData = _rewardList[index];
  143. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  144. item.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
  145. item.m_comIcon.m_txtName.text = itemCfg.name;
  146. item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  147. item.m_comIcon.m_FlipOpenType.selectedIndex = 1;
  148. item.m_comIcon.m_t1.Play();
  149. //带特效的处理先注释
  150. //item.m_comIcon.m_holder.visible = false;
  151. //item.m_comIcon.m_holder1.visible = false;
  152. //if (itemCfg.rarity > 2) {
  153. // string resPath = itemCfg.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_01" : "CK_all_02";
  154. // GGraph holder = itemCfg.rarity == 3 ? item.m_comIcon.m_holder : item.m_comIcon.m_holder1;
  155. // holder.visible = true;
  156. // if (countType == 10 && (!_effListTen.ContainsKey(index) ||
  157. // ((itemCfg.rarity == 3 && !_effListTen[index].ContainsKey(0)) || (itemCfg.rarity == 4 && !_effListTen[index].ContainsKey(1)))))
  158. // {
  159. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  160. // if (!_effListTen.ContainsKey(index))
  161. // {
  162. // Dictionary<int, EffectUI> effectList = new Dictionary<int, EffectUI>();
  163. // if (itemCfg.rarity == 3)
  164. // effectList.Add(0, _effectUI);
  165. // else if (itemCfg.rarity == 4)
  166. // effectList.Add(1, _effectUI);
  167. // _effListTen.Add(index, effectList);
  168. // }
  169. // else {
  170. // if (itemCfg.rarity == 3)
  171. // _effListTen[index].Add(0, _effectUI);
  172. // else if (itemCfg.rarity == 4)
  173. // _effListTen[index].Add(1, _effectUI);
  174. // }
  175. // }
  176. // if (countType == 1 &&
  177. // ((itemCfg.rarity == 3 && !_effList.ContainsKey(0)) || (itemCfg.rarity == 4 && !_effList.ContainsKey(1))))
  178. // {
  179. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  180. // if (itemCfg.rarity == 3)
  181. // _effList.Add(0, _effectUI);
  182. // else if (itemCfg.rarity == 4)
  183. // _effList.Add(1, _effectUI);
  184. // }
  185. //}
  186. int count = 0;
  187. bool isFirst = false;
  188. for (int i = 0; i < _rewardList.Count; i++)
  189. {
  190. if (_rewardList[i].id == itemData.id) count++;
  191. if (count == 1 && i == index) isFirst = true;
  192. }
  193. item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
  194. item.m_t0.Play();
  195. if (item.target.data == null)
  196. {
  197. item.target.onClick.Add(ShowItemTips);
  198. }
  199. item.target.data = index;
  200. _itemIdList.Add(index,itemCfg.id);
  201. _itemObjList.Add(index, com);
  202. UI_LuckyBoxBonusShowItem.ProxyEnd();
  203. }
  204. private void ShowItemTips(EventContext context)
  205. {
  206. GObject obj = context.sender as GObject;
  207. int index = (int)obj.data;
  208. _chooseIndex = index;
  209. HandClickItem(index);
  210. }
  211. private void HandClickItem(int index)
  212. {
  213. _ui.m_touchFlipOpen.touchable = true;
  214. _handClick = true;
  215. ClickItem(index);
  216. Timers.inst.Add(1f, 1, UpClickDataTime,index);
  217. }
  218. private void UpClickDataTime(object param = null)
  219. {
  220. int index = (int)param;
  221. if (_recordTurnIndex.Contains(index) && _recordOpenIndex.Contains(index))
  222. {
  223. Timers.inst.Remove(UpClickDataTime);
  224. HideOtherShowWindow();
  225. _ui.m_touchFlipOpen.touchable = false;
  226. }
  227. else
  228. ClickItem(index);
  229. }
  230. void ClickItem(int index)
  231. {
  232. if (_recordOpenIndex.Count >= _rewardList.Count)
  233. _ui.m_BtnPass.visible = false;
  234. if (!_recordOpenIndex.Contains(index))
  235. TurnItem(index);
  236. else {
  237. if (!_recordTurnIndex.Contains(index))
  238. ShowTurnItem(index);
  239. else
  240. GoodsItemTipsController.ShowItemTips(_itemIdList[index]);
  241. }
  242. }
  243. private void OnClickLoaBg()
  244. {
  245. if (_recordOpenIndex.Count >= _rewardList.Count)
  246. {
  247. _chooseIndex = -1;
  248. this.Hide();
  249. }
  250. else {
  251. for (int index = 0; index < _rewardList.Count; index++)
  252. {
  253. if (!_recordOpenIndex.Contains(index))
  254. {
  255. _chooseIndex = index;
  256. HandClickItem(index);
  257. break;
  258. }
  259. }
  260. }
  261. }
  262. private void OnClickBtnPass()
  263. {
  264. for (int index = 0; index < _rewardList.Count; index++)
  265. {
  266. if (!_recordOpenIndex.Contains(index))
  267. {
  268. int count = 0;
  269. bool isFirst = false;
  270. for (int i = 0; i < _rewardList.Count; i++)
  271. {
  272. if (_rewardList[i].id == _rewardList[index].id) count++;
  273. if (count == 1 && i == index) isFirst = true;
  274. }
  275. bool open = count == ItemDataManager.GetItemNum(_rewardList[index].id) && isFirst;
  276. if (!open)
  277. {
  278. _chooseIndex = -1;
  279. ClickItem(index);
  280. }
  281. }
  282. }
  283. ClickPass();
  284. }
  285. private void ClickPass()
  286. {
  287. _ui.m_touchFlipOpen.touchable = true;
  288. _ui.m_BtnPass.visible = false;
  289. for (int i = 0; i < _rewardList.Count; i++)
  290. {
  291. TurnItem(i);
  292. }
  293. Timers.inst.Add(1f, 0, UpDataTime);
  294. }
  295. private void UpDataTime(object param = null)
  296. {
  297. _ui.m_touchFlipOpen.touchable = true;
  298. for (int i = 0; i < _rewardList.Count; i++)
  299. {
  300. if (!_recordTurnIndex.Contains(i)) {
  301. ShowTurnItem(i);
  302. break;
  303. }
  304. }
  305. if (_recordTurnIndex.Count >= _rewardList.Count)
  306. {
  307. Timers.inst.Remove(UpDataTime);
  308. HideOtherShowWindow();
  309. _ui.m_touchFlipOpen.touchable = false;
  310. }
  311. }
  312. private void ShowTurnItem(int index)
  313. {
  314. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]);
  315. if (!_AnimationWait)
  316. return;
  317. if (item.m_comIcon.m_imgNew.visible)
  318. {
  319. //判断是否有套装需要展示
  320. if (GetSuitItemController.GetSuitWaitingToId(_itemIdList[index]))
  321. {
  322. if (_countShow < 1)
  323. {
  324. _countShow += 1;
  325. ViewManager.Hide<GetSuitItemVIew>();
  326. _rewardItemList.Clear();
  327. _rewardItemList.Add(_rewardList[index]);
  328. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  329. }
  330. else
  331. {
  332. ViewManager.Hide<LuckyBoxNewDressView>();
  333. ViewManager.Hide<LuckyBoxNewCardView>();
  334. GetSuitItemController.TryShow(_itemIdList[index]);
  335. _recordTurnIndex.Add(index);
  336. _countShow = 0;
  337. _AnimationWait = false;
  338. if (_handClick)
  339. {
  340. _handClick = false;
  341. Timers.inst.Remove(UpClickDataTime);
  342. _ui.m_touchFlipOpen.touchable = false;
  343. }
  344. }
  345. }
  346. else
  347. {
  348. ViewManager.Hide<GetSuitItemVIew>();
  349. _rewardItemList.Clear();
  350. _rewardItemList.Add(_rewardList[index]);
  351. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  352. _recordTurnIndex.Add(index);
  353. _ui.m_touchFlipOpen.touchable = false;
  354. }
  355. }
  356. else {
  357. _recordTurnIndex.Add(index);
  358. _ui.m_touchFlipOpen.touchable = false;
  359. }
  360. UI_LuckyBoxBonusShowItem.ProxyEnd();
  361. }
  362. private void TurnItem(int index)
  363. {
  364. if (!_recordOpenIndex.Contains(index))
  365. {
  366. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]);
  367. if (!item.m_comIcon.m_imgNew.visible)
  368. _recordTurnIndex.Add(index);
  369. //先翻开牌面
  370. item.m_comIcon.m_FlipOpenType.selectedIndex = 0;
  371. //item.m_t1.Play();
  372. item.m_t2.Play();
  373. item.m_comIcon.m_t0.Play();
  374. _recordOpenIndex.Add(index);
  375. UI_LuckyBoxBonusShowItem.ProxyEnd();
  376. }
  377. }
  378. private void HideOtherShowWindow()
  379. {
  380. ViewManager.Hide<GetSuitItemVIew>();
  381. ViewManager.Hide<LuckyBoxNewDressView>();
  382. ViewManager.Hide<LuckyBoxNewCardView>();
  383. }
  384. private void SetAnimationWait()
  385. {
  386. _AnimationWait = true;
  387. }
  388. }
  389. }