You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
403 lines
14 KiB
403 lines
14 KiB
|
|
//*********************
|
|
// create by 流云
|
|
// time: Mon Mar 02 2026
|
|
// desc:
|
|
//*********************
|
|
import { _decorator, Component, Node, find, director } from 'cc';
|
|
import { Auto_MainUI } from './Auto_MainUI';
|
|
import { UIPanelHome } from '../PanelHome/UIPanelHome';
|
|
import { UIConfigs, UIID } from '../../game/ConfigRes';
|
|
import { NewFunType } from '../../newFun/NewFun';
|
|
import { StatisticsType } from '../../game/GameData';
|
|
import { GEvent } from 'db://assets/mx/module/event/GEvent';
|
|
import { SmartPreload } from '../../game/SmartPreload';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('UIMainUI')
|
|
export class UIMainUI extends Auto_MainUI {
|
|
|
|
/** 与底部五个按钮对应的子界面 ID(商城、角色、战斗、武器、副本) */
|
|
private static readonly MAIN_TAB_IDS: number[] = [
|
|
UIID.Shop,
|
|
UIID.Role,
|
|
UIID.Home,
|
|
UIID.Weapon,
|
|
UIID.Replica,
|
|
];
|
|
|
|
onLoad(): void {
|
|
super.onLoad();
|
|
}
|
|
|
|
onEnable(): void {
|
|
GEvent.Ins.on(GEvent.homeGuideIndexEvent, this.showGuide, this);
|
|
GEvent.Ins.on(GEvent.homeGuideIndexEventNew, this.showGuideNew, this);
|
|
GEvent.Ins.on(GEvent.LiulianGuideIndexEvent, this.showLiulianGuide, this);
|
|
GEvent.Ins.on(GEvent.UpdateMainUI, this.updateUI, this);
|
|
GEvent.Ins.on(GEvent.Ch4FarmOutlineGuide, this.onCh4FarmOutlineGuide, this);
|
|
super.onEnable();
|
|
}
|
|
|
|
onDisable(): void {
|
|
GEvent.Ins.off(GEvent.homeGuideIndexEvent, this.showGuide, this);
|
|
GEvent.Ins.off(GEvent.homeGuideIndexEventNew, this.showGuideNew, this);
|
|
GEvent.Ins.off(GEvent.UpdateMainUI, this.updateUI, this);
|
|
GEvent.Ins.off(GEvent.Ch4FarmOutlineGuide, this.onCh4FarmOutlineGuide, this);
|
|
GEvent.Ins.off(GEvent.LiulianGuideIndexEvent, this.showLiulianGuide, this);
|
|
super.onDisable();
|
|
}
|
|
|
|
/** 第4章结束剧情后:角色升级引导完成时再指丧尸农场入口(与 UIPanelHome 原 guide4 一致) */
|
|
private onCh4FarmOutlineGuide(): void {
|
|
|
|
const layer = this.getMainUiContentLayer();
|
|
const panelHome = layer?.getChildByName('PanelHome');
|
|
const btnOutLine = panelHome && find('ui_center/btnOutLine', panelHome);
|
|
if (!btnOutLine?.isValid) return;
|
|
gg.ui.openPanel(UIID.NewGuideMask, {
|
|
data: [
|
|
[btnOutLine],
|
|
[''],
|
|
() => { },
|
|
true,
|
|
255
|
|
]
|
|
});
|
|
}
|
|
|
|
async onInit(): Promise<void> {
|
|
gg.audio.playMusic({ name: "主页背景音", path: "bgm/" });
|
|
this.updateUI();
|
|
let pageID = UIID.Home;
|
|
if (this.prema != null && this.prema != undefined)
|
|
pageID = this.prema;
|
|
await this.showPage(pageID);
|
|
gg.game.hideLoading();
|
|
}
|
|
|
|
private _curentID: UIID = null;
|
|
|
|
/** 底部 Tab 切换串行:避免武器页 openPanel 尚未完成又切回战斗/主页,渲染仍访问已隐藏或半加载的 Sprite,真机报 getGFXTexture 空引用 */
|
|
private _showPageChain: Promise<void> = Promise.resolve();
|
|
|
|
showPage(pageID: UIID, notCheck = false): Promise<void> {
|
|
|
|
if (!notCheck && !gg.newFun.isUnLockMainPageTab(pageID)) {
|
|
let conf = gg.newFun.getNewFunData(NewFunType.MainPageTab, pageID);
|
|
gg.ui.showToast(gg.lang.get('通关第{1}章节解锁', [conf.chapter]), false);
|
|
return Promise.resolve();
|
|
}
|
|
|
|
if (pageID == this._curentID) return Promise.resolve();
|
|
this._curentID = pageID;
|
|
|
|
// 智能预测预载:邻接 Tab +(Home 时)战斗包;切走/内存压力由 SmartPreload 统一调度
|
|
if (UIMainUI.MAIN_TAB_IDS.indexOf(pageID) >= 0) {
|
|
SmartPreload.onMainTab(pageID);
|
|
}
|
|
|
|
// this.ui_btns.children.map(c => c.find("select").active = false);
|
|
// this.ui_btns.find("btn" + pageID).find("select").active = true;
|
|
|
|
//设置选择spine1位置
|
|
let posi = this.ui_select.position.toVec2();
|
|
posi.x = this.ui_btns.getChildByName("btn" + pageID).position.x;
|
|
this.ui_select.x = posi.x
|
|
//end
|
|
|
|
this._showPageChain = this._showPageChain
|
|
.then(() => this._showPageImpl(pageID))
|
|
.catch((e) => console.error("[UIMainUI] showPage", e));
|
|
return this._showPageChain;
|
|
}
|
|
|
|
private async _showPageImpl(pageID: UIID): Promise<void> {
|
|
// 排队期间用户已点其它 Tab:放弃本次,避免与当前意图不一致的 openPanel/hide
|
|
if (this._curentID !== pageID) return;
|
|
|
|
// 目标页已存在时先显示;勿在 openPanel 完成前隐藏当前页,避免合批仍访问已释放 SpriteFrame
|
|
this.setMainTabPageActive(pageID, true);
|
|
await gg.ui.openPanel(pageID, { showLoading: 1 });
|
|
if (this._curentID !== pageID) return;
|
|
this.hideOtherMainTabPagesExcept(pageID);
|
|
}
|
|
|
|
/** 主界面子页挂在 Canvas/root/MainUI 下,节点名与 UIConfigs 中 prefab name 一致;只改 active,不碰其它脚本 */
|
|
private getPanelHome(): UIPanelHome | null {
|
|
const layer = this.getMainUiContentLayer();
|
|
const node = layer?.getChildByName('PanelHome');
|
|
return node?.getComponent(UIPanelHome) ?? null;
|
|
}
|
|
|
|
private getMainUiContentLayer(): Node | null {
|
|
const scene = director.getScene();
|
|
if (!scene?.isValid) return null;
|
|
const canvas = scene.getChildByName('Canvas');
|
|
const root = canvas?.getChildByName('root');
|
|
return root?.getChildByName('MainUI') ?? null;
|
|
}
|
|
|
|
/** 底部 Tab 壳子(UIMainUI 组件)挂在 root/Menu/MainUI,与内容层 root/MainUI/* 不同 */
|
|
static resolveShell(): UIMainUI | null {
|
|
const scene = director.getScene();
|
|
if (!scene?.isValid) return null;
|
|
const menu = scene.getChildByName('Canvas')
|
|
?.getChildByName('root')
|
|
?.getChildByName('Menu');
|
|
return menu?.getChildByName('MainUI')?.getComponent(UIMainUI) ?? null;
|
|
}
|
|
|
|
private hideOtherMainTabPagesExcept(showId: UIID) {
|
|
const layer = this.getMainUiContentLayer();
|
|
if (!layer?.isValid) return;
|
|
for (const id of UIMainUI.MAIN_TAB_IDS) {
|
|
const conf = UIConfigs[id];
|
|
if (!conf) continue;
|
|
const page = layer.getChildByName(conf.name);
|
|
if (page?.isValid) {
|
|
page.active = id === showId;
|
|
}
|
|
}
|
|
}
|
|
|
|
private setMainTabPageActive(pageID: UIID, active: boolean): void {
|
|
const layer = this.getMainUiContentLayer();
|
|
if (!layer?.isValid) return;
|
|
const conf = UIConfigs[pageID];
|
|
if (!conf) return;
|
|
const page = layer.getChildByName(conf.name);
|
|
if (page?.isValid) {
|
|
page.active = active;
|
|
}
|
|
}
|
|
|
|
protected update(dt: number): void {
|
|
//在主场景时,暂定每60帧刷新一次红点系统。
|
|
if (director.getTotalFrames() % 60 == 0)
|
|
gg.dot.updateRedDot();
|
|
}
|
|
|
|
updateUI() {
|
|
//修改ui
|
|
|
|
this.btn200.find("select").active = gg.newFun.isUnLockMainPageTab(UIID.Shop);
|
|
this.btn201.find("select").active = gg.newFun.isUnLockMainPageTab(UIID.Role);
|
|
this.btn203.find("select").active = gg.newFun.isUnLockMainPageTab(UIID.Weapon);
|
|
this.btn204.find("select").active = gg.newFun.isUnLockMainPageTab(UIID.Replica);
|
|
this.btn101.find("select").active = gg.newFun.isUnLockMainPageTab(UIID.Home);
|
|
//end
|
|
}
|
|
|
|
click_btn200(): void {
|
|
this.showPage(UIID.Shop);
|
|
}
|
|
|
|
click_btn201(): void {
|
|
this.showPage(UIID.Role);
|
|
}
|
|
|
|
click_btn101(): void {
|
|
this.showPage(UIID.Home);
|
|
}
|
|
|
|
click_btn203(): void {
|
|
|
|
this.showPage(UIID.Weapon);
|
|
}
|
|
|
|
click_btn204(): void {
|
|
this.showPage(UIID.Replica);
|
|
}
|
|
|
|
showLiulianGuide(){
|
|
|
|
if(gg.data.getStatistics(StatisticsType.LiulianGuideIndex) == 1){
|
|
gg.sdk.reportDY("inLevel", `章节1_5-引导点击武器页签!`);
|
|
let toggle = this.btn203
|
|
gg.ui.openPanel(UIID.NewGuideMask, {
|
|
data: [
|
|
[toggle],
|
|
[gg.lang.get('现在我们去装备榴莲')],
|
|
() => {
|
|
|
|
gg.data.setStatistics(StatisticsType.LiulianGuideIndex, 2)
|
|
},
|
|
true,
|
|
255
|
|
]
|
|
})
|
|
}else if(gg.data.getStatistics(StatisticsType.LiulianGuideIndex) == 5){
|
|
//引导点击战斗
|
|
gg.sdk.reportDY("inLevel", `章节1_5-引导点击回到战斗!`);
|
|
let toggle = this.btn101
|
|
gg.ui.openPanel(UIID.NewGuideMask, {
|
|
data: [
|
|
[toggle],
|
|
[''],
|
|
() => {
|
|
gg.data.setStatistics(StatisticsType.LiulianGuideIndex,6)
|
|
this.scheduleOnce(()=>{
|
|
GEvent.Ins.emit(GEvent.LiulianGuideIndexEvent)
|
|
},0.2)
|
|
|
|
},
|
|
true,
|
|
255
|
|
]
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
showGuideNew(){
|
|
if (gg.data.getStatistics(StatisticsType.homeGuideIndex) == 1) {
|
|
this.guideClickBtn203()
|
|
} else if (gg.data.getStatistics(StatisticsType.homeGuideIndex) == 3) {
|
|
this.guideClickBtn101()
|
|
} else if (gg.data.getStatistics(StatisticsType.homeGuideIndex) == 4) {
|
|
this.guideClickBtn201()
|
|
}else if(gg.data.getStatistics(StatisticsType.homeGuideIndex) == 6){
|
|
this.guideClickBtn101_2()
|
|
}
|
|
}
|
|
showGuide() {
|
|
if (gg.data.getStatistics(StatisticsType.homeGuideIndex) == 1) {
|
|
// if(gg.data.getStatistics(StatisticsType.LiulianGuideIndex) == 1){
|
|
// //不引导
|
|
// console.log('已经引导了榴莲,不引导升级');
|
|
// }else{
|
|
|
|
// }
|
|
this.guideClickBtn203()
|
|
} else if (gg.data.getStatistics(StatisticsType.homeGuideIndex) == 4) {
|
|
// 第三章后剧情等:强制出「点角色」(不依赖 doc.chapter)
|
|
if (gg.game.forceHomeRoleTabGuide) {
|
|
gg.game.forceHomeRoleTabGuide = false;
|
|
this.guideClickBtn201();
|
|
return;
|
|
}
|
|
// 武器链:已通关第3章(下一关进度>=4)才引角色;否则结束本段并只走一次队列
|
|
if (gg.data.doc.chapter >= 4) {
|
|
this.guideClickBtn201();
|
|
} else {
|
|
|
|
gg.data.setStatistics(StatisticsType.homeGuideIndex, 6);
|
|
const ph = this.getPanelHome();
|
|
if (ph?.isValid) {
|
|
ph.scheduleHomeOverlayFromGuide();
|
|
} else {
|
|
this.scheduleOnce(() => gg.newFun.checkNewFunPop(), 0);
|
|
}
|
|
}
|
|
} else if (gg.data.getStatistics(StatisticsType.homeGuideIndex) == 3) {
|
|
this.guideClickBtn101()
|
|
}else if (gg.data.getStatistics(StatisticsType.homeGuideIndex) == 11) {
|
|
this.guideClickBtn201_2()
|
|
}
|
|
}
|
|
|
|
guideClickBtn201_2(){
|
|
let toggle = this.btn201
|
|
gg.ui.openPanel(UIID.NewGuideMask, {
|
|
data: [
|
|
[toggle],
|
|
[],
|
|
() => {
|
|
|
|
gg.data.setStatistics(StatisticsType.homeGuideIndex, 12)
|
|
|
|
},
|
|
true,
|
|
255
|
|
]
|
|
})
|
|
}
|
|
/**引导点击角色 */
|
|
guideClickBtn201(){
|
|
let toggle = this.btn201
|
|
gg.ui.openPanel(UIID.NewGuideMask, {
|
|
data: [
|
|
[toggle],
|
|
[gg.lang.get('角色属性模块解锁了,现在可以去升级角色了')],
|
|
() => {
|
|
|
|
gg.data.setStatistics(StatisticsType.homeGuideIndex, 5)
|
|
GEvent.Ins.emit(GEvent.homeGuideIndexEventEnd)
|
|
|
|
},
|
|
true,
|
|
255
|
|
]
|
|
})
|
|
}
|
|
/**引导点击升级武器 */
|
|
guideClickBtn203(){
|
|
let toggle = this.btn203
|
|
gg.ui.openPanel(UIID.NewGuideMask, {
|
|
data: [
|
|
[toggle],
|
|
[gg.lang.get('现在可以去升级武器了')],
|
|
() => {
|
|
|
|
gg.data.setStatistics(StatisticsType.homeGuideIndex, 2)
|
|
},
|
|
true,
|
|
255
|
|
]
|
|
})
|
|
}
|
|
/**引导点击战斗 */
|
|
guideClickBtn101(){
|
|
let toggle = this.btn101
|
|
gg.ui.openPanel(UIID.NewGuideMask, {
|
|
data: [
|
|
[toggle],
|
|
[''],
|
|
() => {
|
|
|
|
gg.data.setStatistics(StatisticsType.homeGuideIndex, 4)
|
|
//显示战斗按钮上的手机点击
|
|
|
|
this.scheduleOnce(()=>{
|
|
const ph = this.getPanelHome();
|
|
if (ph?.isValid) {
|
|
ph.showStartBtnFinger();
|
|
}
|
|
},0.2)
|
|
},
|
|
true,
|
|
255
|
|
]
|
|
})
|
|
}
|
|
|
|
/**引导点击战斗 */
|
|
guideClickBtn101_2(){
|
|
let toggle = this.btn101
|
|
gg.ui.openPanel(UIID.NewGuideMask, {
|
|
data: [
|
|
[toggle],
|
|
[''],
|
|
() => {
|
|
|
|
gg.data.setStatistics(StatisticsType.homeGuideIndex, 7)
|
|
//显示战斗按钮上的手机点击
|
|
|
|
this.scheduleOnce(()=>{
|
|
const ph = this.getPanelHome();
|
|
if (ph?.isValid) {
|
|
ph.showStartBtnFinger();
|
|
}
|
|
},0.2)
|
|
},
|
|
true,
|
|
255
|
|
]
|
|
})
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|