StroyFightResultView.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. _ui.m_btnClose.enabled = true;
  64. InstanceZonesDataManager.isResultFighting = false;
  65. }
  66. else
  67. {
  68. _ui.m_comExpBar.target.visible = true;
  69. _ui.m_btnClose.enabled = false;
  70. //过关
  71. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(_levelCfg.fightID);
  72. _ui.m_comExpBar.m_txtLvlAdded.text = string.Format("经验值:+{0}", fightCfg.exp);
  73. }
  74. if (_levelCfg.type == ConstInstanceZonesType.Field)
  75. {
  76. _ui.m_comExpBar.target.visible = false;
  77. Timers.inst.Add(3, 1, OnClickBtnClose);
  78. }
  79. GetCurStar(out Transition transition);
  80. _ui.m_t0.Play();//播放重置动画
  81. _ui.m_comRoleResult.m_t0.Play();//播放重置动画
  82. _ui.m_comRoleResult.m_comRole.m_t0.Play(() =>
  83. {
  84. transition.Play(() =>
  85. {
  86. _ui.m_t1.Play(AddExp);
  87. });
  88. });
  89. }
  90. private void GetCurStar(out Transition transition)
  91. {
  92. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  93. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  94. transition = _ui.m_comRoleResult.m_t0;
  95. if (_resultData.Star == 1)
  96. {
  97. transition = _ui.m_comRoleResult.m_t1;
  98. }
  99. else if (_resultData.Star == 2)
  100. {
  101. transition = _ui.m_comRoleResult.m_t2;
  102. }
  103. else if (_resultData.Star == 3)
  104. {
  105. transition = _ui.m_comRoleResult.m_t3;
  106. }
  107. }
  108. protected override void OnHide()
  109. {
  110. base.OnHide();
  111. InstanceZonesDataManager.isResultFighting = false;
  112. // Timers.inst.Remove(AddExp);
  113. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  114. _ui.m_comResult.target.height = 0;
  115. _ui.m_comExpBar.target.alpha = 0;
  116. _ui.m_t1.Stop(true, false);
  117. }
  118. private async void OnClickBtnClose(object param)
  119. {
  120. this.Hide();
  121. if (_levelCfg.type == ConstInstanceZonesType.Field)
  122. {
  123. Timers.inst.Remove(OnClickBtnClose);
  124. if (!this._resultData.Result || FieldDataManager.Instance.currFightLv == FieldCfgArray.Instance.GetCfg(FieldDataManager.Instance.chapterId).num)
  125. {
  126. ViewManager.Show<FieldView>();
  127. if (FieldDataManager.Instance.currFightLv <= 1) return;
  128. bool result = await FieldSProxy.ReqFieldInstanceResult();
  129. if (result)
  130. {
  131. ViewManager.Show<FieldFightEndView>();
  132. }
  133. }
  134. else
  135. {
  136. ViewManager.Show<FieldView>();
  137. ViewManager.Show<FieldFightInfoView>();
  138. }
  139. }
  140. else
  141. {
  142. InstanceZonesController.OnFinishStoryLevel(InstanceZonesDataManager.currentLevelCfgId, _resultData.FirstPass, true);
  143. //尝试显示奖励
  144. BonusController.TryShowBonusList(_resultData.BonusList);
  145. }
  146. InstanceZonesDataManager.currentCardId = -1;
  147. }
  148. private void AddExp()
  149. {
  150. int lv = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  151. _ui.m_comExpBar.m_txtLvl.text = string.Format("等级 {0}", GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  152. float exp = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  153. float cfgExp = RoleLevelCfgArray.Instance.GetCfg(lv).exp;
  154. _ui.m_comExpBar.m_pbExp.m_title.text = string.Format("{0}/{1}", exp, cfgExp);
  155. float initWidth = _ui.m_comExpBar.m_pbExp.m_bar.target.initWidth;
  156. float curWidth = _ui.m_comExpBar.m_pbExp.m_bar.target.width;
  157. float width = exp / cfgExp * initWidth;
  158. if (width <= curWidth)
  159. {
  160. _ui.m_comExpBar.m_pbExp.m_bar.target.width = 0;
  161. }
  162. 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) =>
  163. {
  164. _ui.m_comExpBar.m_pbExp.m_bar.target.width = t.value.x;
  165. }).OnComplete(() =>
  166. {
  167. InstanceZonesDataManager.isResultFighting = false;
  168. }); ;
  169. // _ui.m_expBar.m_pbExp..TweenValue(exp, 0.2f);
  170. _ui.m_btnClose.enabled = true;
  171. UpdateToCheckGuide(null);
  172. }
  173. }
  174. }