StroyFightResultView.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using FairyGUI;
  2. using UnityEngine;
  3. using UI.Main;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using ET;
  7. namespace GFGGame
  8. {
  9. public struct StoryFightResultData
  10. {
  11. public bool Result;
  12. public int Score;
  13. public int Star;
  14. public bool FirstPass;
  15. public List<ItemData> BonusList;
  16. }
  17. public class StroyFightResultView : BaseView
  18. {
  19. private UI_StoryFightResultUI _ui;
  20. private GameObject _sceneObject;
  21. private GameObject _scenePrefab;
  22. private GameObject _gameObject;
  23. private GameObject _gameObject1;
  24. private GoWrapper _wrapper;
  25. private GoWrapper _wrapper1;
  26. private StoryLevelCfg _levelCfg;
  27. private StoryFightResultData _resultData;
  28. public override void Dispose()
  29. {
  30. SceneController.DestroyObjectFromView(_gameObject, _wrapper);
  31. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  32. if (_sceneObject != null)
  33. {
  34. GameObject.Destroy(_sceneObject);
  35. _sceneObject = null;
  36. }
  37. if (_ui != null)
  38. {
  39. _ui.Dispose();
  40. }
  41. _ui = null;
  42. base.Dispose();
  43. }
  44. protected override void Init()
  45. {
  46. base.Init();
  47. _ui = UI_StoryFightResultUI.Create();
  48. viewCom = _ui.target;
  49. isfullScreen = true;
  50. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFightResult"));
  51. }
  52. protected override void OnInit()
  53. {
  54. base.OnInit();
  55. _ui.m_btnClose.enabled = false;
  56. _ui.m_btnClose.onClick.Add(OnClickBtnClose);
  57. _ui.m_loaBg.url = ResPathUtil.GetFightBgImgPath("fightBg");
  58. }
  59. protected override void OnShown()
  60. {
  61. base.OnShown();
  62. _resultData = (StoryFightResultData)this.viewData;
  63. InstanceZonesDataManager.usedRecommend = false;
  64. InstanceZonesDataManager.isResultFighting = true;
  65. NTexture nTexture = new NTexture(EquipDataCache.cacher.RoleTextuex);
  66. _ui.m_comRoleResult.m_c1.selectedIndex = _resultData.Star;
  67. _ui.m_comRoleResult.m_comRole.m_imgRole.SetSize(GRoot.inst.width, GRoot.inst.height);
  68. _ui.m_comRoleResult.m_comRole.m_imgRole.texture = nTexture;
  69. _ui.m_comRoleResult.m_comRole.m_imgRole.alpha = 1;
  70. _ui.m_comResult.m_c1.selectedIndex = _resultData.Star;
  71. _ui.m_comResult.m_txtScore.text = "" + _resultData.Score;
  72. _ui.m_comExpBar.m_txtLvl.text = string.Format("等级 {0}", GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  73. _levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  74. if (!this._resultData.Result)
  75. {
  76. _ui.m_comExpBar.target.visible = false;
  77. _ui.m_btnClose.enabled = true;
  78. InstanceZonesDataManager.isResultFighting = false;
  79. }
  80. else
  81. {
  82. _ui.m_comExpBar.target.visible = true;
  83. _ui.m_btnClose.enabled = false;
  84. //过关
  85. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(_levelCfg.fightID);
  86. _ui.m_comExpBar.m_txtLvlAdded.text = string.Format("经验值:+{0}", fightCfg.exp);
  87. }
  88. if (_levelCfg.type == ConstInstanceZonesType.Field)
  89. {
  90. _ui.m_comExpBar.target.visible = false;
  91. Timers.inst.Add(3, 1, OnClickBtnClose);
  92. }
  93. GetCurStar(out Transition transition);
  94. _ui.m_t0.Play();//播放重置动画
  95. _ui.m_comRoleResult.m_t0.Play();//播放重置动画
  96. _ui.m_comRoleResult.m_comRole.m_t0.Play(() =>
  97. {
  98. transition.Play(() =>
  99. {
  100. _ui.m_t1.Play(AddExp);
  101. });
  102. });
  103. }
  104. private void GetCurStar(out Transition transition)
  105. {
  106. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  107. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  108. transition = _ui.m_comRoleResult.m_t0;
  109. if (_resultData.Star == 1)
  110. {
  111. transition = _ui.m_comRoleResult.m_t1;
  112. }
  113. else if (_resultData.Star == 2)
  114. {
  115. transition = _ui.m_comRoleResult.m_t2;
  116. }
  117. else if (_resultData.Star == 3)
  118. {
  119. transition = _ui.m_comRoleResult.m_t3;
  120. }
  121. }
  122. protected override void OnHide()
  123. {
  124. base.OnHide();
  125. InstanceZonesDataManager.isResultFighting = false;
  126. // Timers.inst.Remove(AddExp);
  127. if (_sceneObject != null)
  128. {
  129. GameObject.Destroy(_sceneObject);
  130. _sceneObject = null;
  131. }
  132. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  133. _ui.m_comResult.target.height = 0;
  134. _ui.m_comExpBar.target.alpha = 0;
  135. _ui.m_t1.Stop(true, false);
  136. }
  137. private async void OnClickBtnClose(object param)
  138. {
  139. this.Hide();
  140. if (_levelCfg.type == ConstInstanceZonesType.Field)
  141. {
  142. Timers.inst.Remove(OnClickBtnClose);
  143. if (!this._resultData.Result || FieldDataManager.Instance.currFightLv == FieldCfgArray.Instance.GetCfg(FieldDataManager.Instance.chapterId).num)
  144. {
  145. ViewManager.Show<FieldView>();
  146. if (FieldDataManager.Instance.currFightLv <= 1) return;
  147. bool result = await FieldSProxy.ReqFieldInstanceResult();
  148. if (result)
  149. {
  150. ViewManager.Show<FieldFightEndView>();
  151. }
  152. }
  153. else
  154. {
  155. ViewManager.Show<FieldView>();
  156. ViewManager.Show<FieldFightInfoView>();
  157. }
  158. }
  159. else
  160. {
  161. InstanceZonesController.OnFinishStoryLevel(InstanceZonesDataManager.currentLevelCfgId, _resultData.FirstPass, true);
  162. //尝试显示奖励
  163. BonusController.TryShowBonusList(_resultData.BonusList);
  164. }
  165. InstanceZonesDataManager.currentCardId = -1;
  166. }
  167. private void AddExp()
  168. {
  169. int lv = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  170. _ui.m_comExpBar.m_txtLvl.text = string.Format("等级 {0}", GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  171. float exp = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  172. float cfgExp = RoleLevelCfgArray.Instance.GetCfg(lv).exp;
  173. float initWidth = _ui.m_comExpBar.m_pbExp.m_bar.target.initWidth;
  174. float curWidth = _ui.m_comExpBar.m_pbExp.m_bar.target.width;
  175. float width = exp / cfgExp * initWidth;
  176. if (width <= curWidth)
  177. {
  178. _ui.m_comExpBar.m_pbExp.m_bar.target.width = 0;
  179. }
  180. GTween.To(_ui.m_comExpBar.m_pbExp.m_bar.target.width, width, 0.2f).SetTarget(_ui.m_comExpBar.m_pbExp.m_bar).OnUpdate((GTweener t) =>
  181. {
  182. _ui.m_comExpBar.m_pbExp.m_bar.target.width = t.value.x;
  183. }).OnComplete(() =>
  184. {
  185. InstanceZonesDataManager.isResultFighting = false;
  186. }); ;
  187. // _ui.m_expBar.m_pbExp..TweenValue(exp, 0.2f);
  188. _ui.m_btnClose.enabled = true;
  189. UpdateToCheckGuide(null);
  190. }
  191. }
  192. }