GetSuitItemVIew.cs 6.3 KB

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