StroyFightResultView.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 StoryLevelCfg _levelCfg;
  26. private StoryFightResultData _resultData;
  27. public override void Dispose()
  28. {
  29. SceneController.DestroyObjectFromView(_gameObject);
  30. SceneController.DestroyObjectFromView(_gameObject1);
  31. if (_sceneObject != null)
  32. {
  33. GameObject.Destroy(_sceneObject);
  34. _sceneObject = null;
  35. }
  36. if (_scenePrefab != null)
  37. {
  38. GFGAsset.Release(ResPathUtil.GetPrefabPath("SceneFightResult"));
  39. _scenePrefab = null;
  40. }
  41. if (_ui != null)
  42. {
  43. _ui.Dispose();
  44. }
  45. _ui = null;
  46. base.Dispose();
  47. }
  48. protected override void Init()
  49. {
  50. base.Init();
  51. _ui = UI_StoryFightResultUI.Create();
  52. viewCom = _ui.target;
  53. isfullScreen = true;
  54. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFightResult"));
  55. }
  56. protected override void OnInit()
  57. {
  58. base.OnInit();
  59. _ui.m_btnClose.enabled = false;
  60. _ui.m_btnClose.onClick.Add(OnClickBtnClose);
  61. string resPath = ResPathUtil.GetViewEffectPath("ui_zhandou", "ui_zd_zdjs_jdt");
  62. SceneController.AddObjectToView(_gameObject1, null, _ui.m_expBar.m_pbExp.m_holder, resPath, out _gameObject1, out GoWrapper wrapper);
  63. }
  64. protected override void OnShown()
  65. {
  66. base.OnShown();
  67. _resultData = (StoryFightResultData)this.viewData;
  68. if (_sceneObject == null)
  69. {
  70. _sceneObject = GameObject.Instantiate(_scenePrefab);
  71. }
  72. InstanceZonesDataManager.usedRecommend = false;
  73. InstanceZonesDataManager.isResultFighting = true;
  74. SceneController.UpdateRole(EquipDataCache.cacher.equipDatas, _sceneObject);
  75. _ui.m_txtScore.text = "" + _resultData.Score;
  76. _ui.m_expBar.m_txtLvl.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  77. StoryUtil.UpdateStar(_resultData.Star, _ui.m_flower.target);
  78. string resPath = ResPathUtil.GetViewEffectPath("ui_zhandou", string.Format("zd_zdjs_{0}", _resultData.Star));
  79. SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_holder, resPath, out _gameObject, out _wrapper, 120);
  80. _ui.m_holder.visible = true;
  81. _gameObject.SetActive(true);
  82. TextFormat tf = _ui.m_txtScore.textFormat;
  83. UpdateToCheckGuide(null);
  84. _ui.m_c1.selectedIndex = 0;
  85. _levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  86. if (_levelCfg.type == ConstInstanceZonesType.Field)
  87. {
  88. _ui.m_c1.selectedIndex = 1;
  89. Timers.inst.Add(3, 1, OnClickBtnClose);
  90. }
  91. if (!this._resultData.Result)
  92. {
  93. tf.font = "ui://Main/Font3";
  94. _ui.m_expBar.m_txtLvlAdded.text = "0";
  95. _ui.m_expBar.target.visible = false;
  96. _ui.m_btnClose.enabled = true;
  97. InstanceZonesDataManager.isResultFighting = false;
  98. }
  99. else
  100. {
  101. tf.font = "ui://Main/Font2";
  102. _ui.m_expBar.target.visible = true;
  103. _ui.m_btnClose.enabled = false;
  104. //过关
  105. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(_levelCfg.fightID);
  106. _ui.m_expBar.m_txtLvlAdded.text = "" + fightCfg.exp;
  107. Timers.inst.Add(0.5f, 1, this.AddExp);
  108. }
  109. _ui.m_txtScore.textFormat = tf;
  110. _ui.m_t0.SetValue("posY", 33, this.viewCom.height - 235);
  111. _ui.m_t0.Play();
  112. Timers.inst.AddUpdate(CheckGuide);
  113. }
  114. protected override void OnHide()
  115. {
  116. base.OnHide();
  117. InstanceZonesDataManager.isResultFighting = false;
  118. Timers.inst.Remove(AddExp);
  119. if (_sceneObject != null)
  120. {
  121. GameObject.Destroy(_sceneObject);
  122. _sceneObject = null;
  123. }
  124. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  125. Timers.inst.Remove(CheckGuide);
  126. }
  127. private async void OnClickBtnClose(object param)
  128. {
  129. this.Hide();
  130. if (_levelCfg.type == ConstInstanceZonesType.Field)
  131. {
  132. _ui.m_c1.selectedIndex = 1;
  133. Timers.inst.Remove(OnClickBtnClose);
  134. if (!this._resultData.Result || FieldDataManager.Instance.currFightLv == FieldCfgArray.Instance.GetCfg(FieldDataManager.Instance.chapterId).num)
  135. {
  136. ViewManager.Show<FieldView>();
  137. if (FieldDataManager.Instance.currFightLv <= 1) return;
  138. bool result = await FieldSProxy.ReqFieldInstanceResult();
  139. if (result)
  140. {
  141. ViewManager.Show<FieldFightEndView>();
  142. }
  143. }
  144. else
  145. {
  146. ViewManager.Show<FieldView>();
  147. ViewManager.Show<FieldFightInfoView>();
  148. }
  149. }
  150. else
  151. {
  152. InstanceZonesController.OnFinishStoryLevel(InstanceZonesDataManager.currentLevelCfgId, _resultData.FirstPass, true);
  153. //尝试显示奖励
  154. BonusController.TryShowBonusList(_resultData.BonusList);
  155. }
  156. InstanceZonesDataManager.currentCardId = -1;
  157. }
  158. private void AddExp(object param)
  159. {
  160. int lv = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  161. _ui.m_expBar.m_txtLvl.text = lv.ToString();
  162. float exp = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  163. float cfgExp = RoleLevelCfgArray.Instance.GetCfg(lv).exp;
  164. float initWidth = _ui.m_expBar.m_pbExp.m_bar.target.initWidth;
  165. float curWidth = _ui.m_expBar.m_pbExp.m_bar.target.width;
  166. float width = exp / cfgExp * initWidth;
  167. if (width <= curWidth)
  168. {
  169. _ui.m_expBar.m_pbExp.m_bar.target.width = 0;
  170. }
  171. GTween.To(_ui.m_expBar.m_pbExp.m_bar.target.width, width, 0.2f).SetTarget(_ui.m_expBar.m_pbExp.m_bar).OnUpdate((GTweener t) =>
  172. {
  173. _ui.m_expBar.m_pbExp.m_bar.target.width = t.value.x;
  174. }).OnComplete(() =>
  175. {
  176. InstanceZonesDataManager.isResultFighting = false;
  177. }); ;
  178. // _ui.m_expBar.m_pbExp..TweenValue(exp, 0.2f);
  179. _ui.m_btnClose.enabled = true;
  180. }
  181. private void CheckGuide(object param)
  182. {
  183. if (GuideDataManager.IsGuideFinish(ConstGuideId.FIRST_FIGHT_FAILED) <= 0
  184. || GuideDataManager.IsGuideFinish(ConstGuideId.FIRST_FIGHT_SINGLE_WIN) <= 0
  185. || GuideDataManager.IsGuideFinish(ConstGuideId.FIRST_FIGHT_TARGET_WIN) <= 0)
  186. {
  187. UpdateToCheckGuide(null);
  188. }
  189. else
  190. {
  191. Timers.inst.Remove(CheckGuide);
  192. }
  193. }
  194. protected override void UpdateToCheckGuide(object param)
  195. {
  196. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  197. if (!_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_FAILED, 1, "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!", -1, true, (int)(this.viewCom.height - 150));
  198. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1, "这条连衣裙可真好看!点击空白区域继续", -1, true, (int)(this.viewCom.height - 400));
  199. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1, "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧", -1, true, (int)(this.viewCom.height - 400));
  200. }
  201. protected override void TryCompleteGuide()
  202. {
  203. GuideCfg cfg;
  204. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_FAILED);
  205. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  206. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_FAILED, 1);
  207. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_SINGLE_WIN);
  208. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  209. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1);
  210. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_TARGET_WIN);
  211. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  212. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1);
  213. }
  214. }
  215. }