LuckyBoxBonusShowView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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)
  94. ClickItem(_chooseIndex);
  95. }
  96. protected override void OnShown()
  97. {
  98. base.OnShown();
  99. _rewardList.AddRange(this.viewData as List<ItemData>);
  100. _itemIdList.Clear();
  101. _itemObjList.Clear();
  102. _recordOpenIndex.Clear();
  103. _ui.m_BtnPass.visible = true;
  104. _ui.m_touchFlipOpen.touchable = false;
  105. if (_rewardList.Count == 1)
  106. {
  107. _ui.m_c1.selectedIndex = 0;
  108. UpdateItem(_ui.m_itemOne.target, 0, 1);
  109. }
  110. else
  111. {
  112. _ui.m_c1.selectedIndex = 1;
  113. for (int i = 0; i < _rewardList.Count; i++)
  114. {
  115. UpdateItem(_ui.target.GetChild("item" + i).asCom, i, 10);
  116. }
  117. }
  118. }
  119. protected override void OnHide()
  120. {
  121. _rewardList.Clear();
  122. base.OnHide();
  123. Timers.inst.Remove(UpDataTime);
  124. Timers.inst.Remove(UpClickDataTime);
  125. }
  126. private void UpdateItem(GComponent com, int index, int countType)
  127. {
  128. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
  129. ItemData itemData = _rewardList[index];
  130. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  131. item.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
  132. item.m_comIcon.m_txtName.text = itemCfg.name;
  133. item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  134. item.m_comIcon.m_FlipOpenType.selectedIndex = 1;
  135. item.m_comIcon.m_t1.Play();
  136. //带特效的处理先注释
  137. //item.m_comIcon.m_holder.visible = false;
  138. //item.m_comIcon.m_holder1.visible = false;
  139. //if (itemCfg.rarity > 2) {
  140. // string resPath = itemCfg.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_01" : "CK_all_02";
  141. // GGraph holder = itemCfg.rarity == 3 ? item.m_comIcon.m_holder : item.m_comIcon.m_holder1;
  142. // holder.visible = true;
  143. // if (countType == 10 && (!_effListTen.ContainsKey(index) ||
  144. // ((itemCfg.rarity == 3 && !_effListTen[index].ContainsKey(0)) || (itemCfg.rarity == 4 && !_effListTen[index].ContainsKey(1)))))
  145. // {
  146. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  147. // if (!_effListTen.ContainsKey(index))
  148. // {
  149. // Dictionary<int, EffectUI> effectList = new Dictionary<int, EffectUI>();
  150. // if (itemCfg.rarity == 3)
  151. // effectList.Add(0, _effectUI);
  152. // else if (itemCfg.rarity == 4)
  153. // effectList.Add(1, _effectUI);
  154. // _effListTen.Add(index, effectList);
  155. // }
  156. // else {
  157. // if (itemCfg.rarity == 3)
  158. // _effListTen[index].Add(0, _effectUI);
  159. // else if (itemCfg.rarity == 4)
  160. // _effListTen[index].Add(1, _effectUI);
  161. // }
  162. // }
  163. // if (countType == 1 &&
  164. // ((itemCfg.rarity == 3 && !_effList.ContainsKey(0)) || (itemCfg.rarity == 4 && !_effList.ContainsKey(1))))
  165. // {
  166. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  167. // if (itemCfg.rarity == 3)
  168. // _effList.Add(0, _effectUI);
  169. // else if (itemCfg.rarity == 4)
  170. // _effList.Add(1, _effectUI);
  171. // }
  172. //}
  173. int count = 0;
  174. bool isFirst = false;
  175. for (int i = 0; i < _rewardList.Count; i++)
  176. {
  177. if (_rewardList[i].id == itemData.id) count++;
  178. if (count == 1 && i == index) isFirst = true;
  179. }
  180. item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
  181. item.m_t0.Play();
  182. if (item.target.data == null)
  183. {
  184. item.target.onClick.Add(ShowItemTips);
  185. }
  186. item.target.data = index;
  187. _itemIdList.Add(index,itemCfg.id);
  188. _itemObjList.Add(index, com);
  189. UI_LuckyBoxBonusShowItem.ProxyEnd();
  190. }
  191. private void ShowItemTips(EventContext context)
  192. {
  193. GObject obj = context.sender as GObject;
  194. int index = (int)obj.data;
  195. _chooseIndex = index;
  196. HandClickItem(index);
  197. }
  198. private void HandClickItem(int index)
  199. {
  200. _ui.m_touchFlipOpen.touchable = true;
  201. _handClick = true;
  202. ClickItem(index);
  203. Timers.inst.Add(1f, 1, UpClickDataTime,index);
  204. }
  205. void ClickItem(int index)
  206. {
  207. if (!_recordOpenIndex.Contains(index))
  208. {
  209. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]);
  210. if (_recordOpenIndex.Count >= _rewardList.Count - 1)
  211. _ui.m_BtnPass.visible = false;
  212. //先翻开牌面
  213. if (!item.m_comIcon.m_imgNew.visible || _countNewRecord < 1)
  214. {
  215. HideOtherShowWindow();
  216. item.m_comIcon.m_FlipOpenType.selectedIndex = 0;
  217. item.m_t1.Play();
  218. item.m_comIcon.m_t0.Play();
  219. if (!item.m_comIcon.m_imgNew.visible) {
  220. if (_handClick)
  221. _ui.m_touchFlipOpen.touchable = false;
  222. _recordOpenIndex.Add(index);
  223. }
  224. else if (_countNewRecord < 1)
  225. _countNewRecord += 1;
  226. return;
  227. }
  228. if (item.m_comIcon.m_imgNew.visible && _countNewRecord >= 1)
  229. {
  230. //判断是否有套装需要展示
  231. if (GetSuitItemController.GetSuitWaitingToId(_itemIdList[index]))
  232. {
  233. if (_countShow < 1)
  234. {
  235. _countShow += 1;
  236. ViewManager.Hide<GetSuitItemVIew>();
  237. _rewardItemList.Clear();
  238. _rewardItemList.Add(_rewardList[index]);
  239. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  240. }
  241. else
  242. {
  243. ViewManager.Hide<LuckyBoxNewDressView>();
  244. ViewManager.Hide<LuckyBoxNewCardView>();
  245. GetSuitItemController.TryShow(_itemIdList[index]);
  246. _recordOpenIndex.Add(index);
  247. _countShow = 0;
  248. _countNewRecord = 0;
  249. }
  250. }
  251. else
  252. {
  253. ViewManager.Hide<GetSuitItemVIew>();
  254. _rewardItemList.Clear();
  255. _rewardItemList.Add(_rewardList[index]);
  256. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  257. _recordOpenIndex.Add(index);
  258. _countNewRecord = 0;
  259. }
  260. }
  261. UI_LuckyBoxBonusShowItem.ProxyEnd();
  262. if (_handClick)
  263. {
  264. _ui.m_touchFlipOpen.touchable = false;
  265. Timers.inst.Remove(UpClickDataTime);
  266. }
  267. }
  268. else{
  269. GoodsItemTipsController.ShowItemTips(_itemIdList[index]);
  270. }
  271. }
  272. private void OnClickLoaBg()
  273. {
  274. if (_recordOpenIndex.Count >= _rewardList.Count)
  275. {
  276. _chooseIndex = -1;
  277. this.Hide();
  278. }
  279. else {
  280. for (int index = 0; index < _rewardList.Count; index++)
  281. {
  282. if (!_recordOpenIndex.Contains(index))
  283. {
  284. _chooseIndex = index;
  285. HandClickItem(index);
  286. break;
  287. }
  288. }
  289. }
  290. }
  291. private void OnClickBtnPass()
  292. {
  293. for (int index = 0; index < _rewardList.Count; index++)
  294. {
  295. if (!_recordOpenIndex.Contains(index))
  296. {
  297. int count = 0;
  298. bool isFirst = false;
  299. for (int i = 0; i < _rewardList.Count; i++)
  300. {
  301. if (_rewardList[i].id == _rewardList[index].id) count++;
  302. if (count == 1 && i == index) isFirst = true;
  303. }
  304. bool open = count == ItemDataManager.GetItemNum(_rewardList[index].id) && isFirst;
  305. if (!open)
  306. {
  307. _chooseIndex = index;
  308. ClickItem(index);
  309. }
  310. }
  311. }
  312. ClickPass();
  313. }
  314. private void ClickPass()
  315. {
  316. _ui.m_touchFlipOpen.touchable = true;
  317. Timers.inst.Add(1f, 0, UpDataTime);
  318. }
  319. private void UpDataTime(object param = null)
  320. {
  321. if (_recordOpenIndex.Count >= _rewardList.Count) {
  322. Timers.inst.Remove(UpDataTime);
  323. _ui.m_touchFlipOpen.touchable = false;
  324. HideOtherShowWindow();
  325. }
  326. for (int i = 0; i < _rewardList.Count; i++)
  327. {
  328. if (!_recordOpenIndex.Contains(i)) {
  329. ClickItem(i);
  330. break;
  331. }
  332. }
  333. }
  334. private void UpClickDataTime(object param = null)
  335. {
  336. int index = (int)param;
  337. if (_recordOpenIndex.Contains(index))
  338. {
  339. Timers.inst.Remove(UpClickDataTime);
  340. _ui.m_touchFlipOpen.touchable = false;
  341. HideOtherShowWindow();
  342. }
  343. else
  344. ClickItem(index);
  345. }
  346. private void HideOtherShowWindow()
  347. {
  348. ViewManager.Hide<GetSuitItemVIew>();
  349. ViewManager.Hide<LuckyBoxNewDressView>();
  350. ViewManager.Hide<LuckyBoxNewCardView>();
  351. }
  352. }
  353. }