LuckyBoxBonusView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.LuckyBox;
  4. using System.Collections.Generic;
  5. namespace GFGGame
  6. {
  7. public class LuckyBoxBonusView : BaseWindow
  8. {
  9. private UI_LuckBoxBonusUI _ui;
  10. private List<ItemData> itemList;
  11. private int openCount = 0;
  12. private List<GameObject> _effects = new List<GameObject>();
  13. private List<GoWrapper> _wrappers = new List<GoWrapper>();
  14. private GameObject _effect;
  15. private GoWrapper _wrapper;
  16. public override void Dispose()
  17. {
  18. base.Dispose();
  19. for (int i = 0; i < _effects.Count; i++)
  20. {
  21. SceneController.DestroyObjectFromView(_effects[i], _wrappers[i]);
  22. }
  23. SceneController.DestroyObjectFromView(_effect, _wrapper);
  24. if (_ui != null)
  25. {
  26. _ui.Dispose();
  27. _ui = null;
  28. }
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. packageName = UI_LuckBoxBonusUI.PACKAGE_NAME;
  34. _ui = UI_LuckBoxBonusUI.Create();
  35. this.viewCom = _ui.target;
  36. isfullScreen = true;
  37. InitAllItem();
  38. _ui.m_loaBg.onClick.Add(OnClickBg);
  39. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bj_ckzxin");
  40. _ui.m_loaOpen.onClick.Add(OnClickOpen);
  41. }
  42. protected override void OnShown()
  43. {
  44. base.OnShown();
  45. itemList = (viewData as object[])[0] as List<ItemData>;
  46. if (itemList != null)
  47. {
  48. _ui.m_loaOpen.visible = true;
  49. int count = itemList.Count;
  50. if (count == 10)
  51. {
  52. _ui.m_c1.selectedIndex = 1;
  53. }
  54. else if (count > 0)
  55. {
  56. _ui.m_c1.selectedIndex = 0;
  57. }
  58. ShowBonusList();
  59. }
  60. else
  61. {
  62. _ui.m_loaOpen.visible = false;
  63. }
  64. }
  65. protected override void OnHide()
  66. {
  67. base.OnHide();
  68. }
  69. private void OnClickBg()
  70. {
  71. this.Hide();
  72. ViewManager.Show(ViewName.LUCKY_BOX_VIEW, ViewManager.GetGoBackDatas(ViewName.LUCKY_BOX_STAR_VIEW));
  73. GetSuitItemController.TryShow(0);
  74. }
  75. private void ShowBonusList()
  76. {
  77. if (itemList.Count > 1)
  78. {
  79. for (int i = 0; i < itemList.Count; i++)
  80. {
  81. GObject itemObject = _ui.target.GetChild("item" + i);
  82. if (itemObject != null)
  83. {
  84. UpdateItem(i, itemObject);
  85. }
  86. }
  87. }
  88. else
  89. {
  90. UpdateItem(0, _ui.m_itemOne.target);
  91. }
  92. }
  93. private void HideAllItem()
  94. {
  95. _ui.m_itemOne.target.visible = false;
  96. for (int i = 0; i < 10; i++)
  97. {
  98. GObject itemObject = _ui.target.GetChild("item" + i);
  99. if (itemObject != null)
  100. {
  101. itemObject.visible = false;
  102. }
  103. }
  104. }
  105. private void UpdateItem(int index, GObject obj)
  106. {
  107. ItemData itemData = itemList[index];
  108. UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(obj);
  109. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  110. bool isFirst = true;
  111. int count = 0;
  112. for (int i = 0; i < itemList.Count; i++)
  113. {
  114. if (i < index && itemList[i].id == itemData.id)
  115. {
  116. isFirst = false;
  117. }
  118. if (itemList[i].id == itemData.id)
  119. {
  120. count++;
  121. }
  122. }
  123. itemUI.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  124. itemUI.m_comIcon.m_imgNew.visible = ItemDataManager.GetItemNum(itemData.id) == count && isFirst ? true : false;
  125. string itemName = itemCfg.name;
  126. if (itemData.num > 1)
  127. {
  128. itemName += "x" + itemData.num;
  129. }
  130. itemUI.m_comIcon.m_txtName.text = itemName;
  131. itemUI.m_c1.selectedIndex = itemCfg.rarity;
  132. itemUI.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
  133. RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.m_rarity, itemData.id, false);
  134. itemUI.m_comIcon.m_icon.data = itemData.id;
  135. // itemUI.m_comIcon.target.SetScale(0, 0);
  136. itemUI.m_t0.Play();
  137. UI_LuckyBoxBonusItem.ProxyEnd();
  138. }
  139. private void InitAllItem()
  140. {
  141. UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(_ui.m_itemOne.target);
  142. itemUI.target.onClick.Add(OnClickItem);
  143. itemUI.m_comIcon.m_icon.onClick.Add(OnClickItemTips);
  144. UI_LuckyBoxBonusItem.ProxyEnd();
  145. for (int i = 0; i < 10; i++)
  146. {
  147. GObject itemObject = _ui.target.GetChild("item" + i);
  148. if (itemObject != null)
  149. {
  150. UI_LuckyBoxBonusItem itemUITen = UI_LuckyBoxBonusItem.Proxy(itemObject);
  151. itemUITen.target.onClick.Add(OnClickItem);
  152. itemUITen.m_comIcon.m_icon.onClick.Add(OnClickItemTips);
  153. UI_LuckyBoxBonusItem.ProxyEnd();
  154. }
  155. }
  156. }
  157. private void OnClickItem(EventContext context)
  158. {
  159. GComponent item = context.sender as GComponent;
  160. PlayOpenAni(item);
  161. }
  162. private void OnClickOpen()
  163. {
  164. for (int i = 0; i < itemList.Count; i++)
  165. {
  166. GComponent component = _ui.target.GetChild("item" + i).asCom;
  167. if (component != null)
  168. {
  169. bool playing = PlayOpenAni(component);
  170. if (!playing) continue;
  171. if (playing) break;
  172. }
  173. }
  174. }
  175. private bool PlayOpenAni(GComponent component)
  176. {
  177. Transition transition = component.GetTransition("t1");
  178. GComponent comIcon = component.GetChild("comIcon").asCom;
  179. if (transition.playing || comIcon.skew == Vector2.zero) return false;
  180. transition.Play(UpdateOpenCount);
  181. return true;
  182. }
  183. private void UpdateOpenCount()
  184. {
  185. openCount++;
  186. if (openCount == itemList.Count)
  187. {
  188. _ui.m_loaOpen.visible = false;
  189. }
  190. }
  191. private void OnClickItemTips(EventContext context)
  192. {
  193. GLoader item = context.sender as GLoader;
  194. int itemID = (int)item.data;
  195. GoodsItemTipsController.ShowItemTips(itemID);
  196. }
  197. }
  198. }