LuckyBoxBonusShowView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. Dictionary<int, int> _itemIdList = new Dictionary<int, int>();
  16. Dictionary<int, GComponent> _itemObjList = new Dictionary<int, GComponent>();
  17. List<int> _recordOpenIndex = new List<int>(); //记录打开过得item位置
  18. private int _countShow = 0; //第几次展示
  19. private int _countNewRecord = 0; //展示步骤
  20. private bool touchFlipOpen = true; //禁用点击
  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. if (_rewardList.Count == 1)
  89. {
  90. _ui.m_c1.selectedIndex = 0;
  91. UpdateItem(_ui.m_itemOne.target, 0, 1);
  92. }
  93. else
  94. {
  95. _ui.m_c1.selectedIndex = 1;
  96. for (int i = 0; i < _rewardList.Count; i++)
  97. {
  98. UpdateItem(_ui.target.GetChild("item" + i).asCom, i, 10);
  99. }
  100. }
  101. }
  102. protected override void OnHide()
  103. {
  104. _rewardList.Clear();
  105. base.OnHide();
  106. Timers.inst.Remove(UpDataTime);
  107. Timers.inst.Remove(UpClickDataTime);
  108. }
  109. private void UpdateItem(GComponent com, int index, int countType)
  110. {
  111. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
  112. ItemData itemData = _rewardList[index];
  113. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  114. item.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
  115. item.m_comIcon.m_txtName.text = itemCfg.name;
  116. item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  117. item.m_comIcon.m_FlipOpenType.selectedIndex = 1;
  118. //带特效的处理先注释
  119. //item.m_comIcon.m_holder.visible = false;
  120. //item.m_comIcon.m_holder1.visible = false;
  121. //if (itemCfg.rarity > 2) {
  122. // string resPath = itemCfg.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_01" : "CK_all_02";
  123. // GGraph holder = itemCfg.rarity == 3 ? item.m_comIcon.m_holder : item.m_comIcon.m_holder1;
  124. // holder.visible = true;
  125. // if (countType == 10 && (!_effListTen.ContainsKey(index) ||
  126. // ((itemCfg.rarity == 3 && !_effListTen[index].ContainsKey(0)) || (itemCfg.rarity == 4 && !_effListTen[index].ContainsKey(1)))))
  127. // {
  128. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  129. // if (!_effListTen.ContainsKey(index))
  130. // {
  131. // Dictionary<int, EffectUI> effectList = new Dictionary<int, EffectUI>();
  132. // if (itemCfg.rarity == 3)
  133. // effectList.Add(0, _effectUI);
  134. // else if (itemCfg.rarity == 4)
  135. // effectList.Add(1, _effectUI);
  136. // _effListTen.Add(index, effectList);
  137. // }
  138. // else {
  139. // if (itemCfg.rarity == 3)
  140. // _effListTen[index].Add(0, _effectUI);
  141. // else if (itemCfg.rarity == 4)
  142. // _effListTen[index].Add(1, _effectUI);
  143. // }
  144. // }
  145. // if (countType == 1 &&
  146. // ((itemCfg.rarity == 3 && !_effList.ContainsKey(0)) || (itemCfg.rarity == 4 && !_effList.ContainsKey(1))))
  147. // {
  148. // EffectUI _effectUI = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  149. // if (itemCfg.rarity == 3)
  150. // _effList.Add(0, _effectUI);
  151. // else if (itemCfg.rarity == 4)
  152. // _effList.Add(1, _effectUI);
  153. // }
  154. //}
  155. int count = 0;
  156. bool isFirst = false;
  157. for (int i = 0; i < _rewardList.Count; i++)
  158. {
  159. if (_rewardList[i].id == itemData.id) count++;
  160. if (count == 1 && i == index) isFirst = true;
  161. }
  162. item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
  163. item.m_t0.Play();
  164. if (item.target.data == null)
  165. {
  166. item.target.onClick.Add(ShowItemTips);
  167. }
  168. item.target.data = index;
  169. _itemIdList.Add(index,itemCfg.id);
  170. _itemObjList.Add(index, com);
  171. UI_LuckyBoxBonusShowItem.ProxyEnd();
  172. }
  173. private void ShowItemTips(EventContext context)
  174. {
  175. GObject obj = context.sender as GObject;
  176. int index = (int)obj.data;
  177. TouchClickItem(index);
  178. Timers.inst.Add(1f, 0, UpClickDataTime,index);
  179. }
  180. void TouchClickItem(int index)
  181. {
  182. if (!touchFlipOpen)
  183. return;
  184. ClickItem(index);
  185. }
  186. void ClickItem(int index)
  187. {
  188. if (!_recordOpenIndex.Contains(index)) {
  189. //touchFlipOpen = false;
  190. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(_itemObjList[index]);
  191. item.m_comIcon.m_FlipOpenType.selectedIndex = 0;
  192. if (_recordOpenIndex.Count >= _rewardList.Count)
  193. _ui.m_BtnPass.visible = false;
  194. //先翻开牌面
  195. if (!item.m_comIcon.m_imgNew.visible)
  196. {
  197. HideOtherShowWindow();
  198. _recordOpenIndex.Add(index);
  199. touchFlipOpen = true;
  200. return;
  201. }
  202. else {
  203. if (_countNewRecord <= 1) {
  204. HideOtherShowWindow();
  205. _countNewRecord += 1;
  206. return;
  207. }
  208. }
  209. if (item.m_comIcon.m_imgNew.visible && _countNewRecord >= 1)
  210. {
  211. //判断是否有套装需要展示
  212. if (GetSuitItemController.GetSuitWaitingToId(_itemIdList[index]))
  213. {
  214. if (_countShow < 1)
  215. {
  216. ViewManager.Hide<GetSuitItemVIew>();
  217. _rewardItemList.Clear();
  218. _rewardItemList.Add(_rewardList[index]);
  219. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  220. _countShow += 1;
  221. }
  222. else
  223. {
  224. ViewManager.Hide<LuckyBoxNewDressView>();
  225. ViewManager.Hide<LuckyBoxNewCardView>();
  226. GetSuitItemController.TryShow(_itemIdList[index]);
  227. _recordOpenIndex.Add(index);
  228. touchFlipOpen = true;
  229. _countShow = 0;
  230. _countNewRecord = 0;
  231. }
  232. }
  233. else
  234. {
  235. ViewManager.Hide<GetSuitItemVIew>();
  236. _rewardItemList.Clear();
  237. _rewardItemList.Add(_rewardList[index]);
  238. ViewManager.Show<LuckyBoxNewDressView>(_rewardItemList);
  239. _recordOpenIndex.Add(index);
  240. touchFlipOpen = true;
  241. _countNewRecord = 0;
  242. }
  243. }
  244. UI_LuckyBoxBonusShowItem.ProxyEnd();
  245. }
  246. else
  247. GoodsItemTipsController.ShowItemTips(_itemIdList[index]);
  248. }
  249. private void OnClickLoaBg()
  250. {
  251. if (_recordOpenIndex.Count >= _rewardList.Count)
  252. this.Hide();
  253. }
  254. private void OnClickBtnPass()
  255. {
  256. Timers.inst.Add(1f, 0, UpDataTime);
  257. }
  258. private void UpDataTime(object param = null)
  259. {
  260. if (_recordOpenIndex.Count >= _rewardList.Count) {
  261. Timers.inst.Remove(UpDataTime);
  262. HideOtherShowWindow();
  263. }
  264. for (int i = 0; i < _rewardList.Count; i++)
  265. {
  266. if (!_recordOpenIndex.Contains(i)) {
  267. ClickItem(i);
  268. break;
  269. }
  270. }
  271. }
  272. private void UpClickDataTime(object param = null)
  273. {
  274. int index = (int)param;
  275. if (_recordOpenIndex.Contains(index))
  276. {
  277. Timers.inst.Remove(UpClickDataTime);
  278. HideOtherShowWindow();
  279. }
  280. else
  281. ClickItem(index);
  282. }
  283. private void HideOtherShowWindow()
  284. {
  285. ViewManager.Hide<GetSuitItemVIew>();
  286. ViewManager.Hide<LuckyBoxNewDressView>();
  287. ViewManager.Hide<LuckyBoxNewCardView>();
  288. }
  289. }
  290. }