LuckyBoxBonusShowView.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 Dictionary<int, Dictionary<int, GameObject>> _gameobjects = new Dictionary<int, Dictionary<int, GameObject>>();
  14. private Dictionary<int, Dictionary<int, GoWrapper>> _wrappers = new Dictionary<int, Dictionary<int, GoWrapper>>();
  15. private EffectUI _effectUI1;
  16. private EffectUI _effectUI2;
  17. private EffectUI _effectUI3;
  18. private EffectUI _effectUI4;
  19. private int _effectIndex = 0;
  20. public override void Dispose()
  21. {
  22. base.Dispose();
  23. // for (int i = 0; i < _gameobjects.Count; i++)
  24. // {
  25. // SceneController.DestroyObjectFromView(_gameobjects[i], _wrappers[i]);
  26. // }
  27. foreach (int key in _gameobjects.Keys)
  28. {
  29. foreach (int key1 in _gameobjects[key].Keys)
  30. {
  31. SceneController.DestroyObjectFromView(_gameobjects[key][key1], _wrappers[key][key1]);
  32. }
  33. }
  34. EffectUIPool.Recycle(_effectUI1);
  35. _effectUI1 = null;
  36. EffectUIPool.Recycle(_effectUI2);
  37. _effectUI2 = null;
  38. EffectUIPool.Recycle(_effectUI3);
  39. _effectUI3 = null;
  40. EffectUIPool.Recycle(_effectUI4);
  41. _effectUI4 = null;
  42. if (_ui != null)
  43. {
  44. _ui.Dispose();
  45. _ui = null;
  46. }
  47. }
  48. protected override void OnInit()
  49. {
  50. base.OnInit();
  51. packageName = UI_LuckBoxBonusShowUI.PACKAGE_NAME;
  52. _ui = UI_LuckBoxBonusShowUI.Create();
  53. this.viewCom = _ui.target;
  54. isfullScreen = true;
  55. _ui.m_loaBg.onClick.Add(this.Hide);
  56. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zx_bg");
  57. UpdateEffect();
  58. }
  59. private void UpdateEffect()
  60. {
  61. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder_star, "ui_LuckyBox", "bg_liuxing");
  62. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holder_bg, "ui_LuckyBox", "CK_UI");
  63. _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_holder_cloud, "ui_LuckyBox", "bg_cloud");
  64. }
  65. protected override void OnShown()
  66. {
  67. base.OnShown();
  68. _rewardList.AddRange(this.viewData as List<ItemData>);
  69. _effectIndex = 0;
  70. if (_rewardList.Count == 1)
  71. {
  72. _ui.m_c1.selectedIndex = 0;
  73. UpdateItem(_ui.m_itemOne.target, 0, 1);
  74. }
  75. else
  76. {
  77. _ui.m_c1.selectedIndex = 1;
  78. for (int i = 0; i < _rewardList.Count; i++)
  79. {
  80. UpdateItem(_ui.target.GetChild("item" + i).asCom, i, 10);
  81. }
  82. }
  83. }
  84. protected override void OnHide()
  85. {
  86. base.OnHide();
  87. _rewardList.Clear();
  88. GetSuitItemController.TryShow(0);
  89. }
  90. private void UpdateItem(GComponent com, int index, int countType)
  91. {
  92. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
  93. ItemData itemData = _rewardList[index];
  94. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  95. item.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
  96. item.m_comIcon.m_txtName.text = itemCfg.name;
  97. item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  98. RarityIconController.UpdateRarityIcon(item.m_comIcon.m_rarity, itemData.id, false);
  99. string resPath = itemCfg.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_01" : "CK_all_02";
  100. if (countType == 10 && itemCfg.rarity > 2 && (!_gameobjects.ContainsKey(itemCfg.rarity) || !_gameobjects[itemCfg.rarity].ContainsKey(index)))
  101. {
  102. if (!_gameobjects.ContainsKey(itemCfg.rarity))
  103. {
  104. _gameobjects[itemCfg.rarity] = new Dictionary<int, GameObject>();
  105. _wrappers[itemCfg.rarity] = new Dictionary<int, GoWrapper>();
  106. }
  107. GGraph holder = itemCfg.rarity == 3 ? item.m_comIcon.m_holder : item.m_comIcon.m_holder1;
  108. SceneController.AddObjectToView(null, null, holder, resPath, out GameObject gameObject, out GoWrapper wrapper);
  109. _gameobjects[itemCfg.rarity][index] = gameObject;
  110. _wrappers[itemCfg.rarity][index] = wrapper;
  111. }
  112. if (countType == 1 && itemCfg.rarity > 2 && _effectUI4 == null)
  113. {
  114. GGraph holder = itemCfg.rarity == 3 ? item.m_comIcon.m_holder : item.m_comIcon.m_holder1;
  115. _effectUI4 = EffectUIPool.CreateEffectUI(holder, "ui_LuckyBox", resPath);
  116. }
  117. int count = 0;
  118. bool isFirst = false;
  119. for (int i = 0; i < _rewardList.Count; i++)
  120. {
  121. if (_rewardList[i].id == itemData.id) count++;
  122. if (count == 1 && i == index) isFirst = true;
  123. }
  124. item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
  125. item.m_t0.Play();
  126. if (item.target.data == null)
  127. {
  128. item.target.onClick.Add(ShowItemTips);
  129. }
  130. item.target.data = itemCfg.id;
  131. UI_LuckyBoxBonusShowItem.ProxyEnd();
  132. }
  133. private void ShowItemTips(EventContext context)
  134. {
  135. GObject obj = context.sender as GObject;
  136. int itemID = (int)obj.data;
  137. GoodsItemTipsController.ShowItemTips(itemID);
  138. }
  139. }
  140. }