LuckyBoxBonusShowView.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. GetSuitItemController.TryShow(0);
  84. }
  85. private void UpdateItem(GComponent com, int index)
  86. {
  87. UI_LuckyBoxBonusShowItem item = UI_LuckyBoxBonusShowItem.Proxy(com);
  88. ItemData itemData = _rewardList[index];
  89. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemData.id);
  90. item.m_comIcon.m_c1.selectedIndex = itemCfg.rarity;
  91. item.m_comIcon.m_txtName.text = itemCfg.name;
  92. item.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  93. RarityIconController.UpdateRarityIcon(item.m_comIcon.m_rarity, itemData.id, false);
  94. if (itemCfg.rarity > 2)
  95. {
  96. string resPath = ResPathUtil.GetViewEffectPath("ui_LuckyBox", itemCfg.rarity == ConstDressRarity.Rarity_TIANYI ? "CK_all_01" : "CK_all_02");
  97. if (_effectIndex > _gameobjects.Count)
  98. {
  99. GameObject gameObject = _gameobjects[_effectIndex];
  100. GoWrapper wrapper = _wrappers[_effectIndex];
  101. SceneController.AddObjectToView(gameObject, wrapper, item.m_comIcon.m_holder, resPath, out gameObject, out wrapper);
  102. }
  103. else
  104. {
  105. SceneController.AddObjectToView(null, null, item.m_comIcon.m_holder, resPath, out GameObject gameObject, out GoWrapper wrapper);
  106. _gameobjects.Add(gameObject);
  107. _wrappers.Add(wrapper);
  108. }
  109. _effectIndex++;
  110. }
  111. int count = 0;
  112. bool isFirst = false;
  113. for (int i = 0; i < _rewardList.Count; i++)
  114. {
  115. if (_rewardList[i].id == itemData.id) count++;
  116. if (count == 1 && i == index) isFirst = true;
  117. }
  118. item.m_comIcon.m_imgNew.visible = count == ItemDataManager.GetItemNum(itemData.id) && isFirst;
  119. item.m_t0.Play();
  120. if (item.target.data == null)
  121. {
  122. item.target.onClick.Add(ShowItemTips);
  123. }
  124. item.target.data = itemCfg.id;
  125. UI_LuckyBoxBonusShowItem.ProxyEnd();
  126. }
  127. private void ShowItemTips(EventContext context)
  128. {
  129. GObject obj = context.sender as GObject;
  130. int itemID = (int)obj.data;
  131. GoodsItemTipsController.ShowItemTips(itemID);
  132. }
  133. }
  134. }