SuitShowView.cs 6.8 KB

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