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.
308 lines
10 KiB
308 lines
10 KiB
|
|
//*********************
|
|
// create by 流云
|
|
// time: Tue Aug 18 2026
|
|
// desc:
|
|
//*********************
|
|
import { _decorator, Button, isValid, Label, sp } from 'cc';
|
|
import { Auto_PanelHome } from './Auto_PanelHome';
|
|
import { UIID } from '../../game/ConfigRes';
|
|
import { ItemNumType, StatusType } from '../../game/GameData';
|
|
import { ItemData } from '../../game/ConfigProjectData';
|
|
import { EmolumentDataManager } from '../../manager/EmolumentDataManager';
|
|
import { RankDataManager } from '../../manager/RankDataManager';
|
|
import { sdkConfig } from '../../sdk/sdkConfig';
|
|
import { GEvent } from 'db://assets/mx/module/event/GEvent';
|
|
import { BattleSpinePlayback } from 'db://assets/script/battle/presentation/BattleSpinePlayback';
|
|
import { EmolumentCoinFlySource, PanelHomeEmolumentCoinFlyPresenter } from './PanelHomeEmolumentCoinFlyPresenter';
|
|
import { PanelHomeStartVigourFlyPresenter } from './PanelHomeStartVigourFlyPresenter';
|
|
import { MiniGamePf } from 'db://assets/mx/tools/MiniGameHostInfo';
|
|
import { VivoAd } from '../../sdk/functions/VivoAd';
|
|
|
|
const { ccclass } = _decorator;
|
|
|
|
/** 首页关卡 Spine 可随机动画 */
|
|
const CHAPTER_SPINE_ANIMS = ['动画1', '动画2', '动画3'] as const;
|
|
/** btnStart 体力底与数量 Label 节点名 */
|
|
const START_POWER_BG_NODE = 'powerBg';
|
|
const START_POWER_LABEL_NODE = 'lb_power';
|
|
|
|
@ccclass('UIPanelHome')
|
|
export class UIPanelHome extends Auto_PanelHome {
|
|
|
|
/** 开始游戏:体力影子飞向按钮 */
|
|
private readonly _startVigourFly = new PanelHomeStartVigourFlyPresenter();
|
|
/** 俸禄领取:金币影子飞向 ui_money */
|
|
private readonly _emolumentCoinFly = new PanelHomeEmolumentCoinFlyPresenter();
|
|
/** 桌面礼包弹窗打开中,防重复 */
|
|
private _deskGiftOpen = false;
|
|
|
|
onLoad(): void {
|
|
super.onLoad();
|
|
this._refreshStartVigourCost();
|
|
}
|
|
|
|
start(): void {
|
|
this._refreshStartVigourCost();
|
|
}
|
|
|
|
onEnable(): void {
|
|
super.onEnable();
|
|
this._startVigourFly.bind(this.node, this.ui_vigour, this.btnStart);
|
|
this._emolumentCoinFly.bind(this.node, this.ui_money);
|
|
this._setBtnStartInteractable(true);
|
|
GEvent.Ins.on(GEvent.UpdateRankStars, this._refreshRankDisplay, this);
|
|
GEvent.Ins.on(GEvent.PLATFORM_SHOW, this._tryClaimDeskGift, this);
|
|
this._refreshRankDisplay();
|
|
this._refreshStartVigourCost();
|
|
gg.dot?.updateRedDot();
|
|
this._scheduleEmolumentPopCheck();
|
|
VivoAd.showBanner();
|
|
}
|
|
|
|
onDisable(): void {
|
|
GEvent.Ins.off(GEvent.UpdateRankStars, this._refreshRankDisplay, this);
|
|
GEvent.Ins.off(GEvent.PLATFORM_SHOW, this._tryClaimDeskGift, this);
|
|
VivoAd.hideBanner();
|
|
this._startVigourFly.unbind();
|
|
this._emolumentCoinFly.unbind();
|
|
this._setBtnStartInteractable(true);
|
|
super.onDisable();
|
|
}
|
|
|
|
/** 刷新段位昵称图与星条 */
|
|
private _refreshRankDisplay = (): void => {
|
|
void RankDataManager.applyRankLevelIconToNodeAsync(this.ui_rankLevelName);
|
|
this._refreshStarBg();
|
|
};
|
|
|
|
/** 按总星数对 5 取余点亮 ui_starBg 下 star0~star4 */
|
|
private _refreshStarBg(): void {
|
|
if (!this.ui_starBg?.isValid) {
|
|
console.log('[UIPanelHome] ui_starBg 缺失');
|
|
return;
|
|
}
|
|
const lay = this.ui_starBg.getChildByName('lay');
|
|
if (!lay?.isValid) {
|
|
console.log('[UIPanelHome] ui_starBg 缺少 lay');
|
|
return;
|
|
}
|
|
const count = RankDataManager.getStarModCount();
|
|
for (let i = 0; i < 5; i++) {
|
|
const slot = lay.getChildByName(`star${i}`);
|
|
if (!slot?.isValid) {
|
|
console.log('[UIPanelHome] 星槽缺失', `star${i}`);
|
|
continue;
|
|
}
|
|
slot.active = true;
|
|
const icon = slot.getChildByName('star');
|
|
if (!icon?.isValid) {
|
|
console.log('[UIPanelHome] 星图标缺失', `star${i}`);
|
|
continue;
|
|
}
|
|
icon.active = i < count;
|
|
}
|
|
}
|
|
|
|
|
|
onInit(): void {
|
|
this.btnAddDesk.active = false;
|
|
this.btnSidebar.active = false;
|
|
if (sdkConfig.config.showAddToDesk) {
|
|
gg.sdk.checkNeedShowAddShortcut(this._onAddDeskAvail);
|
|
}
|
|
if (sdkConfig.config.showSidebar) {
|
|
gg.sdk.checkSidebar(this._onSidebarAvail);
|
|
}
|
|
this._refreshRankDisplay();
|
|
this._refreshStartVigourCost();
|
|
this._scheduleEmolumentPopCheck();
|
|
|
|
if (gg.data.IsFirstLogin && !gg.game.isFinishGuide) {
|
|
gg.game.isFinishGuide = true;
|
|
this.ui_guide.active = true;
|
|
} else {
|
|
this.ui_guide.active = false;
|
|
}
|
|
}
|
|
|
|
/** 添加桌面入口是否展示 */
|
|
private _onAddDeskAvail = (ok: boolean): void => {
|
|
if (!this.isValid) return;
|
|
this.btnAddDesk.active = !!ok;
|
|
};
|
|
|
|
/** 侧边栏入口是否展示 */
|
|
private _onSidebarAvail = (ok: boolean): void => {
|
|
if (!this.isValid) return;
|
|
this.btnSidebar.active = !!ok;
|
|
};
|
|
|
|
/** Home 首帧展示完成后再判俸禄弹窗(避免 loading 未关时弹出) */
|
|
private _scheduleEmolumentPopCheck(): void {
|
|
this.scheduleOnce(this._onHomeEnterEmolumentPop, 0);
|
|
}
|
|
|
|
private _onHomeEnterEmolumentPop = (): void => {
|
|
if (!this.isValid) return;
|
|
EmolumentDataManager.tryPopPanelIfNeeded();
|
|
this._tryClaimDeskGift();
|
|
};
|
|
|
|
/**
|
|
* B 站从桌面快捷方式进入:每日一次金币礼包(与侧边栏礼包同额)
|
|
*/
|
|
private _tryClaimDeskGift = (): void => {
|
|
if (!this.isValid) return;
|
|
if (!gg.sdk.isFromDesk()) return;
|
|
if (gg.data.getStatus(StatusType.DeskGiftGetFinish) === 1) return;
|
|
if (this._deskGiftOpen) return;
|
|
this._deskGiftOpen = true;
|
|
const item = new ItemData(ItemNumType.money, 20);
|
|
gg.ui.openPanel(UIID.GetReward, {
|
|
data: [item],
|
|
onClose: this._onDeskGiftClosed,
|
|
});
|
|
};
|
|
|
|
/** 桌面礼包弹窗关闭后记已领 */
|
|
private _onDeskGiftClosed = (): void => {
|
|
this._deskGiftOpen = false;
|
|
gg.data.setStatus(StatusType.DeskGiftGetFinish, 1);
|
|
};
|
|
|
|
/** 俸禄领取后:PopEmolument 起点金币影子飞向顶栏 */
|
|
playEmolumentCoinFly(sources: EmolumentCoinFlySource[]): void {
|
|
this.scheduleOnce(() => {
|
|
if (!this.isValid) return;
|
|
this._emolumentCoinFly.play(sources);
|
|
}, 0);
|
|
}
|
|
|
|
/** 添加桌面快捷方式 */
|
|
click_btnAddDesk(): void {
|
|
gg.sdk.addShortcut((res) => {
|
|
if (res) {
|
|
gg.sdk.reportDY("inLevel", `首页-添加桌面`);
|
|
gg.ui.showToast(MiniGamePf.isBl() ? "添加成功,明天从桌面进入可领取礼包" : "添加成功");
|
|
} else {
|
|
gg.ui.showToast("添加失败");
|
|
}
|
|
});
|
|
}
|
|
|
|
/** 打开投诉面板 */
|
|
click_btnFeedback(): void {
|
|
gg.ui.openPanel(UIID.Complain);
|
|
}
|
|
|
|
/** 打开更新公告弹窗 */
|
|
click_btnNotice(): void {
|
|
gg.ui.openPanel(UIID.PopNotice);
|
|
}
|
|
|
|
/** 打开侧边栏面板 */
|
|
click_btnSidebar(): void {
|
|
gg.ui.openPanel(UIID.Sidebar);
|
|
}
|
|
|
|
click_ui_center_btnRank(): void {
|
|
this.click_btnRank();
|
|
}
|
|
|
|
click_ui_center_ui_RightBtns_btnRank(): void {
|
|
this.click_btnRank();
|
|
}
|
|
|
|
/** 打开排行榜(未授权也可进入;首次打开在面板内弹授权) */
|
|
click_btnRank(): void {
|
|
gg.ui.openPanel(UIID.Rank);
|
|
}
|
|
|
|
click_btnSetting(): void {
|
|
|
|
}
|
|
|
|
/** 打开神将武器页 */
|
|
click_btnWeapon(): void {
|
|
void gg.ui.openPanel(UIID.PanelGemstone);
|
|
}
|
|
|
|
/** 解析 btnStart/powerBg/lb_power */
|
|
private _resolveStartPowerLabel(): Label | null {
|
|
if (isValid(this.lb_power)) return this.lb_power;
|
|
const btn = this.btnStart;
|
|
if (!btn?.isValid) {
|
|
console.log('[UIPanelHome] btnStart 缺失,无法刷新 lb_power');
|
|
return null;
|
|
}
|
|
const powerBg = btn.getChildByName(START_POWER_BG_NODE);
|
|
if (!powerBg?.isValid) {
|
|
console.log('[UIPanelHome] btnStart 缺少', START_POWER_BG_NODE);
|
|
return null;
|
|
}
|
|
const lb = powerBg.getChildByName(START_POWER_LABEL_NODE)?.getComponent(Label) ?? null;
|
|
if (!lb) {
|
|
console.log('[UIPanelHome] powerBg 缺少', START_POWER_LABEL_NODE);
|
|
return null;
|
|
}
|
|
this.lb_power = lb;
|
|
return lb;
|
|
}
|
|
|
|
/** 刷新 btnStart 所需体力(Const 战斗体力消耗) */
|
|
private _refreshStartVigourCost(): void {
|
|
const lb = this._resolveStartPowerLabel();
|
|
if (!lb) return;
|
|
gg.data.project.syncBattleVigourCost();
|
|
const cost = gg.data.project.getBattleVigourCost();
|
|
if (cost <= 0) {
|
|
console.log('[UIPanelHome] 战斗体力消耗非法', cost);
|
|
lb.string = '';
|
|
return;
|
|
}
|
|
lb.string = `${cost}`;
|
|
}
|
|
|
|
/** 选本局 Level:校验体力 → 仅播飞行动画 → 匹配页 → 进战斗页成功后再扣体力 */
|
|
click_btnStart(): void {
|
|
if (this._startVigourFly.isPlaying()) return;
|
|
if (!gg.data.project.checkVigourEnough()) {
|
|
gg.ui.openPanel(UIID.buyPower);
|
|
return;
|
|
}
|
|
this._setBtnStartInteractable(false);
|
|
const levelId = RankDataManager.pickBattleLevelId();
|
|
if (!(levelId > 0)) {
|
|
this._setBtnStartInteractable(true);
|
|
return;
|
|
}
|
|
gg.game.CurentSelectLevelId = levelId;
|
|
const started = this._startVigourFly.play(this._onVigourFlyDone);
|
|
if (!started) {
|
|
this._onVigourFlyDone();
|
|
}
|
|
}
|
|
|
|
/** 体力飞完(或跳过动画)后开匹配页;notCheckPower 避免匹配加载阶段重复弹窗,真实扣费在 BattleGame 打开后 */
|
|
private _onVigourFlyDone = (): void => {
|
|
gg.game.enterBattleWithMatch({
|
|
notCheckPower: true,
|
|
onFail: this._onEnterMatchFail,
|
|
});
|
|
};
|
|
|
|
/** 匹配/进战失败且首页仍在:恢复开始按钮 */
|
|
private _onEnterMatchFail = (): void => {
|
|
if (!this.isValid) return;
|
|
this._setBtnStartInteractable(true);
|
|
};
|
|
|
|
/** 飘体力期间禁用 btnStart,避免重复触发 */
|
|
private _setBtnStartInteractable(enabled: boolean): void {
|
|
const btn = this.btnStart?.getComponent(Button);
|
|
if (btn) {
|
|
btn.interactable = enabled;
|
|
}
|
|
}
|
|
}
|
|
|