SuitShowView.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 (_dressUpObjUI != null)
  113. {
  114. _dressUpObjUI.Dispose();
  115. _dressUpObjUI = null;
  116. }
  117. _dressUpObjUI = new DressUpObjUI("SceneDressUp");
  118. // 使用异步方式重置场景对象
  119. _dressUpObjUI.ResetSceneObjAsync(100, false, true, null, false, (sceneObj) =>
  120. {
  121. if (sceneObj != null)
  122. {
  123. //_dressUpObjUI.dressUpObj.SetOnSuitPutOnCompleteCallback(() =>
  124. //{
  125. //_dressUpObjUI.UpdateWrapper(_ui.m_holder);
  126. //UpdateSuitBoxStatus();
  127. //});
  128. // 场景对象加载完成后穿上套装
  129. _dressUpObjUI.dressUpObj.PutOnSuitCfg(
  130. _suitId,
  131. isPic,
  132. new int[] { ConstDressUpItemType.BEI_JING },
  133. true,
  134. false,
  135. false,
  136. (needYooAsseetDown) =>
  137. {
  138. if(needYooAsseetDown)
  139. Timers.inst.Add(4f, 1, OnTimerUpDate);
  140. else
  141. Timers.inst.Add(0.3f, 1, OnTimerUpDate);
  142. }
  143. );
  144. UpdateSuitBoxStatus();
  145. }
  146. else
  147. {
  148. Debug.LogError("Failed to load scene object for suit view");
  149. }
  150. });
  151. }
  152. private void UpdateArrows()
  153. {
  154. int index = _suitIds.IndexOf(_suitId);
  155. int count = _suitIds.Count;
  156. _ui.m_btnRight.visible = (index + 1 < count);
  157. _ui.m_btnLeft.visible = (index - 1 >= 0);
  158. }
  159. private void OnClickBtnLeft()
  160. {
  161. if (!touchClick) return;
  162. touchClick = false;
  163. int index = _suitIds.IndexOf(_suitId);
  164. int targetIndex = index - 1;
  165. if (targetIndex >= 0)
  166. {
  167. _suitId = _suitIds[targetIndex];
  168. UpdateArrows();
  169. UpdateSuitView();
  170. }
  171. UpdateSuitBoxStatus();
  172. }
  173. private void OnClickBtnRight()
  174. {
  175. if (!touchClick) return;
  176. touchClick = false;
  177. int index = _suitIds.IndexOf(_suitId);
  178. int targetIndex = index + 1;
  179. if (targetIndex < _suitIds.Count)
  180. {
  181. _suitId = _suitIds[targetIndex];
  182. UpdateArrows();
  183. UpdateSuitView();
  184. }
  185. UpdateSuitBoxStatus();
  186. }
  187. private void UpdateSuitBoxStatus(EventContext eventContext = null)
  188. {
  189. if (eventContext == null || _suitId == (int)eventContext.data)
  190. {
  191. int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(_suitId);
  192. RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, false);
  193. RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, status == ConstBonusStatus.CAN_GET);
  194. if (status == ConstBonusStatus.CAN_GET)
  195. {
  196. _ui.m_imgBonusBox.m_c1.selectedIndex = 1;
  197. }
  198. else
  199. {
  200. _ui.m_imgBonusBox.m_c1.selectedIndex = 0;
  201. }
  202. }
  203. }
  204. }
  205. }