SuitShowView.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using UI.FieldGuide;
  2. using FairyGUI;
  3. using UnityEngine;
  4. using System.Collections.Generic;
  5. namespace GFGGame
  6. {
  7. public class SuitShowView : BaseWindow
  8. {
  9. private UI_SuitShowUI _ui;
  10. private int _suitTypeId;
  11. private int _suitId;
  12. private GameObject _scenePrefab;
  13. private GameObject _sceneObject;
  14. private GoWrapper _wrapper;
  15. private DressUpObjDataCache _dressUpObjDataCache;
  16. private bool _actionIsPic;
  17. private List<int> _suitIds;
  18. public override void Dispose()
  19. {
  20. if (_sceneObject != null)
  21. {
  22. GameObject.Destroy(_sceneObject);
  23. _sceneObject = null;
  24. }
  25. if (_wrapper != null)
  26. {
  27. _wrapper.Dispose();
  28. _wrapper = null;
  29. }
  30. if (_dressUpObjDataCache != null)
  31. {
  32. _dressUpObjDataCache.Dispose();
  33. _dressUpObjDataCache = null;
  34. }
  35. if (_ui != null)
  36. {
  37. _ui.Dispose();
  38. _ui = null;
  39. }
  40. base.Dispose();
  41. }
  42. protected override void OnInit()
  43. {
  44. base.OnInit();
  45. _ui = UI_SuitShowUI.Create();
  46. this.viewCom = _ui.target;
  47. isfullScreen = true;
  48. this.clickBlankToClose = false;
  49. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneDressUp"));
  50. _dressUpObjDataCache = new DressUpObjDataCache();
  51. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  52. _ui.m_imgBonusBox.target.onClick.Add(OnClickImgBonusBox);
  53. _ui.m_btnChangeAction.onClick.Add(OnClickBtnChangeAction);
  54. _ui.m_btnLeft.onClick.Add(OnClickBtnLeft);
  55. _ui.m_btnRight.onClick.Add(OnClickBtnRight);
  56. }
  57. protected override void OnShown()
  58. {
  59. base.OnShown();
  60. object[] datas = this.viewData as object[];
  61. _suitTypeId = (int)datas[0];
  62. _suitId = (int)datas[1];
  63. List<int> suitIds = datas[2] as List<int>;
  64. _suitIds = new List<int>();
  65. foreach (int suitId in suitIds)
  66. {
  67. if (DressUpMenuSuitDataManager.CheckHaveSuit(suitId))
  68. {
  69. _suitIds.Add(suitId);
  70. }
  71. }
  72. SuitGuideMenuCfg cfg = SuitGuideMenuCfgArray.Instance.GetCfg(_suitTypeId);
  73. _ui.m_txtTypeName.text = cfg.name;
  74. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjtj_bjbj");
  75. UpdateArrows();
  76. UpdateSuitView();
  77. UpdateSuitBoxStatus();
  78. }
  79. protected override void AddEventListener()
  80. {
  81. base.AddEventListener();
  82. EventAgent.AddEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
  83. }
  84. protected override void OnHide()
  85. {
  86. base.OnHide();
  87. if (_sceneObject != null)
  88. {
  89. GameObject.Destroy(_sceneObject);
  90. _sceneObject = null;
  91. }
  92. }
  93. protected override void RemoveEventListener()
  94. {
  95. base.RemoveEventListener();
  96. EventAgent.RemoveEventListener(ConstMessage.SUIT_BOX_STATUS_CHANGED, UpdateSuitBoxStatus);
  97. }
  98. private void OnClickBtnBack()
  99. {
  100. this.Hide();
  101. }
  102. private void OnClickImgBonusBox()
  103. {
  104. SuitUtil.ShowSuitGuideBonus(_suitId);
  105. }
  106. private void OnClickBtnChangeAction()
  107. {
  108. if (!_ui.m_btnChangeAction.grayed)
  109. {
  110. _actionIsPic = !_actionIsPic;
  111. UpdateSuitView(_actionIsPic);
  112. }
  113. }
  114. private void UpdateSuitView(bool isPic = true)
  115. {
  116. _actionIsPic = isPic;
  117. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_suitId);
  118. _ui.m_txtSuitName.text = suitCfg.name;
  119. if (_sceneObject != null)
  120. {
  121. GameObject.Destroy(_sceneObject);
  122. _sceneObject = null;
  123. }
  124. _sceneObject = GameObject.Instantiate(_scenePrefab);
  125. int scale = 100;
  126. _sceneObject.transform.localScale = new Vector3(scale, scale, scale);
  127. _dressUpObjDataCache.setSceneObj(_sceneObject);
  128. _dressUpObjDataCache.PutOnDefaultSuitSaved(false);
  129. _dressUpObjDataCache.PutOnSuitCfg(_suitId, isPic, false, new int[] { ConstDressUpItemType.BEI_JING });
  130. if (_wrapper == null)
  131. {
  132. _wrapper = new GoWrapper(_sceneObject);
  133. _ui.m_holder.SetNativeObject(_wrapper);
  134. }
  135. else
  136. {
  137. _wrapper.wrapTarget = _sceneObject;
  138. }
  139. _ui.m_btnChangeAction.grayed = !_dressUpObjDataCache.HasSuitPicRes;
  140. UpdateSuitBoxStatus();
  141. }
  142. private void UpdateArrows()
  143. {
  144. int index = _suitIds.IndexOf(_suitId);
  145. int count = _suitIds.Count;
  146. _ui.m_btnRight.visible = (index + 1 < count);
  147. _ui.m_btnLeft.visible = (index - 1 >= 0);
  148. }
  149. private void OnClickBtnLeft()
  150. {
  151. int index = _suitIds.IndexOf(_suitId);
  152. int targetIndex = index - 1;
  153. if (targetIndex >= 0)
  154. {
  155. _suitId = _suitIds[targetIndex];
  156. UpdateArrows();
  157. UpdateSuitView();
  158. }
  159. UpdateSuitBoxStatus();
  160. }
  161. private void OnClickBtnRight()
  162. {
  163. int index = _suitIds.IndexOf(_suitId);
  164. int targetIndex = index + 1;
  165. if (targetIndex < _suitIds.Count)
  166. {
  167. _suitId = _suitIds[targetIndex];
  168. UpdateArrows();
  169. UpdateSuitView();
  170. }
  171. UpdateSuitBoxStatus();
  172. }
  173. private void UpdateSuitBoxStatus(EventContext eventContext = null)
  174. {
  175. if (eventContext == null || _suitId == (int)eventContext.data)
  176. {
  177. int status = DressUpMenuSuitDataManager.GetSuitGuideBonusStatus(_suitId);
  178. RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, false);
  179. RedDotController.Instance.SetComRedDot(_ui.m_imgBonusBox.target, status == ConstBonusStatus.CAN_GET);
  180. if (status == ConstBonusStatus.CAN_GET)
  181. {
  182. _ui.m_imgBonusBox.m_c1.selectedIndex = 1;
  183. }
  184. else
  185. {
  186. _ui.m_imgBonusBox.m_c1.selectedIndex = 0;
  187. }
  188. }
  189. }
  190. }
  191. }