LuckyBoxBonusShowView.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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_t2.Play();
  219. item.m_comIcon.m_t0.Play();
  220. if (!item.m_comIcon.m_imgNew.visible) {
  221. if (_handClick)
  222. _ui.m_touchFlipOpen.touchable = false;
  223. _recordOpenIndex.Add(index);
  224. }
  225. else if (_countNewRecord < 1)
  226. _countNewRecord += 1;
  227. return;
  228. }
  229. if (item.m_comIcon.m_imgNew.visible && _countNewRecord >= 1)
  230. {
  231. //判断是否有套装需要展示
  232. if (GetSuitItemController.GetSuitWaitingToId(_itemIdList[index]))
  233. {
  234. if (_countShow < 1)
  235. {
  236. _countShow += 1;
  237. ViewManager.Hide<GetSuitItemVIew>();
  238. _rewardItemList.Clear();
  239. _rewardItemList.Add(_rewardList[index]);
  240. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  241. }
  242. else
  243. {
  244. ViewManager.Hide<LuckyBoxNewDressView>();
  245. ViewManager.Hide<LuckyBoxNewCardView>();
  246. GetSuitItemController.TryShow(_itemIdList[index]);
  247. _recordOpenIndex.Add(index);
  248. _countShow = 0;
  249. _countNewRecord = 0;
  250. }
  251. }
  252. else
  253. {
  254. ViewManager.Hide<GetSuitItemVIew>();
  255. _rewardItemList.Clear();
  256. _rewardItemList.Add(_rewardList[index]);
  257. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  258. _recordOpenIndex.Add(index);
  259. _countNewRecord = 0;
  260. }
  261. }
  262. UI_LuckyBoxBonusShowItem.ProxyEnd();
  263. if (_handClick)
  264. {
  265. _ui.m_touchFlipOpen.touchable = false;
  266. Timers.inst.Remove(UpClickDataTime);
  267. }
  268. }
  269. else{
  270. GoodsItemTipsController.ShowItemTips(_itemIdList[index]);
  271. }
  272. }
  273. private void OnClickLoaBg()
  274. {
  275. if (_recordOpenIndex.Count >= _rewardList.Count)
  276. {
  277. _chooseIndex = -1;
  278. this.Hide();
  279. }
  280. else {
  281. for (int index = 0; index < _rewardList.Count; index++)
  282. {
  283. if (!_recordOpenIndex.Contains(index))
  284. {
  285. _chooseIndex = index;
  286. HandClickItem(index);
  287. break;
  288. }
  289. }
  290. }
  291. }
  292. private void OnClickBtnPass()
  293. {
  294. for (int index = 0; index < _rewardList.Count; index++)
  295. {
  296. if (!_recordOpenIndex.Contains(index))
  297. {
  298. int count = 0;
  299. bool isFirst = false;
  300. for (int i = 0; i < _rewardList.Count; i++)
  301. {
  302. if (_rewardList[i].id == _rewardList[index].id) count++;
  303. if (count == 1 && i == index) isFirst = true;
  304. }
  305. bool open = count == ItemDataManager.GetItemNum(_rewardList[index].id) && isFirst;
  306. if (!open)
  307. {
  308. _chooseIndex = index;
  309. ClickItem(index);
  310. }
  311. }
  312. }
  313. ClickPass();
  314. }
  315. private void ClickPass()
  316. {
  317. _ui.m_touchFlipOpen.touchable = true;
  318. Timers.inst.Add(1f, 0, UpDataTime);
  319. }
  320. private void UpDataTime(object param = null)
  321. {
  322. if (_recordOpenIndex.Count >= _rewardList.Count) {
  323. Timers.inst.Remove(UpDataTime);
  324. _ui.m_touchFlipOpen.touchable = false;
  325. HideOtherShowWindow();
  326. }
  327. for (int i = 0; i < _rewardList.Count; i++)
  328. {
  329. if (!_recordOpenIndex.Contains(i)) {
  330. ClickItem(i);
  331. break;
  332. }
  333. }
  334. }
  335. private void UpClickDataTime(object param = null)
  336. {
  337. int index = (int)param;
  338. if (_recordOpenIndex.Contains(index))
  339. {
  340. Timers.inst.Remove(UpClickDataTime);
  341. _ui.m_touchFlipOpen.touchable = false;
  342. HideOtherShowWindow();
  343. }
  344. else
  345. ClickItem(index);
  346. }
  347. private void HideOtherShowWindow()
  348. {
  349. ViewManager.Hide<GetSuitItemVIew>();
  350. ViewManager.Hide<LuckyBoxNewDressView>();
  351. ViewManager.Hide<LuckyBoxNewCardView>();
  352. }
  353. }
  354. }