LuckyBoxBonusShowView.cs 5.5 KB

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