SuitShowView.cs 6.5 KB

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