LuckyBoxBonusShowView.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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<GameObject> _gameobjects = new List<GameObject>();
  13. private List<GoWrapper> _wrappers = new List<GoWrapper>();
  14. private GameObject _gameobject;
  15. private GoWrapper _wrapper;
  16. private int _effectIndex = 0;
  17. public override void Dispose()
  18. {
  19. base.Dispose();
  20. for (int i = 0; i < _gameobjects.Count; i++)
  21. {
  22. SceneController.DestroyObjectFromView(_gameobjects[i], _wrappers[i]);
  23. }
  24. SceneController.DestroyObjectFromView(_gameobject, _wrapper);
  25. if (_ui != null)
  26. {
  27. _ui.Dispose();
  28. _ui = null;
  29. }
  30. }
  31. protected override void OnInit()
  32. {
  33. base.OnInit();
  34. packageName = UI_LuckBoxBonusShowUI.PACKAGE_NAME;
  35. _ui = UI_LuckBoxBonusShowUI.Create();
  36. this.viewCom = _ui.target;
  37. isfullScreen = true;
  38. _ui.m_loaBg.onClick.Add(this.Hide);
  39. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  40. }
  41. protected override void OnShown()
  42. {
  43. base.OnShown();
  44. _rewardList.AddRange(this.viewData as List<ItemData>);
  45. _effectIndex = 0;
  46. if (_rewardList.Count == 1)
  47. {
  48. _ui.m_c1.selectedIndex = 0;
  49. UpdateItem(_ui.m_itemOne.target, 0);
  50. }
  51. else
  52. {
  53. _ui.m_c1.selectedIndex = 1;
  54. for (int i = 0; i < _rewardList.Count; i++)
  55. {
  56. UpdateItem(_ui.target.GetChild("item" + i).asCom, i);
  57. }
  58. }
  59. }
  60. protected override void OnHide()
  61. {
  62. base.OnHide();
  63. _rewardList.Clear();
  64. }
  65. private void UpdateItem(GComponent com, int index)
  66. {
  67. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
  68. ItemData itemData = _rewardList[index];
  69. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  70. item.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
  71. item.m_comIcon.m_txtName.text = itemCfg.name;
  72. item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  73. RarityIconController.UpdateRarityIcon(item.m_comIcon.m_rarity, itemData.id, false);
  74. if (itemCfg.rarity > 2)
  75. {
  76. string resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", itemCfg.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_01" : "CK_all_02");
  77. if (_effectIndex > _gameobjects.Count)
  78. {
  79. GameObject gameObject = _gameobjects[_effectIndex];
  80. GoWrapper wrapper = _wrappers[_effectIndex];
  81. SceneController.AddObjectToView(gameObject, wrapper, item.m_comIcon.m_holder, resPath, out gameObject, out wrapper);
  82. }
  83. else
  84. {
  85. SceneController.AddObjectToView(null, null, item.m_comIcon.m_holder, resPath, out GameObject gameObject, out GoWrapper wrapper);
  86. _gameobjects.Add(gameObject);
  87. _wrappers.Add(wrapper);
  88. }
  89. _effectIndex++;
  90. }
  91. int count = 0;
  92. bool isFirst = false;
  93. for (int i = 0; i < _rewardList.Count; i++)
  94. {
  95. if (_rewardList[i].id == itemData.id) count++;
  96. if (count == 1 && i == index) isFirst = true;
  97. }
  98. item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
  99. item.m_t0.Play();
  100. if (item.target.data == null)
  101. {
  102. item.target.onClick.Add(ShowItemTips);
  103. }
  104. item.target.data = itemCfg.id;
  105. UI_LuckyBoxBonusShowItem.ProxyEnd();
  106. }
  107. private void ShowItemTips(EventContext context)
  108. {
  109. GObject obj = context.sender as GObject;
  110. int itemID = (int)obj.data;
  111. GoodsItemTipsController.ShowItemTips(itemID);
  112. }
  113. }
  114. }