StroyFightResultView.cs 7.0 KB

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