StroyFightResultView.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 StoryFightResultData _resultData;
  26. public override void Dispose()
  27. {
  28. SceneController.DestroyObjectFromView(_gameObject);
  29. SceneController.DestroyObjectFromView(_gameObject1);
  30. if (_scenePrefab != null)
  31. {
  32. GameObject.Destroy(_scenePrefab);
  33. _scenePrefab = null;
  34. }
  35. if (_ui != null)
  36. {
  37. _ui.Dispose();
  38. }
  39. _ui = null;
  40. base.Dispose();
  41. }
  42. protected override void Init()
  43. {
  44. base.Init();
  45. _ui = UI_StoryFightResultUI.Create();
  46. viewCom = _ui.target;
  47. isfullScreen = true;
  48. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneFightResult"));
  49. }
  50. protected override void OnInit()
  51. {
  52. base.OnInit();
  53. _ui.m_btnClose.enabled = false;
  54. _ui.m_btnClose.onClick.Add(OnClickBtnClose);
  55. string resPath = ResPathUtil.GetViewEffectPath("ui_zhandou", "ui_zd_zdjs_jdt");
  56. SceneController.AddObjectToView(_gameObject1, null, _ui.m_expBar.m_pbExp.m_holder, resPath, out _gameObject1, out GoWrapper wrapper);
  57. }
  58. protected override void OnShown()
  59. {
  60. base.OnShown();
  61. _resultData = (StoryFightResultData)this.viewData;
  62. // Timers.inst.AddUpdate(UpdateToCheckGuide);
  63. if (_sceneObject == null)
  64. {
  65. _sceneObject = GameObject.Instantiate(_scenePrefab);
  66. }
  67. SceneController.UpdateRole(EquipDataCache.cacher.equipDatas, _sceneObject);
  68. _ui.m_selfScore.m_txtScore.text = "" + _resultData.Score;
  69. _ui.m_expBar.m_txtLvl.text = "" + GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  70. RoleLevelCfg roleLevelCfg = RoleLevelCfgArray.Instance.GetCfg(GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl));
  71. // _ui.m_expBar.m_pbExp.max = roleLevelCfg.exp;
  72. // _ui.m_expBar.m_pbExp.value = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  73. StoryUtil.UpdateStar(_resultData.Star, _ui.m_selfScore.m_flower.target);
  74. string resPath = ResPathUtil.GetViewEffectPath("ui_zhandou", string.Format("zd_zdjs_{0}", _resultData.Star));
  75. SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_selfScore.m_holder, resPath, out _gameObject, out _wrapper, 120);
  76. // _ui.m_selfScore.m_bg.url = "ui://Main/zd_jsjm_jszi_" + _resultData.Star;
  77. TextFormat tf = _ui.m_selfScore.m_txtScore.textFormat;
  78. UpdateToCheckGuide(null);
  79. if (!this._resultData.Result)
  80. {
  81. tf.font = "ui://Main/Font3";
  82. _ui.m_expBar.m_txtLvlAdded.text = "0";
  83. _ui.m_expBar.target.visible = false;
  84. _ui.m_btnClose.enabled = true;
  85. }
  86. else
  87. {
  88. tf.font = "ui://Main/Font2";
  89. _ui.m_expBar.target.visible = true;
  90. _ui.m_btnClose.enabled = false;
  91. //过关
  92. StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(InstanceZonesDataManager.currentLevelCfgId);
  93. StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID);
  94. _ui.m_expBar.m_txtLvlAdded.text = "" + fightCfg.exp;
  95. Timers.inst.Add(0.5f, 1, this.AddExp);
  96. }
  97. _ui.m_selfScore.m_txtScore.textFormat = tf;
  98. _ui.m_t0.SetValue("posY", 33, this.viewCom.height - 235);
  99. _ui.m_t0.Play();
  100. }
  101. protected override void OnHide()
  102. {
  103. base.OnHide();
  104. Timers.inst.Remove(AddExp);
  105. if (_sceneObject != null)
  106. {
  107. GameObject.Destroy(_sceneObject);
  108. _sceneObject = null;
  109. }
  110. }
  111. private void OnClickBtnClose()
  112. {
  113. this.Hide();
  114. InstanceZonesController.OnFinishStoryLevel(InstanceZonesDataManager.currentLevelCfgId, _resultData.FirstPass, true);
  115. //尝试显示奖励
  116. BonusController.TryShowBonusList(_resultData.BonusList);
  117. InstanceZonesDataManager.currentCardId = -1;
  118. }
  119. private void AddExp(object param)
  120. {
  121. int lv = GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl);
  122. _ui.m_expBar.m_txtLvl.text = lv.ToString();
  123. float exp = GameGlobal.myNumericComponent.GetAsInt(NumericType.Exp);
  124. float cfgExp = RoleLevelCfgArray.Instance.GetCfg(lv).exp;
  125. float initWidth = _ui.m_expBar.m_pbExp.m_bar.target.initWidth;
  126. float curWidth = _ui.m_expBar.m_pbExp.m_bar.target.width;
  127. float width = exp / cfgExp * initWidth;
  128. if (width <= curWidth)
  129. {
  130. _ui.m_expBar.m_pbExp.m_bar.target.width = 0;
  131. }
  132. 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) =>
  133. {
  134. _ui.m_expBar.m_pbExp.m_bar.target.width = t.value.x;
  135. }); ;
  136. // _ui.m_expBar.m_pbExp..TweenValue(exp, 0.2f);
  137. _ui.m_btnClose.enabled = true;
  138. }
  139. protected override void UpdateToCheckGuide(object param)
  140. {
  141. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  142. if (!_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_FAILED, 1, "不要气馁呀,可以通过再次挑战已通关的关卡、摘星、绣坊等途径获取更多的物资来提升自己的战斗力哦!", -1, true, (int)(this.viewCom.height - 150));
  143. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1, "这条连衣裙可真好看!点击空白区域继续", -1, true, (int)(this.viewCom.height - 400));
  144. if (_resultData.Result) GuideController.TryGuide(null, ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1, "你太厉害了,初次对战就获得了这么好的战绩,继续加油吧", -1, true, (int)(this.viewCom.height - 400));
  145. }
  146. protected override void TryCompleteGuide()
  147. {
  148. GuideCfg cfg;
  149. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_FAILED);
  150. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  151. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_FAILED, 1);
  152. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_SINGLE_WIN);
  153. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  154. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_SINGLE_WIN, 1);
  155. cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIRST_FIGHT_TARGET_WIN);
  156. GuideController.TryCompleteGuideIndex(cfg.id, 1);
  157. GuideController.TryCompleteGuide(ConstGuideId.FIRST_FIGHT_TARGET_WIN, 1);
  158. }
  159. }
  160. }