using ET; using FairyGUI; using UI.Field; using UnityEngine; namespace GFGGame { public class FieldView : BaseWindow { private UI_FieldUI _ui; private ValueBarController _valueBarController; private FieldCfg _curCfg; private FieldDataManager _dataManager; private int _selectedIndex = 0; public override void Dispose() { base.Dispose(); _valueBarController.Dispose(); _valueBarController = null; } protected override void OnInit() { base.OnInit(); packageName = UI_FieldUI.PACKAGE_NAME; _ui = UI_FieldUI.Create(); this.viewCom = _ui.target; isfullScreen = true; _ui.m_btnBack.onClick.Add(OnClickBtnBack); _ui.m_btnGo.onClick.Add(OnClickBtnGo); _ui.m_btnTask.onClick.Add(OnBtnTaskClick); _ui.m_c1.onChanged.Add(OnDifficultyChange); _valueBarController = new ValueBarController(_ui.m_comValueBar); EventAgent.AddEventListener(ConstMessage.FIELD_RESULT, UpdateView); EventAgent.AddEventListener(ConstMessage.FIELD_TASK, UpdateView); } protected override void OnShown() { base.OnShown(); _valueBarController.OnShown(); _dataManager = FieldDataManager.Instance; _selectedIndex = _dataManager.difficulty; _ui.m_c1.selectedIndex = _selectedIndex; _curCfg = FieldCfgArray.Instance.dataArray[_selectedIndex]; _dataManager.chapterId = _curCfg.id; FieldCfg[] cfgs = FieldCfgArray.Instance.dataArray; for (int i = 0; i < cfgs.Length; i++) { bool isPass = i == 0 ? true : InstanceZonesDataManager.CheckLevelPass(cfgs[i].storyLvId); _ui.target.GetChild("btn" + i).asButton.GetChild("imgLock").asImage.visible = !isPass; } UpdateView(); Timers.inst.Add(1, 0, UpdateShowTime); } protected override void OnHide() { base.OnHide(); Timers.inst.Remove(UpdateShowTime); } private void OnClickBtnBack() { _dataManager.difficulty = 0; ViewManager.GoBackFrom(typeof(FieldView).FullName); } private void OnDifficultyChange() { int priorIndex = _ui.m_c1.selectedIndex - 1; FieldCfg selectCfg = FieldCfgArray.Instance.dataArray[_ui.m_c1.selectedIndex]; bool isPass = InstanceZonesDataManager.CheckLevelPass(selectCfg.storyLvId); if (priorIndex >= 0 && !isPass) { _ui.m_c1.selectedIndex = _selectedIndex; StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(selectCfg.storyLvId); string str = string.Format("完成主线{0}-{1}解锁", storyLevelCfg.chapterId, storyLevelCfg.order); PromptController.Instance.ShowFloatTextPrompt(str); return; } FieldCfg priorfg = priorIndex >= 0 ? FieldCfgArray.Instance.dataArray[priorIndex] : null; if (priorIndex >= 0 && _dataManager.GetHighestLvByChapterId(priorfg.id) < priorfg.num) { _ui.m_c1.selectedIndex = _selectedIndex; PromptController.Instance.ShowFloatTextPrompt("需通关前置关卡"); return; } _selectedIndex = _ui.m_c1.selectedIndex; _curCfg = FieldCfgArray.Instance.dataArray[_selectedIndex]; ; _dataManager.chapterId = _curCfg.id; _dataManager.difficulty = _selectedIndex; UpdateView(); } private void UpdateView() { _ui.m_txtScore.text = ConstDressUpScoreType.scoreTypeList()[_dataManager.fieldInfos.theme].ToString(); _ui.m_txtMaxLv.text = string.Format("最高记录:{0}/{1}", _dataManager.GetHighestLvByChapterId(_dataManager.chapterId), _curCfg.num); _ui.m_txtConsume.text = string.Format("x{0}", _curCfg.needPower); _ui.m_proTaskReward.max = _dataManager.fieldInfos.bonusMaxLimit; _ui.m_proTaskReward.value = _dataManager.fieldInfos.bonusWeekly; _ui.m_loaTaskReward.url = ResPathUtil.GetIconPath(ItemCfgArray.Instance.GetCfg(ConstItemID.DIAMOND_RED)); } private void UpdateShowTime(object param) { _ui.m_txtTime.text = string.Format("{0}后刷新", TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, TimeUtil.GetNextWeekTime(GlobalCfgArray.globalCfg.refreshTime))); } private void OnClickBtnGo() { if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Power) < _curCfg.needPower) { PromptController.Instance.ShowFloatTextPrompt("体力不足"); return; } if (_dataManager.fieldInfos.bonusWeekly >= _dataManager.fieldInfos.bonusMaxLimit) { Alert.Show("本周可获得奖励已达上限,是否继续挑战?") .SetLeftButton(true) .SetRightButton(true, "确定", (object data) => { StartFight(); }); } else { StartFight(); } } private void StartFight() { int curLevelId = StoryLevelCfgArray.Instance.GetCfgs(_curCfg.type, 0, _curCfg.id)[0].id; ViewManager.Show(ViewName.DRESS_UP_FIGHT_VIEW, curLevelId, new object[] { typeof(FieldView).Name, this.viewData }, true); InstanceZonesDataManager.currentLevelCfgId = curLevelId; } private void OnBtnTaskClick() { ViewManager.Show(); } } }