StroyFightResultView.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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("zd_jsjm_bjtu");
  58. }
  59. protected override void OnShown()
  60. {
  61. base.OnShown();
  62. _resultData = (StoryFightResultData)(this.viewData as object[])[0];
  63. InstanceZonesDataManager.usedRecommend = false;
  64. InstanceZonesDataManager.isResultFighting = true;
  65. _ui.m_ComRoleResult.m_c1.selectedIndex = _resultData.Star;
  66. NTexture nTexture = (this.viewData as object[])[1] as NTexture;
  67. GLoader loaRole = _ui.m_ComRoleResult.m_comRole.m_loaRole;
  68. loaRole.texture = nTexture;
  69. loaRole.alpha = 1;
  70. // loaRole.SetSize(loaRole.width, loaRole.texture.height * loaRole.width / loaRole.texture.width);
  71. _ui.m_comResult.m_c1.selectedIndex = _resultData.Star;
  72. _ui.m_comResult.m_txtScore.text = "" + _resultData.Score;
  73. _ui.m_comExpBar.m_txtLvl.text = string.Format("等级 {0}", GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  74. _levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  75. if (!this._resultData.Result)
  76. {
  77. _ui.m_comExpBar.target.visible = false;
  78. _ui.m_btnClose.enabled = true;
  79. InstanceZonesDataManager.isResultFighting = false;
  80. }
  81. else
  82. {
  83. _ui.m_comExpBar.target.visible = true;
  84. _ui.m_btnClose.enabled = false;
  85. //过关
  86. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(_levelCfg.fightID);
  87. _ui.m_comExpBar.m_txtLvlAdded.text = string.Format("经验值:+{0}", fightCfg.exp);
  88. }
  89. if (_levelCfg.type == ConstInstanceZonesType.Field)
  90. {
  91. _ui.m_comExpBar.target.visible = false;
  92. Timers.inst.Add(3, 1, OnClickBtnClose);
  93. }
  94. _ui.m_t1.Play(AddExp);
  95. // _ui.m_ComRoleResult.m_comRole.m_t1.Play(() =>
  96. // {
  97. // _ui.m_t1.Play(AddExp);
  98. // });
  99. }
  100. protected override void OnHide()
  101. {
  102. base.OnHide();
  103. InstanceZonesDataManager.isResultFighting = false;
  104. // Timers.inst.Remove(AddExp);
  105. if (_sceneObject != null)
  106. {
  107. GameObject.Destroy(_sceneObject);
  108. _sceneObject = null;
  109. }
  110. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  111. Timers.inst.Remove(CheckGuide);
  112. _ui.m_comResult.target.height = 0;
  113. _ui.m_comExpBar.target.alpha = 0;
  114. _ui.m_t1.Stop(true, false);
  115. }
  116. private async void OnClickBtnClose(object param)
  117. {
  118. this.Hide();
  119. if (_levelCfg.type == ConstInstanceZonesType.Field)
  120. {
  121. Timers.inst.Remove(OnClickBtnClose);
  122. if (!this._resultData.Result || FieldDataManager.Instance.currFightLv == FieldCfgArray.Instance.GetCfg(FieldDataManager.Instance.chapterId).num)
  123. {
  124. ViewManager.Show<FieldView>();
  125. if (FieldDataManager.Instance.currFightLv <= 1) return;
  126. bool result = await FieldSProxy.ReqFieldInstanceResult();
  127. if (result)
  128. {
  129. ViewManager.Show<FieldFightEndView>();
  130. }
  131. }
  132. else
  133. {
  134. ViewManager.Show<FieldView>();
  135. ViewManager.Show<FieldFightInfoView>();
  136. }
  137. }
  138. else
  139. {
  140. InstanceZonesController.OnFinishStoryLevel(InstanceZonesDataManager.currentLevelCfgId, _resultData.FirstPass, true);
  141. //尝试显示奖励
  142. BonusController.TryShowBonusList(_resultData.BonusList);
  143. }
  144. InstanceZonesDataManager.currentCardId = -1;
  145. }
  146. private void AddExp()
  147. {
  148. int lv = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  149. _ui.m_comExpBar.m_txtLvl.text = string.Format("等级 {0}", GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  150. float exp = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  151. float cfgExp = RoleLevelCfgArray.Instance.GetCfg(lv).exp;
  152. float initWidth = _ui.m_comExpBar.m_pbExp.m_bar.target.initWidth;
  153. float curWidth = _ui.m_comExpBar.m_pbExp.m_bar.target.width;
  154. float width = exp / cfgExp * initWidth;
  155. if (width <= curWidth)
  156. {
  157. _ui.m_comExpBar.m_pbExp.m_bar.target.width = 0;
  158. }
  159. 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) =>
  160. {
  161. _ui.m_comExpBar.m_pbExp.m_bar.target.width = t.value.x;
  162. }).OnComplete(() =>
  163. {
  164. InstanceZonesDataManager.isResultFighting = false;
  165. }); ;
  166. // _ui.m_expBar.m_pbExp..TweenValue(exp, 0.2f);
  167. _ui.m_btnClose.enabled = true;
  168. UpdateToCheckGuide(null);
  169. Timers.inst.AddUpdate(CheckGuide);
  170. }
  171. private void CheckGuide(object param)
  172. {
  173. if (GuideDataManager.IsGuideFinish(ConstGuideId.FIRST_FIGHT_FAILED) <= 0
  174. || GuideDataManager.IsGuideFinish(ConstGuideId.FIRST_FIGHT_SINGLE_WIN) <= 0
  175. || GuideDataManager.IsGuideFinish(ConstGuideId.FIRST_FIGHT_TARGET_WIN) <= 0)
  176. {
  177. UpdateToCheckGuide(null);
  178. }
  179. else
  180. {
  181. Timers.inst.Remove(CheckGuide);
  182. }
  183. }
  184. protected override void UpdateToCheckGuide(object param)
  185. {
  186. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  187. if (!_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_FAILED, 1, "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!", -1, true, (int)(this.viewCom.height - 150));
  188. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1, "这条连衣裙可真好看!点击空白区域继续。", -1, true, (int)(this.viewCom.height - 400));
  189. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1, "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧。", -1, true, (int)(this.viewCom.height - 400));
  190. }
  191. protected override void TryCompleteGuide()
  192. {
  193. GuideCfg cfg;
  194. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_FAILED);
  195. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  196. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_FAILED, 1);
  197. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_SINGLE_WIN);
  198. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  199. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1);
  200. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_TARGET_WIN);
  201. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  202. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1);
  203. }
  204. }
  205. }