StroyFightResultView.cs 9.6 KB

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