//********************* // create by 流云 // time: Sat Mar 14 2026 // desc: //********************* import { _decorator, Component, Node, find, sp, Label, instantiate, tween, Tween, v3, Prefab, assetManager, Asset, AssetManager } from 'cc'; import { Auto_PanelHome } from './Auto_PanelHome'; import { GBundle, getBattleResPakage, getZombieResPakage, GPath, UIID } from '../../game/ConfigRes'; import { HomeBattlePreload } from '../../game/HomeBattlePreload'; import { BattleType, ChapterDifficulty } from '../../manager/ChapterDataManager'; import { GEvent } from 'db://assets/mx/module/event/GEvent'; import { NewFunType } from '../../newFun/NewFun'; import { GuideType } from '../../storyManager/storyManager'; import { sdkConfig } from '../../sdk/sdkConfig'; import { WeaponType } from '../../manager/WeaponDataManager'; import { StatisticsType } from '../../game/GameData'; import { ItemGrid } from '../../com/ItemGrid'; import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad'; import { UIManager } from 'db://assets/mx/module/ui/UIManager'; const { ccclass, property } = _decorator; @ccclass('UIPanelHome') export class UIPanelHome extends Auto_PanelHome { /**切难度防重入,避免事件链反复触发时出现循环调用 */ private _switchingDiff: boolean = false; /** 第4章后「去丧尸工厂」引导进行中:暂缓新功能弹窗,待引导结束再续播 */ private _pauseOverlayUntilGuideEnd: boolean = false; /** 选关页随机角色动画:防快速切章节时旧 schedule 打到已销毁节点 */ private _randomRolePlaySerial = 0; /** * homeGuideIndex 状态机约定(与 MainUI / 各子页保持一致): * - 1~13:引导进行中(默认拦截主页叠加流程) * - 6/7:一段引导结束/收尾态(不拦截) * - >=14:引导完全结束(不拦截) */ private static readonly HOME_GUIDE_BLOCKING_RANGE: readonly [number, number] = [1, 13]; private static readonly HOME_GUIDE_NON_BLOCKING_INDEX = new Set([6, 7]); private static readonly HOME_GUIDE_NON_BLOCKING_FROM = 14; // setBattlePerfProfile('ios') // 切到苹果档 // setBattlePerfProfile('android') // 切到安卓档 // setBattlePerfProfile('auto') // 恢复默认(安卓) /** 主页拆出的动态子预制是否已挂到 ui_center */ private _dynamicHomeUiReady = false; getResPkg() { return { name: "主页动态UI", // 主页常驻,勿随分包释放导致子预制引用失效 isReleaseable: false, ress: [ // ui_task:沿用 comm2/taskTargetNode,挂载后改名为 ui_task { name: 'taskTargetNode', bundle: GBundle.Comm2, path: GPath.Prefab, type: Prefab }, { name: 'ui_btns', bundle: GBundle.Home, path: GPath.Prefab, type: Prefab }, { name: 'ui_leftBtns', bundle: GBundle.Home, path: GPath.Prefab, type: Prefab }, { name: 'ui_RightBtns', bundle: GBundle.Home, path: GPath.Prefab, type: Prefab }, { name: 'ui_topBtns', bundle: GBundle.Home, path: GPath.Prefab, type: Prefab }, ] }; } onLoad(): void { super.onLoad(); if(gg.data.getStatistics(StatisticsType.LiulianGuideIndex) != 0 && gg.data.getStatistics(StatisticsType.LiulianGuideIndex) != 7){ console.log("榴莲引导索引异常", gg.data.getStatistics(StatisticsType.LiulianGuideIndex)) gg.data.setStatistics(StatisticsType.LiulianGuideIndex, 7) } } onEnable(): void { super.onEnable(); this.ui_title.on(Node.EventType.TOUCH_END, this.click_ui_title, this); this.ui_rewardLayer.on(Node.EventType.TOUCH_END, this.click_ui_rewardLayer, this); GEvent.Ins.on(GEvent.SelectChapter, this.onChapterOrDiffChange, this); GEvent.Ins.on(GEvent.SelectDifficult, this.onDiffChange, this); GEvent.Ins.on(GEvent.StoryDialogEnd, this.StoryDialogEnd, this); GEvent.Ins.on(GEvent.checkJuQing, this.checkJuQing, this); GEvent.Ins.on(GEvent.homeGuideIndexEventEnd, this.guideEnd, this); GEvent.Ins.on(GEvent.LiulianGuideIndexEvent, this.showLiulianGuideEnd, this); GEvent.Ins.on(GEvent.jumpLayerOpenBox, this.updateBoxUI, this); } onDisable(): void { super.onDisable(); this.ui_title.off(Node.EventType.TOUCH_END, this.click_ui_title, this); this.ui_rewardLayer.off(Node.EventType.TOUCH_END, this.click_ui_rewardLayer, this); GEvent.Ins.off(GEvent.SelectChapter, this.onChapterOrDiffChange, this); GEvent.Ins.off(GEvent.SelectDifficult, this.onDiffChange, this); GEvent.Ins.off(GEvent.StoryDialogEnd, this.StoryDialogEnd, this); GEvent.Ins.off(GEvent.checkJuQing, this.checkJuQing, this); GEvent.Ins.off(GEvent.homeGuideIndexEventEnd, this.guideEnd, this); GEvent.Ins.off(GEvent.LiulianGuideIndexEvent, this.showLiulianGuideEnd, this); GEvent.Ins.off(GEvent.jumpLayerOpenBox, this.updateBoxUI, this); this._randomRolePlaySerial++; } /** 供 UIMainUI 在武器链跳过「点角色」时拉队列(避免依赖 PanelHome.onEnable 监听,切 Tab 时 onDisable 会丢事件) */ scheduleHomeOverlayFromGuide(): void { this.scheduleHomeOverlaySequence(); } /** 最大章节ID */ private _maxChapterId: number = 0; /** 当前章节ID */ private _curentChapterId: number = 0; /** 当前难度 */ private _curentDiffId: number = 2; /** 当前章节配置 */ private _curentConfig: ITableChapter = null; /**当前章节是否可挑战 */ private _curentSelectChapterIsUnlock: boolean = true; /** 当前章节宝箱配置的进度百分比数组 */ private _chapterProgressArr: number[] = []; /**当前章节推荐战力 */ private _curentRecommendPower: number = 0; /**当前章节是否已通关 */ private _curentChapterIsComplete: boolean = false; /** onInit 期间先搭完动态 UI,章节项放到最后创建 */ private _deferChapterItem = false; onInit(): void { this.ensureDynamicHomeUI(); if (gg.data.project.syncNormalChapterProgress()) { gg.data.saveLocal(); } this._maxChapterId = gg.data.project.getMaxChapterId(); this._curentDiffId = gg.data.project.getCurSelectSaveChapterDifficulty(); if (!this._curentDiffId) this._curentDiffId = ChapterDifficulty.Normal; this._curentChapterId = gg.data.project.getCurentLevelChapterId(this._curentDiffId); if (!this._curentChapterId) this._curentChapterId = 1; this.updateChapterData(); this._deferChapterItem = true; this.initUI(); this._deferChapterItem = false; // 与界面一致:主界面红点(左右章节宝箱)用 gg.game.CurentSelectChapterId,默认曾为 1,未同步会导致重启后误判为 true gg.game.CurentSelectChapterId = this._curentChapterId; gg.game.CurentSelectBattleType = BattleType.Level; gg.game.CurentSelectBattleDifficulty = this._curentDiffId; gg.dot?.updateRedDot(); gg.newFun.checkNewFunPop(); HomeBattlePreload.startNow(this._curentChapterId); let isUnLockTask = gg.newFun.isUnLockMainPageTab(UIID.Shop) if (this.ui_task) { this.ui_task.active = !!isUnLockTask; } this.guideShow() this.tryShowOfflineRewardIfNeeded(); // 动态 UI 全部就绪后再创建 MainChapterItem this.setChapterItem(); // this.scheduleOnce(()=>{ // gg.sdk.PlatformFeedSubscribe(); // },1) } /** * 将拆出的五个子预制动态挂到 ui_center: * ui_task(taskTargetNode)、ui_btns、ui_leftBtns、ui_RightBtns、ui_topBtns */ private ensureDynamicHomeUI() { if (!this.ui_center?.isValid) { console.warn('UIPanelHome: ui_center missing, skip dynamic home UI'); return; } if (this._dynamicHomeUiReady && this.ui_btns?.isValid) { return; } const specs: { nodeName: string; assetName: string; bundle: string }[] = [ { nodeName: 'ui_task', assetName: 'taskTargetNode', bundle: GBundle.Comm2 }, { nodeName: 'ui_btns', assetName: 'ui_btns', bundle: GBundle.Home }, { nodeName: 'ui_leftBtns', assetName: 'ui_leftBtns', bundle: GBundle.Home }, { nodeName: 'ui_RightBtns', assetName: 'ui_RightBtns', bundle: GBundle.Home }, { nodeName: 'ui_topBtns', assetName: 'ui_topBtns', bundle: GBundle.Home }, ]; for (const spec of specs) { let node = this.ui_center.getChildByName(spec.nodeName); if (!node) { node = gg.res.getNode(GPath.Prefab, spec.assetName, spec.bundle); if (!node) { console.warn('UIPanelHome: dynamic prefab not ready', spec.bundle, spec.assetName); continue; } if (node.name !== spec.nodeName) { node.name = spec.nodeName; } this.setLayerMask(node, this.ui_center.layer); this.ui_center.addChild(node); } node.active = true; } this.bindDynamicHomeNodes(); // 首次 onEnable 早于资源加载,动态按钮当时未绑定,此处补绑 this.bindDynamicHomeEvents(true); this._dynamicHomeUiReady = true; } /** 更新章节数据 */ updateChapterData() { this._curentConfig = gg.data.project.getChapterConfig(this._curentChapterId); this._curentSelectChapterIsUnlock = gg.data.project.isChapterCanChallenge(this._curentChapterId, this._curentDiffId); this._chapterProgressArr = gg.data.project.getChapterBoxProgress(this._curentChapterId, this._curentDiffId); this._curentRecommendPower = gg.data.project.getRecommendPower(this._curentChapterId, this._curentDiffId); this._curentChapterIsComplete = gg.data.project.isChapterComplete(this._curentChapterId, this._curentDiffId); } /** 初始化UI */ initUI() { this.showIAPVersionUI() this.updateUI(); } //内购版本显示UI showIAPVersionUI() { if (!this.ui_RightMidBtns || !this.ui_leftMidBtns) { return; } if (sdkConfig.isIAPVersion) { // this.ui_RightMidBtns.active = true; this.ui_leftMidBtns.active = true } else { //非内购版本显示UI this.ui_RightMidBtns.active = false; this.ui_leftMidBtns.active = false } } /** 更新UI */ updateUI() { this.updateBtnsStatus(); this.updateDiffUI(); this.updateChapterInfo(); if (!this.btnLeft || !this.btnRight) { return; } if (this._curentChapterId == this._maxChapterId){ this.btnRight.active = false; this.btnLeft.active = true; } else if(this._curentChapterId ==1 ){ this.btnRight.active = true; this.btnLeft.active = false; }else{ this.btnRight.active = true; this.btnLeft.active = true; } } /** 更新按钮状态 */ updateBtnsStatus() { if (!this.btnStart || !this.btnBack || !this.btnLeft || !this.btnRight) { return; } this.btnStart.active = this._curentSelectChapterIsUnlock; //this.lb_status.node.active = !this.btnStart.active && !this._curentSelectChapterIsUnlock; this.btnBack.active = !this.btnStart.active && !this._curentSelectChapterIsUnlock; if (this._curentDiffId == ChapterDifficulty.Normal) { //this.lb_status.string = gg.lang.get('请通关前置关卡后可挑战'); } else { let diffStr = "普通"; if (this._curentDiffId == ChapterDifficulty.Hell) diffStr = "困难"; let diffStr2 = '困难'; if (this._curentDiffId == ChapterDifficulty.Hell) diffStr2 = "地狱"; //this.lb_status.string = gg.lang.get('通关本关{1}模式和{2}模式前置关卡后可挑战', [diffStr, diffStr2]); } this.btnLeft.active = this._curentChapterId > 1; this.btnRight.active = this._curentChapterId < gg.data.doc.chapter + 2; this.btnStart.find("bg").children.forEach(x => x.active = false); this.btnLeft.find("bg").children.forEach(x => x.active = false); this.btnRight.find("bg").children.forEach(x => x.active = false); this.btnStart.find(`bg/${this._curentDiffId}`).active = true; this.btnLeft.find(`bg/${this._curentDiffId}`).active = true; this.btnRight.find(`bg/${this._curentDiffId}`).active = true; } /** 更新难度UI */ updateDiffUI() { //ps 修改ui } /** 更新章节信息 */ updateChapterInfo() { this.lb_chapter.string = gg.lang.get('第{1}章', [this._curentChapterId]); this.lb_chapterName.string = gg.lang.get(this._curentConfig.name); this.lb_combatPower.string = gg.lang.get('推荐战力:{1}', [this._curentRecommendPower]); this.ui_lockStatus.active = !this._curentSelectChapterIsUnlock; this.ui_finishStatus.active = this._curentChapterIsComplete; gg.data.project.vigourCost = this._curentConfig.chapter_enery; if (this.lb_tilifree && this.ui_tilitag && this.lb_needVigour) { if(this._curentConfig.chapter_enery == 0){ this.lb_tilifree.node.active = true this.ui_tilitag.active = false this.lb_needVigour.node.active = false }else{ this.lb_needVigour.node.active = true this.ui_tilitag.active = true this.lb_tilifree.node.active = false this.lb_needVigour.string = 'x'+this._curentConfig.chapter_enery.toString() } } if (!this._deferChapterItem) { this.setChapterItem(); } this.updateBoxUI(); } async setChapterItem(){ //设置关卡预制体 this.ui_chapterNode.active = true; this.ui_chapterNode.removeAllChildren(); let prefab = await this.loadPrefab(GBundle.Home,"prefab/"+"MainChapterItem"+this._curentChapterId) as Prefab; if(!this.ui_chapterNode || !this.ui_chapterNode.isValid){ return } let chapterItem = instantiate(prefab); if (!chapterItem) { console.warn("UIPanelHome: MainChapterItem"+this._curentChapterId+" prefab not ready", GBundle.Home); return; } if(!this.ui_chapterNode || !this.ui_chapterNode.isValid){ return } chapterItem.active = true; this.setLayerMask(chapterItem, chapterItem.layer); chapterItem.setPosition(v3(0, 0, 0)); this.ui_chapterNode.addChild(chapterItem); // 随机播放角色动画:原生/小游戏端偶发同一帧内 find 不到子节点或 Spine 未就绪,延后一帧再播(与模拟器一致) const itemRef = chapterItem; const chapterId = this._curentChapterId; //console.log('[UIPanelHome.setChapterItem] defer randomRolePlay next frame', 'chapter', chapterId, 'item', itemRef?.name); this.scheduleOnce(() => { if (!itemRef?.isValid || !this.ui_chapterNode?.isValid) { //console.warn('[UIPanelHome.setChapterItem] randomRolePlay skip: item or chapterNode invalid', 'chapter', chapterId); return; } //console.log('[UIPanelHome.setChapterItem] run randomRolePlay', 'chapter', chapterId); this.randomRolePlay(itemRef); }, 1); } private async loadPrefab(bundleName, assetPath) { let bundle = assetManager.getBundle(bundleName); if (!bundle) bundle = await this.loadBundle(bundleName); let res = await this.loadRes(bundle, assetPath); return res; } private async loadBundle(bundleName) { return new Promise((resolve, reject) => { assetManager.loadBundle(bundleName, (err, bundle) => { if (err) { console.log(`加载Bundle:${bundleName}错误`, err); resolve(null); } else { resolve(bundle); } }) }) } private async loadRes(bundle: AssetManager.Bundle, assetPath) { return new Promise((resolve, reject) => { let b = bundle.get(assetPath, Prefab); if (b) { resolve(b); } else { bundle.load(assetPath, Prefab, (err, asset) => { if (err) { console.log(`加载Bundle:${bundle.name},path:${assetPath}资源错误`, err); resolve(null); } else { resolve(asset); } }) } }) } randomRolePlay(node: Node){ if (!node) return; this._randomRolePlaySerial++; const serial = this._randomRolePlaySerial; let rolePath:string[] = []; let roleName:string[] = ["role", "role-001", "role-002", "role-003", "role-004", "role-005"]; for (let i = 0; i < roleName.length; i++) { const spineRelPath = roleName[i]; if (!spineRelPath) continue; let spineNode = find(spineRelPath, node); if (spineNode) { const skInit = spineNode.getComponent(sp.Skeleton); if (!skInit) { console.log('[UIPanelHome.randomRolePlay] no Skeleton', spineRelPath); continue; } rolePath.push(spineRelPath); skInit.setAnimation(0, '待机', true); } } let count = rolePath.length; if (count === 1) { const onlyRelPath = rolePath[0]; if (onlyRelPath) { let spineNode = find(onlyRelPath, node); if (spineNode) { const sk1 = spineNode.getComponent(sp.Skeleton); if (sk1) sk1.setAnimation(0, "选关页待机", true); } } } else if (count >= 2) { // 对「节点相对路径」副本洗牌后直接遍历,避免 Array(n).keys() / 数字索引在部分运行环境异常导致 path 取不到 const shuffledPaths = rolePath.slice(); for (let i = shuffledPaths.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); const tmp = shuffledPaths[i]; shuffledPaths[i] = shuffledPaths[j]; shuffledPaths[j] = tmp; } // 每个 Spine 单独 schedule、单调递增的绝对延迟,避免原生端链式 scheduleOnce 在同一帧连发(与浏览器表现不一致、看起来「一起跳」) let cum = 0.35 + Math.random() * 0.55; for (let k = 0; k < shuffledPaths.length; k++) { const spineRelPath = shuffledPaths[k]; if (!spineRelPath) continue; const spineNode = find(spineRelPath, node); if (!spineNode) continue; const sk = spineNode.getComponent(sp.Skeleton); if (!sk) continue; sk.setAnimation(0, null, false); const when = cum; cum += 0.28 + Math.random() * 1; const skRef = sk; this.scheduleOnce(() => { if (serial !== this._randomRolePlaySerial || !node?.isValid || !skRef?.isValid) { return; } skRef.setAnimation(0, "选关页待机", true); }, when); } } } setLayerMask(n: Node, layerMask: number) { n.layer = layerMask; for (let i = 0; i < n.children.length; i++) { if (n.children[i].isValid) { this.setLayerMask(n.children[i], layerMask); } } } /** 更新宝箱UI */ updateBoxUI() { let curentProgress = 0; for (let i = 0; i < 3; i++) { let boxStatus = gg.data.project.getChapterStatus(this._curentChapterId, this._curentDiffId, i); let btn = this.ui_boxBtns.find("btnBox" + (i + 1)); let progress = this._chapterProgressArr[i]; if (boxStatus >= 1) curentProgress = progress; if (btn) { btn.find("open").active = boxStatus == 2; btn.find("dot").active = boxStatus == 1; btn.find("lbProgres").getComponent(Label).string = progress * 100 + "%"; } } this.sp_progress.fillRange = curentProgress; } /** 选择章节 */ selectChapter(chapterId: number) { if (this._curentChapterId == chapterId) return; this._curentChapterId = chapterId; gg.data.project.setCurSelectSaveChapterId(chapterId); gg.game.CurentSelectChapterId = this._curentChapterId; gg.game.CurentSelectBattleType = BattleType.Level; gg.game.CurentSelectBattleDifficulty = this._curentDiffId; this.updateChapterData(); HomeBattlePreload.startNow(this._curentChapterId); } /** 选择难度 */ selectDiff(diffId: ChapterDifficulty) { if (this._switchingDiff) return; if (this._curentDiffId == diffId) return; this._switchingDiff = true; try { this._curentDiffId = diffId; // 切难度时:若当前章节在新难度不可挑战,跳到该难度最高可挑战章节 // if (!gg.data.project.isChapterCanChallenge(this._curentChapterId, this._curentDiffId)) { // } this._curentChapterId = gg.data.project.getCurentLevelChapterId(this._curentDiffId); gg.data.project.setCurSelectSaveChapterId(this._curentChapterId); gg.data.project.setCurSelectSaveChapterDifficulty(diffId); gg.game.CurentSelectChapterId = this._curentChapterId; gg.game.CurentSelectBattleType = BattleType.Level; gg.game.CurentSelectBattleDifficulty = this._curentDiffId; this.updateChapterData(); HomeBattlePreload.startNow(this._curentChapterId); } finally { this._switchingDiff = false; } } /** 章节或难度改变时更新UI */ onChapterOrDiffChange(chapterId: number) { this.selectChapter(chapterId); //this.selectDiff(diffId); this.updateUI(); } /** 难度改变时更新UI */ onDiffChange(diffId: ChapterDifficulty) { this.selectDiff(diffId); this.updateUI(); } click_ui_title(): void { gg.ui.openPanel(UIID.selectDifficult) } click_ui_rewardLayer(): void { this.ui_rewardLayer.active = false; } click_btnDiff2(): void { this.selectDiff(ChapterDifficulty.Normal); this.updateUI(); } click_btnDiff3(): void { let hardConf = gg.newFun.getNewFunData(NewFunType.Difficulty, ChapterDifficulty.Hard); let isUnLockHard = gg.newFun.isUnLockDifficult(ChapterDifficulty.Hard); if (!isUnLockHard) { //提示章节不足 gg.ui.showToast(gg.lang.get(hardConf.desc, [hardConf.chapter])); return } this.selectDiff(ChapterDifficulty.Hard); this.updateUI(); } click_btnDiff4(): void { let hellConf = gg.newFun.getNewFunData(NewFunType.Difficulty, ChapterDifficulty.Hell); let isUnLockHell = gg.newFun.isUnLockDifficult(ChapterDifficulty.Hell); if (!isUnLockHell) { //提示章节不足 gg.ui.showToast(gg.lang.get(hellConf.desc, [hellConf.chapter])); return } this.selectDiff(ChapterDifficulty.Hell); this.updateUI(); } click_btnBox1(): void { this.clickBoxBtn(1, this.btnBox1); } click_btnBox2(): void { this.clickBoxBtn(2, this.btnBox2); } click_btnBox3(): void { this.clickBoxBtn(3, this.btnBox3); } clickBoxBtn(boxIndex: number, btn: Node) { let rewardStr = gg.data.project.getChapterBoxRewardStr(this._curentChapterId,ChapterDifficulty.Normal ,boxIndex); if (btn.find("dot").active) { gg.data.project.setChapterStatus(this._curentChapterId, this._curentDiffId, boxIndex - 1, 2); gg.game.showGetRewardByReardStr(rewardStr); this.updateBoxUI(); } else { let itens = gg.game.parseRewardStr(rewardStr); this.ui_rewardLayer.active = true; if (boxIndex == 1) this.ui_ItemReward.x = -140; else if (boxIndex == 2) this.ui_ItemReward.x = 0; else if (boxIndex == 3) this.ui_ItemReward.x = 140; this.ui_ItemReward.children.forEach(x => x.active = false); for (let i = 0; i < itens.length; i++) { let item = itens[i]; let n: Node = null; if (i < this.ui_ItemReward.children.length) { n = this.ui_ItemReward.children[i]; } else { n = instantiate(this.ui_ItemReward.children[0]); this.ui_ItemReward.addChild(n); } n.active = true; n.getComponent(ItemGrid).setData(item); } } } click_btnLeft(): void { let id = this._curentChapterId - 1; if (id < 1) id = 1; if (id == this._curentChapterId){ return } //ps 修改ui去掉动画效果 // Tween.stopAllByTarget(this.ui_di); // let angleOffset = this.ui_di.angle % 90; // tween(this.ui_di) // .by(0.2, { angle: 90 + angleOffset }) // .start(); //end this.selectChapter(id); this.updateUI(); } click_btnRight(): void { let id = this._curentChapterId + 1; if (id > this._maxChapterId) id = this._maxChapterId; if (id == this._curentChapterId){ return; } // Tween.stopAllByTarget(this.ui_di); // let angleOffset = this.ui_di.angle % 90; // tween(this.ui_di) // .by(0.2, { angle: -90 - angleOffset }) // .start(); this.selectChapter(id); this.updateUI(); } click_btnStart(): void { if (gg.data.getVigour() < gg.data.project.vigourCost) { gg.ui.showToast('请补充体力!') return } if(this._curentChapterId<=0){ return } gg.game.CurentSelectReplica = null; gg.game.CurentSelectChapterId = this._curentChapterId; gg.game.CurentSelectBattleType = BattleType.Level; gg.game.CurentSelectBattleDifficulty = this._curentDiffId; gg.game.enterBattle(); } click_btnBack(): void { //点击返回到当前章节 let curChapterId = gg.data.project.getCurentLevelChapterId(ChapterDifficulty.Normal); if (curChapterId < 1) curChapterId = 1; this.selectChapter(curChapterId); //this.selectDiff(diffId); this.updateUI(); } click_btnEntrance(): void { gg.ui.openPanel(UIID.Sidebar); } click_btnNotice(): void { gg.ui.openPanel(UIID.PopNotice); } click_btnSupergift() { gg.ui.openPanel(UIID.greatGift); } click_btnMoreGame() { gg.ui.openPanel(UIID.atGameChoose); } click_btnOutLine(): void { // let conf = gg.newFun.getNewFunData(NewFunType.MainPageTab, UIID.zombieLayer); // if (gg.data.doc.chapter <= conf.chapter) { // gg.ui.showToast(gg.lang.get('通关第{1}章节解锁', [conf.chapter]), false) // return; // } // //预加载UIID.zombieFarm // gg.game.showLoading(1); // let resPkg = getZombieResPakage(); // this.scheduleOnce(() => { // gg.res.loadResPakg(resPkg, (c, t) => { // }, () => { // gg.game.hideLoading(); // gg.ui.openPanel(UIID.zombieLayer); // }); // }) // gg.ui.openPanel(UIID.zombieLayer); gg.ui.openPanel(UIID.wipeOut); } click_btnTask(): void { let conf = gg.newFun.getNewFunData(NewFunType.MainPageBtn, 5); if (gg.data.doc.chapter <= conf.chapter) { gg.ui.showToast(gg.lang.get(conf.desc, [conf.chapter]), false) return } gg.ui.openPanel(UIID.taskView); } click_btnSignIn(): void { gg.ui.openPanel(UIID.sign7Day); } click_btnSetting(): void { gg.ui.openPanel(UIID.Settings); } click_btnLevel(): void { let conf = gg.newFun.getNewFunData(NewFunType.MainPageBtn, 2); if (gg.data.doc.chapter <= conf.chapter) { gg.ui.showToast(gg.lang.get(conf.desc, [conf.chapter]), false) return } gg.ui.openPanel(UIID.jumpGameLevel) } /** 点击邀请好友 */ click_btnInvite(): void { } /** 点击排行榜 */ click_btnRank(): void { } /** 点击超值礼包 */ click_btnValueGift(): void { let conf = gg.newFun.getNewFunData(NewFunType.MainPageBtn, 1); if (gg.data.doc.chapter <= conf.chapter) { gg.ui.showToast(gg.lang.get(conf.desc, [conf.chapter]), false) return } } click_btnFirstBag(): void { gg.ui.openPanel(UIID.PopFirstRecharge); } click_btnMonthlyCard(): void { let conf = gg.newFun.getNewFunData(NewFunType.MainPageBtn, 3); if (gg.data.doc.chapter <= conf.chapter) { gg.ui.showToast(gg.lang.get(conf.desc, [conf.chapter]), false) return } gg.ui.openPanel(UIID.PopMonthCard); } click_btnDayGift(): void { gg.ui.openPanel(UIID.PopContinuouslyBag); } click_btnfund(): void { let conf = gg.newFun.getNewFunData(NewFunType.MainPageBtn, 4); if (gg.data.doc.chapter <= conf.chapter) { gg.ui.showToast(gg.lang.get(conf.desc, [conf.chapter]), false) return } gg.ui.openPanel(UIID.PopFund); } showStartBtnFinger() { this.btnStart.getChildByName('finger').active = true } showLiulianGuideEnd(){ if (gg.data.getStatistics(StatisticsType.LiulianGuideIndex) == 6) { this.showStartBtnFinger() gg.data.setStatistics(StatisticsType.LiulianGuideIndex, 7) } } guideEnd() { //引导结束 if (gg.data.getStatistics(StatisticsType.homeGuideIndex) == 4) { this.showStartBtnFinger() } else { if (this._pauseOverlayUntilGuideEnd) { this._pauseOverlayUntilGuideEnd = false; } this.scheduleHomeOverlaySequence(); this.tryShowOfflineRewardIfNeeded(); } } guideShow(){ if( gg.data.doc.chapter == 2 && gg.game.playerGameFail && gg.data.getStatistics(StatisticsType.homeGuideIndex) == 0){ let weaponLevel = gg.data.project.getWeaponLevel(WeaponType.DanGong); if (weaponLevel >= 2) { // 已跳过武器引导时:仅当已通关第3章才进入「点角色」(index4);否则直接结束本段 gg.data.setStatistics(StatisticsType.homeGuideIndex, 4) return } let goodID = 21 //彩虹飞弹碎片 gg.data.addItemNum(goodID, 5); gg.data.setStatistics(StatisticsType.homeGuideIndex, 1) GEvent.Ins.emit(GEvent.homeGuideIndexEventNew, 1) }else if(gg.data.doc.chapter == 2 && gg.game.IsPlayedGame){ //引导角色升级 // if(gg.data.getStatistics(StatisticsType.homeGuideIndex) < 4){ gg.data.setStatistics(StatisticsType.homeGuideIndex, 4) } GEvent.Ins.emit(GEvent.homeGuideIndexEventNew, 4) } } StoryDialogEnd(guideIndex) { if (guideIndex == 0) { this.scheduleHomeOverlaySequence(); return } //引导结束新功能引导 if (GuideType.guide1 == guideIndex) { //引导进入丧尸工厂 console.log("超值弹窗+若引导"); // gg.game.guideGreatGift = true; // gg.ui.popPanel(UIID.greatGift); // this.showStartBtnFinger() } else if (GuideType.guide2 == guideIndex) { console.log("武器引导"); //判断彩虹飞弹武器等级 let weaponLevel = gg.data.project.getWeaponLevel(WeaponType.DanGong); if (weaponLevel >= 2) { // 已跳过武器引导时:仅当已通关第3章才进入「点角色」(index4);否则直接结束本段 gg.data.setStatistics(StatisticsType.homeGuideIndex, gg.data.doc.chapter >= 4 ? 4 : 6) this.scheduleHomeOverlaySequence(); return } let goodID = 21 //彩虹飞弹碎片 gg.data.addItemNum(goodID, 5); gg.data.setStatistics(StatisticsType.homeGuideIndex, 1) GEvent.Ins.emit(GEvent.homeGuideIndexEvent) //引导点击武器 ->引导点击彩虹飞弹->点击升级->点击战斗 } else if (GuideType.guide3 == guideIndex) { console.log("角色引导(配表 type4 第三章后剧情)"); // 通关第3章后播片结束 → 引导点角色升级(与武器链 doc.chapter>=4 一致) let playerLevel = gg.data.getPlayerLevel(); if (playerLevel >= 2) { gg.data.setStatistics(StatisticsType.homeGuideIndex, 6) this.scheduleHomeOverlaySequence(); return } if(playerLevel == 0){ gg.game.forceHomeRoleTabGuide = true; gg.data.setStatistics(StatisticsType.homeGuideIndex, 4) GEvent.Ins.emit(GEvent.homeGuideIndexEvent); } return; } else if (GuideType.guide4 == guideIndex) { console.log("强引导点击进入丧尸农场(第4章结束剧情,配表 guide4)"); // guide4 与「新副本解锁弹窗」同帧触发时会抢层:引导期间先暂停叠加流程,待 guideEnd 再恢复 this._pauseOverlayUntilGuideEnd = true; let btnOutLine = this.btnOutLine gg.ui.openPanel(UIID.NewGuideMask, { data: [ [btnOutLine], [''], () => { // NewGuideMask 本身不会派发“引导结束”事件;若不补这个,_pauseOverlayUntilGuideEnd 会一直卡住 // 这里以“用户完成点击目标按钮”为本段引导结束信号,恢复主页叠加队列 this.scheduleOnce(() => { GEvent.Ins.emit(GEvent.homeGuideIndexEventEnd); }, 0); }, true, 255 ] }) } else if (GuideType.guide5 == guideIndex) { console.log("引导解锁困难模式"); let toggle = this.ui_title gg.data.setStatistics(StatisticsType.homeGuideIndex, 8) gg.ui.openPanel(UIID.NewGuideMask, { data: [ [toggle], [gg.lang.get('远方传来一阵异响,地狱模式已开放,该你出手了')], () => { }, true, 255 ] }) } else if (GuideType.guide6 == guideIndex) { console.log("引导点击角色"); //角色-宠物-宠物抽取 gg.data.setStatistics(StatisticsType.homeGuideIndex, 11) GEvent.Ins.emit(GEvent.homeGuideIndexEvent) } } /** * 主页叠加流程:引导(openPanel 遮罩,优先级最高)-> 剧情(popPanel 队列)-> 新功能解锁(popPanel 队列)。 * 引导未完成时不入队剧情/新功能,避免与 NewGuideMask 等抢层。 */ checkJuQing() { this.scheduleHomeOverlaySequence(); //地狱引导,因为和剧情和新功能没有冲突开启引导 // if(gg.data.getStatistics(StatisticsType.HellGuideIndex) == 0 && gg.data.doc.chapter > 16){ // let toggle = this.ui_title // gg.data.setStatistics(StatisticsType.HellGuideIndex, 1) // gg.ui.openPanel(UIID.NewGuideMask, { // data: [ // [toggle], // [gg.lang.get('远方传来一阵异响,地狱模式已开放,该你出手了')], // () => { // }, // true, // 255 // ] // }) // } } /** 与 MainUI / 各子页 homeGuideIndex 状态机一致:6=一段引导结束,7/14+=不拦截 */ private isHomeGuideBlocking(): boolean { const idx = gg.data.getStatistics(StatisticsType.homeGuideIndex); if (UIPanelHome.HOME_GUIDE_NON_BLOCKING_INDEX.has(idx)) return false; if (idx >= UIPanelHome.HOME_GUIDE_NON_BLOCKING_FROM) return false; const [min, max] = UIPanelHome.HOME_GUIDE_BLOCKING_RANGE; return idx >= min && idx <= max; } /** 离线收益(wipeOut):引导进行中不弹,引导结束后再尝试 */ private tryShowOfflineRewardIfNeeded(): void { if (gg.data.doc.chapter <= 1 || gg.game.isShowWipeOut) return; if (this.isHomeGuideBlocking() || this._pauseOverlayUntilGuideEnd) return; gg.game.isShowWipeOut = true; const maxTime = 8 * 60 * 60; const lastAddTime = gg.data.getStatistics(StatisticsType.AfkRewards); const curTime = gg.data.getCurentTime(); const time = Math.floor((curTime - lastAddTime) / 1000); if (time >= maxTime) { this.scheduleOnce(() => { if (this.isHomeGuideBlocking() || this._pauseOverlayUntilGuideEnd) return; gg.ui.openPanel(UIID.wipeOut); }, 1); } } private scheduleHomeOverlaySequence(): void { return; if (this._pauseOverlayUntilGuideEnd) { return; } if (this.isHomeGuideBlocking()) { const idx = gg.data.getStatistics(StatisticsType.homeGuideIndex); if (idx === 1 || idx === 3 || idx === 4 || idx === 11) { GEvent.Ins.emit(GEvent.homeGuideIndexEvent); } return; } const funid = gg.storyManager.isUnLockMode(); if (funid !== -1) { const list = gg.storyManager.getStoryComicData(funid); const isCanOpen = gg.storyManager.isCanOpen(funid); if (list && isCanOpen) { gg.storyManager.storyGuide(funid); return; } }else{ if(gg.game.thirdChapterFailWeaponUpgrade && gg.data.getStatistics(StatisticsType.secondChapterFailWeaponUpgrade) == 0){ gg.data.setStatistics(StatisticsType.secondChapterFailWeaponUpgrade, 1) gg.storyManager.storyForceGuide(3); return; } if(gg.game.thirdChapterFailRoleUpgrade && gg.data.getStatistics(StatisticsType.secondChapterFailRoleUpgrade) == 0){ gg.data.setStatistics(StatisticsType.secondChapterFailRoleUpgrade, 1) //加200的金币升级 gg.data.addMoney(200); //引导点击角色升级 gg.game.forceHomeRoleTabGuide = true; gg.data.setStatistics(StatisticsType.homeGuideIndex, 4) GEvent.Ins.emit(GEvent.homeGuideIndexEvent); return; } if(gg.data.doc.chapter == 3 && gg.game.thirdChapterWinGreatGift){ gg.game.thirdChapterWinGreatGift = false; let greatGiftGetDay = gg.data.getStatistics(StatisticsType.GreatGiftGetDay) if(greatGiftGetDay == 0 && gg.data.getStatistics(StatisticsType.GreatGiftStatus) == 0){ gg.game.guideGreatGift = true; gg.ui.openPanel(UIID.greatGift) } } } gg.newFun.checkNewFunPop(); } checkGuide() { return false } showGude() { } }