SuitShowView.cs 6.2 KB

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