FieldFightInfoView.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using cfg.GfgCfg;
  2. using FairyGUI;
  3. using UI.Field;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class FieldFightInfoView : BaseWindow
  8. {
  9. private UI_FieldFightInfoUI _ui;
  10. // private StoryLevelCfg _storyLevelCfg;
  11. // private StoryFightCfg _storyFightCfg;
  12. private int _time = 3;
  13. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. _ui = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. _ui = UI_FieldFightInfoUI.Create();
  26. this.viewCom = _ui.target;
  27. this.viewCom.Center();
  28. this.modal = true;
  29. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  30. this.clickBlankToClose = false;
  31. _ui.m_btnStop.onClick.Add(OnBtnStopClick);
  32. }
  33. protected override void OnShown()
  34. {
  35. base.OnShown();
  36. _time = 3;
  37. UpdateView();
  38. }
  39. private void UpdateView()
  40. {
  41. FieldDataManager dataManager = FieldDataManager.Instance;
  42. FieldCfg fieldCfg = CommonDataManager.Tables.TblFieldCfg.GetOrDefault(dataManager.chapterId);
  43. StoryLevelCfg storyLevelCfg = StoryLevelConfigManager.GetConfigs(fieldCfg.Type, 0, fieldCfg.Id)[dataManager.currFightLv];
  44. StoryFightCfg storyFightCfg = CommonDataManager.Tables.TblStoryFightCfg.GetOrDefault(int.Parse(storyLevelCfg.FightID));
  45. dataManager.currFightLv++;
  46. FieldFightDataManager.Instance.currentLevelCfgId = storyLevelCfg.Id;
  47. _ui.m_txtName.text = storyFightCfg.TargetName;
  48. _ui.m_txtDesc.text = storyLevelCfg.Desc;
  49. string num = StringUtil.GetColorText(string.Format("{0}/{1}", dataManager.currFightLv, fieldCfg.Num), "#BB674E");
  50. _ui.m_txtNum.text = string.Format("第{0}轮", num);
  51. _ui.m_loaNpc.url = ResPathUtil.GetNpcHeadPath(storyFightCfg.TargetRes);
  52. _ui.m_txtTime.text = string.Format("{0}秒后自动进入下一轮", _time);
  53. Timers.inst.Add(1, _time, OnTimerUpdate, 1);
  54. }
  55. private void OnTimerUpdate(object param)
  56. {
  57. _time -= (int)param;
  58. if (_time == 0)
  59. {
  60. Timers.inst.Remove(OnTimerUpdate);
  61. InstanceZonesDataManager.currentCardId = FieldFightDataManager.Instance.CurrentCardId;
  62. InstanceZonesDataManager.currentScoreType = FieldFightDataManager.Instance.CurrentScoreType;
  63. InstanceZonesDataManager.currentLevelCfgId = FieldFightDataManager.Instance.currentLevelCfgId;
  64. ViewManager.Show<StoryFightTargetView>(null,true);
  65. this.Hide();
  66. }
  67. _ui.m_txtTime.text = string.Format("{0}秒后自动进入下一轮", _time);
  68. }
  69. private void OnBtnStopClick()
  70. {
  71. Timers.inst.Remove(OnTimerUpdate);
  72. AlertUI.Show("确认中止本轮挑战?")
  73. .SetLeftButton(true, "取消", (object data) =>
  74. {
  75. Timers.inst.Add(1, _time, OnTimerUpdate, 1);
  76. })
  77. .SetRightButton(true, "中止", async (object data) =>
  78. {
  79. this.Hide();
  80. bool result = await FieldSProxy.ReqFieldInstanceResult();
  81. if (result)
  82. {
  83. FieldDataManager.Instance.accumulateReward = 0;
  84. ViewManager.Show<FieldFightEndView>();
  85. }
  86. });
  87. }
  88. protected override void OnHide()
  89. {
  90. base.OnHide();
  91. }
  92. }
  93. }