using FairyGUI; using UI.Main; using System.Collections.Generic; using UI.CommonGame; using System; namespace GFGGame { public class StoryLevelInfoView : BaseWindow { private UI_StoryLevelInfoUI _ui; private int _fightID; private int _levelID; private int _storyType; private List _bonusList = new List(); private int _fightTimes; private const int _timeCount = 10; protected override void OnInit() { base.OnInit(); _ui = UI_StoryLevelInfoUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; viewAnimationType = EnumViewAnimationType.ZOOM_CENTER; _ui.m_listBonus.itemRenderer = UpdateBonusItem; // _ui.m_listBonus.onClickItem.Add(OnClickListBonusItem); _ui.m_btnStart.onClick.Add(OnClickBtnStart); _ui.m_btnFightOnce.onClick.Add(OnClickBtnFightOnce); _ui.m_btnFightTimes.onClick.Add(OnClickBtnFightTimes); // _ui.m_btnClose.onClick.Add(() => // { // this.Hide(); // }); _ui.m_listTag.itemRenderer = RenderListTagItem; } protected override void OnShown() { base.OnShown(); _levelID = (int)viewData; StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID); _storyType = levelCfg.subType; _ui.m_btnStart.touchable = true; UpdateView(); EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes); } protected override void OnHide() { base.OnHide(); EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateBtnFightTimes); } private void OnClickBtnStart() { int time = StoryDataManager.GetCanFightTime(_levelID); if (time > 0) { ViewManager.Show(ViewName.DRESS_UP_FIGHT_VIEW, _levelID, null, true); } else { ItemUtil.AddPower("体力不足", OnClickBtnStart); } } private void OnClickBtnFightOnce() { int time = StoryDataManager.GetCanFightTime(_levelID); if (time > 0) { ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, 1); } else { ItemUtil.AddPower("体力不足", OnClickBtnFightOnce); } } private void OnClickBtnFightTimes() { if (_storyType == ConstInstanceZonesSubType.Normal) { if (_fightTimes < _timeCount) { ItemUtil.AddPower("体力不足", OnClickBtnFightTimes); } else { ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, _fightTimes); } } else if (_storyType == ConstInstanceZonesSubType.Hard) { ViewManager.Show(ViewName.STORY_FIGHT_QUICKLY_VIEW, _fightTimes); } } private void UpdateBonusItem(int index, GObject item) { ItemData itemData = _bonusList[index] as ItemData; UI_ComItem listItem = UI_ComItem.Proxy(item); if (item.data == null) { item.data = new ItemView(item as GComponent); } (item.data as ItemView).SetData(itemData); List bonusOnceData = StoryBonusDataCache.GetBonusData(_levelID).bonusOnce; (item.data as ItemView).LoaShouTongRewardVisble = !StoryDataManager.CheckCurrentLevelPass() && index < bonusOnceData.Count; } private void UpdateBtnFightTimes() { if (_ui.m_groupPass.visible) { int time = StoryDataManager.GetCanFightTime(_levelID); time = Math.Min(GameConst.MAX_COUNT_FIGHT_QUICKLY, time); if (_storyType == ConstInstanceZonesSubType.Normal) { _ui.m_btnFightTimes.visible = true; _fightTimes = time; _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText(_timeCount) + "次"; } else if (_storyType == ConstInstanceZonesSubType.Hard) { _ui.m_btnFightTimes.visible = time > 0; if (_ui.m_btnFightTimes.visible) { _fightTimes = time; _ui.m_btnFightTimes.text = "挑战" + NumberUtil.GetChiniseNumberText(time) + "次"; } } } } private void UpdateView() { StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID); StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID); _ui.m_txtTitle.text = StoryDataManager.CurrentChapterOrder + "-" + StoryDataManager.currentLevelOrder + " " + levelCfg.name; _ui.m_txtLevelDesc.text = levelCfg.desc; _ui.m_txtPowerDesc.SetVar("power", "" + levelCfg.power).FlushVars(); _ui.m_scoreType.url = "ui://CommonGame/kp_sx_" + fightCfg.scoreType; if (fightCfg.targetName != null && fightCfg.targetName.Length > 0) { _ui.m_txtTargetName.text = "挑战对手 : " + fightCfg.targetName; _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath(fightCfg.targetRes); } else { _ui.m_txtTargetName.text = RoleDataManager.roleName; _ui.m_loaderHead.url = ResPathUtil.GetNpcHeadPath("self"); } _bonusList.Clear(); if (StoryDataManager.CheckCurrentLevelPass()) { _bonusList = StoryBonusDataCache.GetBonusList(_levelID, false); _ui.m_groupPass.visible = true; _ui.m_groupUnpass.visible = false; UpdateBtnFightTimes(); } else { _bonusList = StoryBonusDataCache.GetBonusList(_levelID, true); _ui.m_groupPass.visible = false; _ui.m_groupUnpass.visible = true; _ui.m_txtUnpassTips.SetVar("count", NumberUtil.GetChiniseNumberText(fightCfg.quickFightStart)).FlushVars(); } _ui.m_listBonus.numItems = _bonusList.Count; if (_ui.m_listBonus.numItems > 4) { _ui.m_listBonus.columnGap = 40; } else { _ui.m_listBonus.columnGap = 60; } int score = StoryDataManager.GetScoreHighest(_levelID); if (score > 0) { string scoreStr = "" + score; if (score <= fightCfg.score1) { scoreStr = "[color=#A28D77]失败 " + scoreStr + "[/color]"; } _ui.m_txtHighestScore.text = scoreStr; _ui.m_flower.target.visible = true; int starCount = StoryDataManager.GetStarCountHistory(_levelID); StoryUtil.UpdateStar(starCount, _ui.m_flower.target); } else { _ui.m_txtHighestScore.text = "--"; _ui.m_flower.target.visible = false; } _ui.m_ctrlNeed.selectedIndex = 0; if (fightCfg.needItemId != 0) { _ui.m_ctrlNeed.selectedIndex = 1; ItemCfg cfg = ItemCfgArray.Instance.GetCfg(fightCfg.needItemId); _ui.m_txtNeed.text = cfg.name; } else if (fightCfg.needSuitId != 0) { _ui.m_ctrlNeed.selectedIndex = 1; SuitCfg cfg = SuitCfgArray.Instance.GetCfg(fightCfg.needSuitId); _ui.m_txtNeed.text = cfg.name; } else if (fightCfg.needTagsArr.Length > 0) { _ui.m_ctrlNeed.selectedIndex = 2; _ui.m_listTag.numItems = fightCfg.needTagsArr.Length; } } private void RenderListTagItem(int index, GObject obj) { UI_ListTagItem item = UI_ListTagItem.Proxy(obj); StoryLevelCfg levelCfg = StoryLevelCfgArray.Instance.GetCfg(_levelID); StoryFightCfg fightCfg = StoryFightCfgArray.Instance.GetCfg(levelCfg.fightID); string[] tag = fightCfg.needTagsArr[index].Split('_'); item.m_loaTag.url = ResPathUtil.GetCommonGameResPath("fzd_bqbq_" + tag[0]); item.m_txtTag.text = tag[1]; } protected override void UpdateToCheckGuide(object param) { if (!ViewManager.CheckIsTopView(this.viewCom)) return; GuideController.TryGuide(_ui.m_btnStart, ConstGuideId.SINGLE_FIGHT, 2, "点击开启换装"); if (GuideController.TryGuide(_ui.m_txtNeed, ConstGuideId.CLOTHING_SYNTHETIC, 2, "这次必需品,要通过合成获得")) { _ui.m_btnStart.touchable = false; } GuideController.TryGuide(null, ConstGuideId.CLOTHING_SYNTHETIC, 3, "点击空白处关闭", false, 0, true, false, (int)(this.viewCom.y + _ui.m_groupPass.y)); GuideController.TryGuide(_ui.m_listTag, ConstGuideId.OPEN_TAGS, 1, "选择相应的关卡标签,可提高分数", false, 0, true, false, 0); GuideController.TryCompleteGuide(ConstGuideId.OPEN_TAGS, 1); } protected override void TryCompleteGuide() { GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.CLOTHING_SYNTHETIC); GuideController.TryCompleteGuideIndex(cfg.id, 3); } } }