LuckyBoxBonusView.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. public override void Dispose()
  12. {
  13. base.Dispose();
  14. }
  15. protected override void OnInit()
  16. {
  17. base.OnInit();
  18. packageName = UI_LuckBoxBonusUI.PACKAGE_NAME;
  19. _ui = UI_LuckBoxBonusUI.Create();
  20. this.viewCom = _ui.target;
  21. isfullScreen = true;
  22. InitAllItem();
  23. _ui.m_bg.touchable = false;
  24. _ui.m_bg.onClick.Add(OnClickBg);
  25. }
  26. protected override void OnShown()
  27. {
  28. base.OnShown();
  29. List<ItemData> itemList = (viewData as object[])[0] as List<ItemData>;
  30. if (itemList != null)
  31. {
  32. _ui.m_bg.touchable = false;
  33. int count = itemList.Count;
  34. if (count == 10)
  35. {
  36. ShowBonusList(itemList);
  37. }
  38. else if (count > 0)
  39. {
  40. ShowBonus(itemList[0]);
  41. }
  42. else
  43. {
  44. _ui.m_bg.touchable = true;
  45. }
  46. }
  47. else
  48. {
  49. _ui.m_bg.touchable = true;
  50. }
  51. }
  52. protected override void OnHide()
  53. {
  54. base.OnHide();
  55. }
  56. private void OnClickBg()
  57. {
  58. this.Hide();
  59. ViewManager.Show(ViewName.LUCKY_BOX_VIEW);
  60. }
  61. private void ShowBonusList(List<ItemData> itemList)
  62. {
  63. HideAllItem();
  64. for (int i = 0; i < 10; i++)
  65. {
  66. ItemData itemData = itemList[i];
  67. GObject itemObject = _ui.target.GetChild("item" + i);
  68. if (itemObject != null)
  69. {
  70. UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(itemObject);
  71. UpdateItem(itemUI, itemData);
  72. Timers.inst.Add(0.1f * i, 1, (object param) =>
  73. {
  74. itemObject.visible = true;
  75. if ((int)param == 9)
  76. {
  77. Timers.inst.Add(0.1f, 1, (object param) =>
  78. {
  79. _ui.m_bg.touchable = true;
  80. List<ItemData> list = LuckyBoxDataManager.Instance.GetFirstClothingList();
  81. if (list.Count > 0)
  82. {
  83. ViewManager.Show(ViewName.LUCKY_BOX_CARD_VIEW, new object[] { list, FirstGetCardViewType.CANNOT_JUMP_CANNOT_SUIT });
  84. }
  85. else
  86. {
  87. int itemId = GetSuitItemController.TryShow(0);
  88. }
  89. });
  90. }
  91. }, i);
  92. }
  93. }
  94. }
  95. private void ShowBonus(ItemData itemData)
  96. {
  97. HideAllItem();
  98. _ui.m_itemOne.visible = true;
  99. UpdateItem(UI_LuckyBoxBonusItem.Proxy(_ui.m_itemOne), itemData);
  100. _ui.m_bg.touchable = true;
  101. }
  102. private void HideAllItem()
  103. {
  104. _ui.m_itemOne.visible = false;
  105. for (int i = 0; i < 10; i++)
  106. {
  107. GObject itemObject = _ui.target.GetChild("item" + i);
  108. if (itemObject != null)
  109. {
  110. itemObject.visible = false;
  111. }
  112. }
  113. }
  114. private void UpdateItem(UI_LuckyBoxBonusItem itemUI, ItemData itemData)
  115. {
  116. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  117. itemUI.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  118. itemUI.m_imgNew.visible = ItemDataManager.GetItemNum(itemData.id) == 1 ? true : false;
  119. string itemName = itemCfg.name;
  120. if (itemData.num > 1)
  121. {
  122. itemName += "x" + itemData.num;
  123. }
  124. itemUI.m_txtName.text = itemName;
  125. RarityIconController.UpdateRarityIcon(itemUI.m_rarity, itemData.id, false);
  126. itemUI.target.data = itemData.id;
  127. }
  128. private void InitAllItem()
  129. {
  130. _ui.m_itemOne.onClick.Add(OnClickItemUI);
  131. for (int i = 0; i < 10; i++)
  132. {
  133. GObject itemObject = _ui.target.GetChild("item" + i);
  134. if (itemObject != null)
  135. {
  136. itemObject.onClick.Add(OnClickItemUI);
  137. }
  138. }
  139. }
  140. private void OnClickItemUI(EventContext context)
  141. {
  142. GComponent item = context.sender as GComponent;
  143. int itemID = (int)item.data;
  144. GoodsItemTipsController.ShowItemTips(itemID);
  145. }
  146. }
  147. }