LuckyBoxBonusShowView.cs 6.1 KB

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