SuitShowView.cs 6.4 KB

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