SuitShowView.cs 6.8 KB

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