LuckyBoxBonusShowView.cs 13 KB

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