GetSuitItemVIew.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using cfg.GfgCfg;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using UnityEngine;
  5. using UI.LuckyBox;
  6. namespace GFGGame
  7. {
  8. public class GetSuitItemVIew : BaseWindow
  9. {
  10. private UI_GetSuitItemUI _ui;
  11. private EffectUI _effectUI1;
  12. private DressUpObjUI _dressUpObjUI;
  13. public override void Dispose()
  14. {
  15. EffectUIPool.Recycle(_effectUI1);
  16. _effectUI1 = null;
  17. if (_dressUpObjUI != null)
  18. {
  19. _dressUpObjUI.Dispose();
  20. _dressUpObjUI = null;
  21. }
  22. if (_dressUpObjUI != null)
  23. {
  24. _dressUpObjUI.Dispose();
  25. _dressUpObjUI = null;
  26. }
  27. if (_ui != null)
  28. {
  29. _ui.Dispose();
  30. _ui = null;
  31. }
  32. base.Dispose();
  33. }
  34. protected override void OnInit()
  35. {
  36. base.OnInit();
  37. _ui = UI_GetSuitItemUI.Create();
  38. this.viewCom = _ui.target;
  39. isfullScreen = true;
  40. _dressUpObjUI = new DressUpObjUI("SceneDressUp", onShowAction);
  41. _ui.m_loaBg.onClick.Add(OnClickBg);
  42. _ui.m_btnShare.onClick.Add(OnClickShare);
  43. EffectUIPool.CreateEffectUI(_ui.m_holderEffect, "ui_ck", "ui_ck_tz",
  44. onComplete: (effect) =>
  45. {
  46. if (effect != null)
  47. {
  48. _effectUI1 = effect;
  49. }
  50. });
  51. }
  52. void onShowAction()
  53. {
  54. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_ANIMATION_WAIT);
  55. }
  56. protected override void OnShown()
  57. {
  58. base.OnShown();
  59. GRoot.inst.touchable = true;
  60. _ui.m_loaBg.touchable = false;
  61. int suitId = (int)viewData;
  62. if (suitId == 202025)
  63. {
  64. _ui.m_icon.x = -600;
  65. }
  66. else
  67. {
  68. _ui.m_icon.x = 0;
  69. }
  70. if (!GetSuitItemController.isAuto)
  71. {
  72. _ui.m_btnShare.visible = false;
  73. }
  74. else
  75. {
  76. _ui.m_btnShare.visible = false;
  77. }
  78. UpdateView(suitId);
  79. Timers.inst.Add(0.5f, 1, OnTimerClick);
  80. }
  81. protected override void OnHide()
  82. {
  83. base.OnHide();
  84. if (this.viewCom == null || this.viewCom.root == null)
  85. {
  86. Timers.inst.CallLater((object param) => { GetSuitItemController.TryShow(0); });
  87. }
  88. TryCompleteGuide();
  89. Timers.inst.Remove(OnTimerClick);
  90. _ui.m_loaBg.touchable = true;
  91. }
  92. private void OnTimerClick(object param)
  93. {
  94. _ui.m_loaBg.touchable = true;
  95. }
  96. private void OnClickBg()
  97. {
  98. if (!GetSuitItemController.isAuto)
  99. {
  100. Hide();
  101. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_SHOW_VIEW_CLOSE);
  102. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_ANIMATION_WAIT);
  103. }
  104. }
  105. private void OnClickShare()
  106. {
  107. ShareDataManager.Instance.CaptureCameraToImage();
  108. }
  109. private void UpdateItem(int itemdId)
  110. {
  111. UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(_ui.m_item);
  112. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemdId);
  113. itemUI.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  114. string itemName = itemCfg.Name;
  115. itemUI.m_comIcon.m_txtName.text = itemName;
  116. RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.m_rarity, itemdId, false);
  117. itemUI.target.data = itemdId;
  118. itemUI.target.onClick.Clear();
  119. itemUI.target.onClick.Add(OnClickItemUI);
  120. UI_LuckyBoxBonusItem.ProxyEnd();
  121. }
  122. private void OnClickItemUI(EventContext context)
  123. {
  124. GComponent item = context.sender as GComponent;
  125. int itemID = (int)item.data;
  126. GoodsItemTipsController.ShowItemTips(itemID);
  127. }
  128. private void UpdateView(int suitId)
  129. {
  130. _ui.m_holderEffect.visible = true;
  131. int count = 0; // 套装当前拥有的部件数量
  132. int totalCount = 1;
  133. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bg_zhuxian");
  134. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  135. if (suitId > 0)
  136. {
  137. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(suitId);
  138. _ui.m_txtName.text = "套装·" + suitCfg.Name;
  139. int targetY = (int)(_ui.m_item.y + _ui.m_item.height + 50);
  140. }
  141. bool showAction = SuitCfgArray.Instance.CheckSuitHasAction(suitId) &&
  142. DressUpMenuSuitDataManager.CheckSuitHasActionRes(suitId);
  143. // 使用异步方式重置场景对象
  144. _dressUpObjUI.ResetSceneObjAsync(
  145. 115,
  146. false,
  147. true,
  148. null,
  149. false,
  150. (sceneObj) =>
  151. {
  152. if (sceneObj != null)
  153. {
  154. // 场景对象加载完成后穿上套装
  155. _dressUpObjUI.dressUpObj.PutOnSuitCfg(
  156. suitId,
  157. showAction,
  158. null,
  159. false,
  160. false
  161. );
  162. _dressUpObjUI.UpdateWrapper(_ui.m_holder);
  163. }
  164. else
  165. {
  166. Debug.LogError($"Failed to load scene object for suit: {suitId}");
  167. }
  168. }
  169. );
  170. }
  171. }
  172. }