SuitShowView.cs 7.2 KB

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