GetSuitItemVIew.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderEffect, "ui_ck", "ui_ck_tz");
  44. }
  45. void onShowAction()
  46. {
  47. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_ANIMATION_WAIT);
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. GRoot.inst.touchable = true;
  53. _ui.m_loaBg.touchable = false;
  54. int suitId = (int)viewData;
  55. if (suitId == 202025)
  56. {
  57. _ui.m_icon.x = -600;
  58. }
  59. else
  60. {
  61. _ui.m_icon.x = 0;
  62. }
  63. if (!GetSuitItemController.isAuto)
  64. {
  65. _ui.m_btnShare.visible = false;
  66. }
  67. else
  68. {
  69. _ui.m_btnShare.visible = false;
  70. }
  71. UpdateView(suitId);
  72. Timers.inst.Add(0.5f, 1, OnTimerClick);
  73. }
  74. protected override void OnHide()
  75. {
  76. base.OnHide();
  77. if (this.viewCom == null || this.viewCom.root == null)
  78. {
  79. Timers.inst.CallLater((object param) => { GetSuitItemController.TryShow(0); });
  80. }
  81. TryCompleteGuide();
  82. Timers.inst.Remove(OnTimerClick);
  83. _ui.m_loaBg.touchable = true;
  84. }
  85. private void OnTimerClick(object param)
  86. {
  87. _ui.m_loaBg.touchable = true;
  88. }
  89. private void OnClickBg()
  90. {
  91. if (!GetSuitItemController.isAuto)
  92. {
  93. Hide();
  94. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_SHOW_VIEW_CLOSE);
  95. EventAgent.DispatchEvent(ConstMessage.LUCKY_BOX_ANIMATION_WAIT);
  96. }
  97. }
  98. private void OnClickShare()
  99. {
  100. ShareDataManager.Instance.CaptureCameraToImage();
  101. }
  102. private void UpdateItem(int itemdId)
  103. {
  104. UI_LuckyBoxBonusItem itemUI = UI_LuckyBoxBonusItem.Proxy(_ui.m_item);
  105. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemdId);
  106. itemUI.m_comIcon.m_icon.url = ResPathUtil.GetIconPath(itemCfg);
  107. string itemName = itemCfg.Name;
  108. itemUI.m_comIcon.m_txtName.text = itemName;
  109. RarityIconController.UpdateRarityIcon(itemUI.m_comIcon.m_rarity, itemdId, false);
  110. itemUI.target.data = itemdId;
  111. itemUI.target.onClick.Clear();
  112. itemUI.target.onClick.Add(OnClickItemUI);
  113. UI_LuckyBoxBonusItem.ProxyEnd();
  114. }
  115. private void OnClickItemUI(EventContext context)
  116. {
  117. GComponent item = context.sender as GComponent;
  118. int itemID = (int)item.data;
  119. GoodsItemTipsController.ShowItemTips(itemID);
  120. }
  121. private void UpdateView(int suitId)
  122. {
  123. _ui.m_holderEffect.visible = true;
  124. int count = 0; // 套装当前拥有的部件数量
  125. int totalCount = 1;
  126. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bg_zhuxian");
  127. DressUpMenuSuitDataManager.GetSuitProgressBySuitId(suitId, out count, out totalCount);
  128. if (suitId > 0)
  129. {
  130. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(suitId);
  131. _ui.m_txtName.text = "套装·" + suitCfg.Name;
  132. int targetY = (int)(_ui.m_item.y + _ui.m_item.height + 50);
  133. }
  134. bool showAction = SuitCfgArray.Instance.CheckSuitHasAction(suitId) &&
  135. DressUpMenuSuitDataManager.CheckSuitHasActionRes(suitId);
  136. // 使用异步方式重置场景对象
  137. _dressUpObjUI.ResetSceneObjAsync(
  138. 115,
  139. false,
  140. true,
  141. null,
  142. false,
  143. (sceneObj) =>
  144. {
  145. if (sceneObj != null)
  146. {
  147. // 场景对象加载完成后穿上套装
  148. _dressUpObjUI.dressUpObj.PutOnSuitCfg(
  149. suitId,
  150. showAction,
  151. null,
  152. false,
  153. false
  154. );
  155. _dressUpObjUI.UpdateWrapper(_ui.m_holder);
  156. }
  157. else
  158. {
  159. Debug.LogError($"Failed to load scene object for suit: {suitId}");
  160. }
  161. }
  162. );
  163. }
  164. }
  165. }