LuckyBoxBonusShowView.cs 15 KB

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