FieldView.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using ET;
  2. using UI.Field;
  3. using UnityEngine;
  4. namespace GFGGame
  5. {
  6. public class FieldView : BaseWindow
  7. {
  8. private UI_FieldUI _ui;
  9. private ValueBarController _valueBarController;
  10. private FieldCfg _curCfg;
  11. private FieldDataManager _dataManager;
  12. private int _selectedIndex = 0;
  13. public override void Dispose()
  14. {
  15. base.Dispose();
  16. _valueBarController.Dispose();
  17. _valueBarController = null;
  18. }
  19. protected override void OnInit()
  20. {
  21. base.OnInit();
  22. packageName = UI_FieldUI.PACKAGE_NAME;
  23. _ui = UI_FieldUI.Create();
  24. this.viewCom = _ui.target;
  25. isfullScreen = true;
  26. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  27. _ui.m_btnGo.onClick.Add(OnClickBtnGo);
  28. _ui.m_btnTask.onClick.Add(OnBtnTaskClick);
  29. _ui.m_c1.onChanged.Add(OnDifficultyChange);
  30. _valueBarController = new ValueBarController(_ui.m_comValueBar);
  31. // FieldDataManager.Instance.fieldInfos.theme = 1;
  32. // FieldDataManager.Instance.fieldInfos.bonusWeekly = 250;
  33. // FieldDataManager.Instance.fieldInfos.bonusMaxLimit = 800;
  34. // FieldDataManager.Instance.fieldInfos.highestLvls = new System.Collections.Generic.Dictionary<int, int>();
  35. // FieldDataManager.Instance.fieldInfos.taskDic = new System.Collections.Generic.Dictionary<int, int>();
  36. }
  37. protected override void OnShown()
  38. {
  39. base.OnShown();
  40. _valueBarController.OnShown();
  41. _selectedIndex = 0;
  42. _ui.m_c1.selectedIndex = _selectedIndex;
  43. _curCfg = FieldCfgArray.Instance.dataArray[_selectedIndex];
  44. _dataManager = FieldDataManager.Instance;
  45. _dataManager.chapterId = _curCfg.id;
  46. _dataManager.currFightLv = 1;
  47. FieldCfg[] cfgs = FieldCfgArray.Instance.dataArray;
  48. for (int i = 0; i < cfgs.Length; i++)
  49. {
  50. bool isPass = i == 0 ? true : InstanceZonesDataManager.CheckLevelPass(cfgs[i].storyLvId);
  51. _ui.target.GetChild("btn" + i).asButton.GetChild("imgLock").asImage.visible = !isPass;
  52. }
  53. UpdateView();
  54. }
  55. protected override void OnHide()
  56. {
  57. base.OnHide();
  58. }
  59. private void OnClickBtnBack()
  60. {
  61. ViewManager.GoBackFrom(typeof(FieldView).FullName);
  62. }
  63. private void OnDifficultyChange()
  64. {
  65. int priorIndex = _ui.m_c1.selectedIndex - 1;
  66. FieldCfg selectCfg = FieldCfgArray.Instance.dataArray[_ui.m_c1.selectedIndex];
  67. bool isPass = InstanceZonesDataManager.CheckLevelPass(selectCfg.storyLvId);
  68. if (priorIndex >= 0 && !isPass)
  69. {
  70. _ui.m_c1.selectedIndex = _selectedIndex;
  71. StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(selectCfg.storyLvId);
  72. string str = string.Format("完成主线{0}-{1}解锁", storyLevelCfg.chapterId, storyLevelCfg.order);
  73. PromptController.Instance.ShowFloatTextPrompt(str);
  74. return;
  75. }
  76. FieldCfg priorfg = priorIndex >= 0 ? FieldCfgArray.Instance.dataArray[priorIndex] : null;
  77. if (priorIndex >= 0 && _dataManager.GetHighestLvByChapterId(priorfg.id) < priorfg.num)
  78. {
  79. _ui.m_c1.selectedIndex = _selectedIndex;
  80. PromptController.Instance.ShowFloatTextPrompt("需通关前置关卡");
  81. return;
  82. }
  83. _selectedIndex = _ui.m_c1.selectedIndex;
  84. _curCfg = FieldCfgArray.Instance.dataArray[_selectedIndex]; ;
  85. _dataManager.chapterId = _curCfg.id;
  86. UpdateView();
  87. }
  88. private void UpdateView()
  89. {
  90. _ui.m_txtScore.text = ConstDressUpScoreType.scoreTypeList()[_dataManager.fieldInfos.theme].ToString();
  91. _ui.m_txtMaxLv.text = string.Format("最高记录:{0}/{1}", _dataManager.GetHighestLvByChapterId(_dataManager.chapterId), _curCfg.num);
  92. _ui.m_txtConsume.text = string.Format("x{0}", _curCfg.needPower);
  93. _ui.m_proTaskReward.max = _dataManager.fieldInfos.bonusMaxLimit;
  94. _ui.m_proTaskReward.value = _dataManager.fieldInfos.bonusWeekly;
  95. }
  96. private void OnClickBtnGo()
  97. {
  98. if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) < _curCfg.needPower)
  99. {
  100. PromptController.Instance.ShowFloatTextPrompt("体力不足");
  101. return;
  102. }
  103. if (_dataManager.fieldInfos.bonusWeekly >= _dataManager.fieldInfos.bonusMaxLimit)
  104. {
  105. Alert.Show("本周可获得奖励已达上限,是否继续挑战?")
  106. .SetLeftButton(true)
  107. .SetRightButton(true, "确定", (object data) =>
  108. {
  109. StartFight();
  110. });
  111. }
  112. else
  113. {
  114. StartFight();
  115. }
  116. }
  117. private void StartFight()
  118. {
  119. int curLevelId = StoryLevelCfgArray.Instance.GetCfgs(_curCfg.type, 0, _curCfg.id)[0].id;
  120. ViewManager.Show(ViewName.DRESS_UP_FIGHT_VIEW, curLevelId, new object[] { typeof(FieldView).Name, this.viewData }, true);
  121. InstanceZonesDataManager.currentLevelCfgId = curLevelId;
  122. }
  123. private void OnBtnTaskClick()
  124. {
  125. ViewManager.Show<FieldTaskView>();
  126. }
  127. }
  128. }