SuitShowView.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using UI.FieldGuide;
  2. using FairyGUI;
  3. using UnityEngine;
  4. using System.Collections.Generic;
  5. using cfg.GfgCfg;
  6. using ET;
  7. namespace GFGGame
  8. {
  9. public class SuitShowView : BaseWindow
  10. {
  11. private UI_SuitShowUI _ui;
  12. private int _suitTypeId;
  13. private int _suitId;
  14. private DressUpObjUI _dressUpObjUI;
  15. private bool _actionIsPic;
  16. private List<int> _suitIds;
  17. private bool touchClick = true;
  18. public override void Dispose()
  19. {
  20. Timers.inst.Remove(OnTimerUpDate);
  21. if (_dressUpObjUI != null)
  22. {
  23. _dressUpObjUI.Dispose();
  24. _dressUpObjUI = null;
  25. }
  26. if (_ui != null)
  27. {
  28. _ui.Dispose();
  29. _ui = null;
  30. }
  31. base.Dispose();
  32. }
  33. protected override void OnInit()
  34. {
  35. base.OnInit();
  36. packageName = UI_SuitShowUI.PACKAGE_NAME;
  37. _ui = UI_SuitShowUI.Create();
  38. this.viewCom = _ui.target;
  39. isfullScreen = true;
  40. //isReturnView = true;
  41. this.clickBlankToClose = false;
  42. //_dressUpObjUI = new DressUpObjUI("SceneDressUp");
  43. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  44. _ui.m_imgBonusBox.target.onClick.Add(OnClickImgBonusBox);
  45. _ui.m_btnChangeAction.visible = false;
  46. _ui.m_btnLeft.onClick.Add(OnClickBtnLeft);
  47. _ui.m_btnRight.onClick.Add(OnClickBtnRight);
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. object[] datas = this.viewData as object[];
  53. _suitTypeId = (int)datas[0];
  54. _suitId = (int)datas[1];
  55. List<int> suitIds = datas[2] as List<int>;
  56. _ui.m_imgBonusBox.target.visible = datas.Length >= 4 ? (bool)datas[3] : true;
  57. _suitIds = new List<int>();
  58. foreach (int suitId in suitIds)
  59. {
  60. if (DressUpMenuSuitDataManager.CheckHaveSuit(suitId))
  61. {
  62. _suitIds.Add(suitId);
  63. }
  64. }
  65. SuitGuideMenuCfg cfg = CommonDataManager.Tables.TblSuitGuideMenuCfg.GetOrDefault(_suitTypeId);
  66. if (cfg == null)
  67. {
  68. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_suitId);
  69. _ui.m_txtSuitName.text = suitCfg.Name;
  70. }
  71. else
  72. {
  73. _ui.m_txtTypeName.text = cfg.Name;
  74. }
  75. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjtj_bjbj");
  76. UpdateArrows();
  77. UpdateSuitView();
  78. UpdateSuitBoxStatus();
  79. }
  80. protected override void AddEventListener()
  81. {
  82. base.AddEventListener();
  83. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
  84. }
  85. protected override void OnHide()
  86. {
  87. base.OnHide();
  88. }
  89. protected override void RemoveEventListener()
  90. {
  91. base.RemoveEventListener();
  92. EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
  93. }
  94. private void OnClickBtnBack()
  95. {
  96. this.Hide();
  97. }
  98. private void OnClickImgBonusBox()
  99. {
  100. SuitUtil.ShowSuitGuideBonus(_suitId);
  101. }
  102. private void OnTimerUpDate(object param = null)
  103. {
  104. touchClick = true;
  105. _dressUpObjUI.UpdateWrapper(_ui.m_holder);
  106. }
  107. private async void UpdateSuitView(bool isPic = true)
  108. {
  109. _actionIsPic = isPic;
  110. SuitCfg suitCfg = CommonDataManager.Tables.TblSuitCfg.GetOrDefault(_suitId);
  111. _ui.m_txtSuitName.text = suitCfg.Name;
  112. if (GameGlobal.ShowPainting)
  113. {
  114. touchClick = true;
  115. _ui.m_loaCard.url = ResPathUtil.GetLiHuiPath(suitCfg.Illustration);
  116. }
  117. else
  118. {
  119. if (_dressUpObjUI != null)
  120. {
  121. _dressUpObjUI.Dispose();
  122. _dressUpObjUI = null;
  123. }
  124. _dressUpObjUI = new DressUpObjUI("SceneDressUp");
  125. // 使用异步方式重置场景对象
  126. _dressUpObjUI.ResetSceneObjAsync(100, false, true, null, false, (sceneObj) =>
  127. {
  128. if (sceneObj != null)
  129. {
  130. //_dressUpObjUI.dressUpObj.SetOnSuitPutOnCompleteCallback(() =>
  131. //{
  132. //_dressUpObjUI.UpdateWrapper(_ui.m_holder);
  133. //UpdateSuitBoxStatus();
  134. //});
  135. // 场景对象加载完成后穿上套装
  136. _dressUpObjUI.dressUpObj.PutOnSuitCfg(
  137. _suitId,
  138. isPic,
  139. new int[] { ConstDressUpItemType.BEI_JING },
  140. true,
  141. false,
  142. false,
  143. (needYooAsseetDown) =>
  144. {
  145. if(needYooAsseetDown)
  146. Timers.inst.Add(4f, 1, OnTimerUpDate);
  147. else
  148. Timers.inst.Add(0.3f, 1, OnTimerUpDate);
  149. }
  150. );
  151. UpdateSuitBoxStatus();
  152. }
  153. else
  154. {
  155. Debug.LogError("Failed to load scene object for suit view");
  156. }
  157. });
  158. }
  159. }
  160. private void UpdateArrows()
  161. {
  162. int index = _suitIds.IndexOf(_suitId);
  163. int count = _suitIds.Count;
  164. _ui.m_btnRight.visible = (index + 1 < count);
  165. _ui.m_btnLeft.visible = (index - 1 >= 0);
  166. }
  167. private void OnClickBtnLeft()
  168. {
  169. if (!touchClick) return;
  170. touchClick = false;
  171. int index = _suitIds.IndexOf(_suitId);
  172. int targetIndex = index - 1;
  173. if (targetIndex >= 0)
  174. {
  175. _suitId = _suitIds[targetIndex];
  176. UpdateArrows();
  177. UpdateSuitView();
  178. }
  179. UpdateSuitBoxStatus();
  180. }
  181. private void OnClickBtnRight()
  182. {
  183. if (!touchClick) return;
  184. touchClick = false;
  185. int index = _suitIds.IndexOf(_suitId);
  186. int targetIndex = index + 1;
  187. if (targetIndex < _suitIds.Count)
  188. {
  189. _suitId = _suitIds[targetIndex];
  190. UpdateArrows();
  191. UpdateSuitView();
  192. }
  193. UpdateSuitBoxStatus();
  194. }
  195. private void UpdateSuitBoxStatus(EventContext eventContext = null)
  196. {
  197. if (eventContext == null || _suitId == (int)eventContext.data)
  198. {
  199. int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(_suitId);
  200. RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, false);
  201. RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, status == ConstBonusStatus.CAN_GET);
  202. if (status == ConstBonusStatus.CAN_GET)
  203. {
  204. _ui.m_imgBonusBox.m_c1.selectedIndex = 1;
  205. }
  206. else
  207. {
  208. _ui.m_imgBonusBox.m_c1.selectedIndex = 0;
  209. }
  210. }
  211. }
  212. }
  213. }