using FairyGUI; using UI.CommonGame; using UI.Main; using System.Collections.Generic; using UnityEngine; using System.Collections; using ET; namespace GFGGame { public class ActivityStoryChapterView : BaseWindow { private UI_ActivityStoryChapterUI _ui; private int _chapterID; private int _activityID; private ActivityOpenCfg _activityCfg; private GComponent _compChapter; private ValueBarController _valueBarController; private GObject _unPasslevelItem; private GObject _endLevelItem; private EffectUI _effectUI1; private EffectUI _effectUI2; private EffectUI _effectUI3; private EffectUI _effectUI4; private GComponent _comEff; private GComponent _effFirst; //当前章节索引 private int newIndex; //y轴移动索引 private float indexY; private GameObject gamey; //特效类型数组,这里后面可以二维数组,放向左和向右的 private string[] effArray = new string[2] { "ZJ_JuQing", "ZJ_ZD" }; private int currentDifficulty; public override void Dispose() { EffectUIPool.Recycle(_effectUI1); _effectUI1 = null; EffectUIPool.Recycle(_effectUI2); _effectUI2 = null; EffectUIPool.Recycle(_effectUI3); _effectUI3 = null; EffectUIPool.Recycle(_effectUI4); _effectUI4 = null; if (_comEff != null) { _comEff.RemoveFromParent(); _comEff.Dispose(); } if (_effFirst != null) { _effFirst.RemoveFromParent(); _effFirst.Dispose(); } if (_valueBarController != null) { _valueBarController.Dispose(); _valueBarController = null; } if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void Init() { base.Init(); _ui = UI_ActivityStoryChapterUI.Create(); viewCom = _ui.target; isfullScreen = true; isReturnView = true; } protected override void OnInit() { base.OnInit(); _valueBarController = new ValueBarController(_ui.m_valueBar); _ui.m_btnBack.onClick.Add(OnClickBtnBack); _ui.m_chapter.m_compChapterScroll.m_imgBegin.onClick.Add(OnClickNext); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zxian_bg3"); _effFirst = new GComponent(); _effFirst = UIPackage.CreateObject(UI_MainUI.PACKAGE_NAME, "ComEff").asCom; _effectUI3 = EffectUIPool.CreateEffectUI(_ui.m_bgEffect, "ui_zj", "ZX_BG_TX"); _effectUI4 = EffectUIPool.CreateEffectUI(_ui.m_chapter.m_compChapterScroll.m_nextEffect, "ui_zj", "ZX_Next_Boat"); } protected override void OnShown() { base.OnShown(); GRoot.inst.touchable = false; SuitFosterProxy.SendGetSuitInfos().Coroutine(); MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT)); _activityID = (int)viewData; _activityCfg = ActivityOpenCfgArray.Instance.GetCfg(_activityID); _chapterID = _activityCfg.params3Arr[0]; _ui.m_activityID.selectedPage = _activityID.ToString(); _valueBarController.OnShown(); _ui.m_t0.SetHook("canHit", () => { GRoot.inst.touchable = true; }); _ui.m_t0.Play(); UpdateView(); UpdateTime(); Timers.inst.Add(1, 0, UpdateTime); } protected override void OnHide() { base.OnHide(); _unPasslevelItem = null; _endLevelItem = null; // _ui.m_chapter.RemoveChildren(0, 0, true); GRoot.inst.touchable = true; _valueBarController.OnHide(); Timers.inst.Remove(SetContainerY); Timers.inst.Remove(UpdateTime); } protected override void RemoveEventListener() { base.RemoveEventListener(); } private void OnClickBtnBack() { ViewManager.GoBackFrom(typeof(StoryChapterView).FullName); //GameController.GoBackToMainView(); } private void UpdateView() { //由于这里会切换特效,所以切换界面时进行清空 EffectUIPool.Recycle(_effectUI2); _effectUI2 = null; if (_effFirst != null) { _effFirst.RemoveFromParent(); } StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID); newIndex = StoryUtil.GetChapterOrder(chapterCfg.id); indexY = 111.0f * Mathf.Max(0, (float)StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id).Count - 5); gamey = GameObject.Find("Stage/GRoot/Window - StoryChapterUI/ContentPane/CompChapter/Container/Container"); _ui.m_chapter.m_compChapterScroll.m_imgBegin.visible = false; _ui.m_chapter.m_compChapterScroll.m_nextEffect.visible = false; Timers.inst.StartCoroutine(InitChapter()); //Timers.inst.Add(0.2f, 1, SetContainerY); _ui.m_chapter.m_compChapterScroll.target.y = 1; //招财进宝活动 if (chapterCfg.subType == 2) { UI_ComponentValueBar valueBar = UI_ComponentValueBar.Proxy(_ui.m_valueBar); valueBar.m_c1.selectedIndex = 12; UI_ComponentValueBar.ProxyEnd(); _valueBarController.UpdateList(new List() { ConstItemID.DIAMOND_PURPLE, ConstItemID.DIAMOND_RED }); long timeActivity = ActivityGlobalDataManager.Instance.GetActivityInfoOneByType(17).EndTime - TimeHelper.ServerNow(); } else { UI_ComponentValueBar valueBar = UI_ComponentValueBar.Proxy(_ui.m_valueBar); valueBar.m_c1.selectedIndex = 1; UI_ComponentValueBar.ProxyEnd(); } } private void OnClickNext() { StoryChapterCfg chapterSuitCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID); if (MainStoryDataManager.CheckChapterUnlock(_chapterID + 1) && StoryController.CheckSuitGot(chapterSuitCfg.suitId)) { Timers.inst.Remove(SetContainerY); _chapterID += 1; MainStoryDataManager.currentChapterCfgId = _chapterID; //ViewManager.Show(new object[] { (_chapterID+1), currentDifficulty }); UpdateView(); } else { StoryChapterCfg chapterCfg = StoryChapterCfgArray.Instance.GetCfg(_chapterID + 1); if (!StoryController.CheckSuitGot(chapterSuitCfg.suitId)) { PromptController.Instance.ShowFloatTextPrompt("需集齐所需套装"); } else if (GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) < chapterCfg.lvl) { PromptController.Instance.ShowFloatTextPrompt(string.Format("角色等级达到{0}级开启", chapterCfg.lvl)); } } } private IEnumerator InitChapter() { ActivityFightCfg chapterCfg = ActivityFightCfgArray.Instance.GetCfg(_chapterID); var list = StoryLevelCfgArray.Instance.GetCfgsBytypeAndsubTypeAndchapterId(chapterCfg.type, chapterCfg.subType, chapterCfg.id); int endLevel = 0; int UnlockCount = 0; _compChapter = _ui.m_chapter.m_compChapterScroll.target; float starPosY = _ui.m_chapter.m_compChapterScroll.m_imgBegin.y; int lineGap = 4500 / list.Count; StoryLevelCfg lastLevelCfg = list[list.Count - 1]; //根据困难程度选择显示图片 currentDifficulty = chapterCfg.subType; if (currentDifficulty == 1) { _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("zhangjie_bg"); } else { currentDifficulty = 0; _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bg_zhuxian"); } //_comEff.visible = false; //_effFirst.visible = false; for (int i = 0; i < 20; i++) { GObject obj = _ui.m_chapter.m_compChapterScroll.target.GetChild("g" + (19 - i + 1)); obj.SetPosition(obj.x, starPosY - lineGap * i - 300, 0); ; StoryLevelCfg levelCfg = i < list.Count ? list[i] : null; UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(obj); levelItem.m_fightBg.visible = true; levelItem.m_loaDialogBg.visible = true; if (levelCfg != null && MainStoryDataManager.CheckLevelUnlock(levelCfg.id)) { UnlockCount++; levelItem.target.data = levelCfg.id; levelItem.target.visible = true; levelItem.target.onClick.Clear(); levelItem.target.onClick.Add(OnClickLevelItem); string showId = StoryUtil.GetChapterOrder(_chapterID) + "-" + levelCfg.order; levelItem.m_txtDialogOrder.text = showId; levelItem.m_txtFightOrder.text = showId; levelItem.m_activityID.selectedPage = _activityID.ToString(); levelItem.m_c1.selectedIndex = 1; int score = InstanceZonesDataManager.GetScoreHighest(levelCfg.id); if (score <= 0) { levelItem.m_flower.target.visible = false; } else { levelItem.m_flower.target.visible = true; int starCount = InstanceZonesDataManager.GetStarCountHistory(levelCfg.id); StoryUtil.UpdateStar(starCount, levelItem.m_flower.target, Mathf.Max(0, currentDifficulty)); } //根据困难程度选择显示图片 if (currentDifficulty == 1) { levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq_jy"; levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd_jy"; levelItem.m_txtFightOrder.text = string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#E3F8FF")); levelItem.m_fightIconA.alpha = 0; levelItem.m_fightIconB.alpha = 0; } else { levelItem.m_loaDialogBg.url = "ui://Main/zxian_btn_jq"; levelItem.m_fightBg.url = "ui://Main/zxian_btn_zd"; levelItem.m_txtFightOrder.text = string.Format("{0}", StringUtil.GetColorText(showId.ToString(), "#FFEABF")); levelItem.m_fightIconA.alpha = 0; levelItem.m_fightIconB.alpha = 0; } levelItem.m_holder.visible = !InstanceZonesDataManager.CheckLevelPass(levelCfg.id); if (!InstanceZonesDataManager.CheckLevelPass(levelCfg.id)) { //设置为解锁关卡 MainStoryDataManager.currentLevelCfgId = levelCfg.id; _unPasslevelItem = levelItem.target; //levelItem.target.AddChild(_comEff); //_comEff.visible = true; //设置解锁特效 string effName; if (currentDifficulty == 1) { effName = effArray[levelItem.m_c1.selectedIndex] + "_Bule"; } else { effName = effArray[levelItem.m_c1.selectedIndex]; } if (levelItem.m_c1.selectedIndex == 0) { if (levelItem.m_c2.selectedIndex == 0) { _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq_left").asGraph, "ui_zj", effName); _effFirst.GetChild("effect_jq_left").rotationY = 180; } else { _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_jq").asGraph, "ui_zj", effName); _effFirst.GetChild("effect_jq").rotationY = 0; } } else { _effectUI2 = EffectUIPool.CreateEffectUI(_effFirst.GetChild("effect_zd").asGraph, "ui_zj", effName); if (levelItem.m_c2.selectedIndex == 0) { _effFirst.GetChild("effect_zd").rotationY = 0; } else { _effFirst.GetChild("effect_zd").rotationY = 180; } } levelItem.target.AddChild(_effFirst); levelItem.m_fightBg.visible = false; levelItem.m_loaDialogBg.visible = false; levelItem.m_t0.Play(); _effFirst.visible = true; //Timers.inst.Add(1.7f, 1, HideEffect, obj); } if (levelCfg.order > endLevel) { endLevel = levelCfg.order; _endLevelItem = levelItem.target; } } else { levelItem.target.visible = false; } UI_CompStoryLevelItem.ProxyEnd(); } yield return new WaitForEndOfFrame(); _ui.m_chapter.m_compChapterScroll.target.y = 0; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height); if (gamey != null) gamey.transform.position = new Vector3(0, indexY, 0); } private void SetContainerY(object param = null) { _ui.m_chapter.m_compChapterScroll.target.y = 1; //Mathf.Max(0, _ui.m_chapter.target.height - _ui.m_chapter.m_compChapterScroll.target.height - 1); } private void HideEffect(object param = null) { //_effFirst.visible = false; } private void OnClickLevelItem(EventContext context) { UI_CompStoryLevelItem levelItem = UI_CompStoryLevelItem.Proxy(context.sender as GObject); int levelCfgId = (int)levelItem.target.data; UI_CompStoryLevelItem.ProxyEnd(); StoryController.ShowLevelView(levelCfgId); TryCompleteGuide(); } private void UpdateTime(object param = null) { long endTime = TimeUtil.DateTimeToTimestamp(_activityCfg.endTime); long curTime = TimeHelper.ServerNow(); if (endTime < curTime) { Timers.inst.Remove(UpdateTime); return; } TimeUtil.FormattingTime(curTime, endTime, out int num, out string str); string timeStr = TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime); _ui.m_txtTime.text = timeStr; } } }