LuckyBoxBonusView.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.LuckyBox;
  4. using UI.CommonGame;
  5. using System.Collections.Generic;
  6. namespace GFGGame
  7. {
  8. public class LuckyBoxBonusView : BaseWindow
  9. {
  10. private UI_LuckBoxBonusUI _ui;
  11. private List<ItemData> itemList;
  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. _ui.m_loaBg.Dispose();
  25. // for (int i = 0; i < 10; i++)
  26. // {
  27. // GObject itemObject = _ui.target.GetChild("item" + i);
  28. // UI_LuckyBoxBonusItem listItem = UI_LuckyBoxBonusItem.Proxy(itemObject);
  29. // listItem.m_comIcon.m_icon.Dispose();
  30. // UI_LuckyBoxBonusItem.ProxyEnd();
  31. // }
  32. // UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(_ui.m_itemOne);
  33. // itemUI.m_comIcon.m_icon.Dispose();
  34. // UI_LuckyBoxBonusItem.ProxyEnd();
  35. if (_ui != null)
  36. {
  37. _ui.Dispose();
  38. _ui = null;
  39. }
  40. }
  41. protected override void OnInit()
  42. {
  43. base.OnInit();
  44. packageName = UI_LuckBoxBonusUI.PACKAGE_NAME;
  45. _ui = UI_LuckBoxBonusUI.Create();
  46. this.viewCom = _ui.target;
  47. isfullScreen = true;
  48. InitAllItem();
  49. _ui.m_loaBg.touchable = false;
  50. _ui.m_loaBg.onClick.Add(OnClickBg);
  51. string resPath = ResPathUtil.GetViewEffectPath("ui_ck", "ui_ck_zl");
  52. for (int i = 0; i < 10; i++)
  53. {
  54. GameObject gameObject0;
  55. GoWrapper wrapper0;
  56. GGraph holder = _ui.target.GetChild("item" + i).asCom.GetChild("holder").asGraph;
  57. SceneController.AddObjectToView(null, null, holder, resPath, out gameObject0, out wrapper0);
  58. _effects.Add(gameObject0);
  59. _wrappers.Add(wrapper0);
  60. }
  61. GGraph holder1 = _ui.target.GetChild("itemOne").asCom.GetChild("holder").asGraph;
  62. SceneController.AddObjectToView(null, null, holder1, resPath, out _effect, out _wrapper);
  63. }
  64. protected override void OnShown()
  65. {
  66. base.OnShown();
  67. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gxhd_bjbj");
  68. itemList = (viewData as object[])[0] as List<ItemData>;
  69. if (itemList != null)
  70. {
  71. _ui.m_loaBg.touchable = false;
  72. int count = itemList.Count;
  73. if (count == 10)
  74. {
  75. ShowBonusList(itemList);
  76. }
  77. else if (count > 0)
  78. {
  79. ShowBonus(itemList[0]);
  80. }
  81. else
  82. {
  83. _ui.m_loaBg.touchable = true;
  84. }
  85. }
  86. else
  87. {
  88. _ui.m_loaBg.touchable = true;
  89. }
  90. }
  91. protected override void OnHide()
  92. {
  93. base.OnHide();
  94. }
  95. private void OnClickBg()
  96. {
  97. this.Hide();
  98. ViewManager.Show(ViewName.LUCKY_BOX_VIEW, ViewManager.GetGoBackDatas(ViewName.LUCKY_BOX_STAR_VIEW));
  99. GetSuitItemController.TryShow(0);
  100. }
  101. private void ShowBonusList(List<ItemData> itemList)
  102. {
  103. HideAllItem();
  104. for (int i = 0; i < 10; i++)
  105. {
  106. ItemData itemData = itemList[i];
  107. GObject itemObject = _ui.target.GetChild("item" + i);
  108. if (itemObject != null)
  109. {
  110. UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(itemObject);
  111. UpdateItem(itemUI, itemData, i);
  112. UI_LuckyBoxBonusItem.ProxyEnd();
  113. Timers.inst.Add(0.3f * i, 1, (object param) =>
  114. {
  115. itemObject.visible = true;
  116. if ((int)param == 9)
  117. {
  118. Timers.inst.Add(0.1f, 1, (object param) =>
  119. {
  120. _ui.m_loaBg.touchable = true;
  121. // List<ItemData> list = LuckyBoxDataManager.Instance.GetFirstClothingList();
  122. // if (list.Count > 0)
  123. // {
  124. // ViewManager.Show(ViewName.LUCKY_BOX_CARD_VIEW, new object[] { list, FirstGetCardViewType.CANNOT_JUMP_CANNOT_SUIT });
  125. // }
  126. // else
  127. // {
  128. // GetSuitItemController.TryShow(0);
  129. // }
  130. });
  131. }
  132. }, i);
  133. }
  134. }
  135. }
  136. private void ShowBonus(ItemData itemData)
  137. {
  138. HideAllItem();
  139. _ui.m_itemOne.visible = true;
  140. UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(_ui.m_itemOne);
  141. UpdateItem(itemUI, itemData, 0);
  142. UI_LuckyBoxBonusItem.ProxyEnd();
  143. _ui.m_loaBg.touchable = true;
  144. }
  145. private void HideAllItem()
  146. {
  147. _ui.m_itemOne.visible = false;
  148. for (int i = 0; i < 10; i++)
  149. {
  150. GObject itemObject = _ui.target.GetChild("item" + i);
  151. if (itemObject != null)
  152. {
  153. itemObject.visible = false;
  154. }
  155. }
  156. }
  157. private void UpdateItem(UI_LuckyBoxBonusItem itemUI, ItemData itemData, int index)
  158. {
  159. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  160. itemUI.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  161. bool isFirst = true;
  162. int count = 0;
  163. for (int i = 0; i < itemList.Count; i++)
  164. {
  165. if (i < index && itemList[i].id == itemData.id)
  166. {
  167. isFirst = false;
  168. }
  169. if (itemList[i].id == itemData.id)
  170. {
  171. count++;
  172. }
  173. }
  174. itemUI.m_comIcon.m_imgNew.visible = ItemDataManager.GetItemNum(itemData.id) == count && isFirst ? true : false;
  175. string itemName = itemCfg.name;
  176. if (itemData.num > 1)
  177. {
  178. itemName += "x" + itemData.num;
  179. }
  180. itemUI.m_comIcon.m_txtName.text = itemName;
  181. RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.m_rarity, itemData.id, false);
  182. itemUI.target.data = itemData.id;
  183. itemUI.m_comIcon.target.SetScale(0, 0);
  184. itemUI.m_t0.Play();
  185. // GTween.To(0, 1, 0.2f).SetTarget(itemUI).OnUpdate((GTweener t) => { itemUI.target.SetScale(t.value.x, t.value.x); });
  186. }
  187. private void InitAllItem()
  188. {
  189. _ui.m_itemOne.onClick.Add(OnClickItemUI);
  190. for (int i = 0; i < 10; i++)
  191. {
  192. GObject itemObject = _ui.target.GetChild("item" + i);
  193. if (itemObject != null)
  194. {
  195. itemObject.onClick.Add(OnClickItemUI);
  196. }
  197. }
  198. }
  199. private void OnClickItemUI(EventContext context)
  200. {
  201. GComponent item = context.sender as GComponent;
  202. int itemID = (int)item.data;
  203. GoodsItemTipsController.ShowItemTips(itemID);
  204. }
  205. }
  206. }