LuckyBoxBonusShowView.cs 15 KB

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