feat: 首页接入成就系统

This commit is contained in:
richarjiang
2026-05-03 22:07:22 +08:00
parent 0127013bae
commit 7249df8c22
3 changed files with 112 additions and 9 deletions

View File

@@ -1,10 +1,12 @@
import { _decorator, Node, Button, Label, tween, Vec3, UIOpacity, UITransform, Color, instantiate } from 'cc';
import { _decorator, Node, Button, Label, tween, Vec3, UIOpacity, UITransform, Color, instantiate, ProgressBar } from 'cc';
import { BaseView } from 'db://assets/scripts/core/BaseView';
import { ViewManager } from 'db://assets/scripts/core/ViewManager';
import { WxSDK, checkPrivacySetting, requirePrivacyAuthorize } from 'db://assets/scripts/utils/WxSDK';
import { StaminaManager } from 'db://assets/scripts/utils/StaminaManager';
import { ToastManager } from 'db://assets/scripts/utils/ToastManager';
import { StaminaInfo } from 'db://assets/scripts/types/ApiTypes';
import { AuthManager } from 'db://assets/scripts/utils/AuthManager';
import { AchievementTitleManager } from 'db://assets/scripts/utils/AchievementTitleManager';
const { ccclass, property } = _decorator;
/**
@@ -26,6 +28,22 @@ export class PageHome extends BaseView {
@property(Label)
liveLabel: Label | null = null;
/** 首页主称号文本 */
@property(Label)
levelLabel: Label | null = null;
/** 称号进度条 */
@property(ProgressBar)
titleProgressBar: ProgressBar | null = null;
/** 称号进度提示文案 */
@property(Label)
progressLabel: Label | null = null;
/** 称号进度游标 */
@property(Node)
progressAnchor: Node | null = null;
/** 飞行动画持续时间(秒) */
private static readonly FLY_DURATION = 0.5;
@@ -41,11 +59,16 @@ export class PageHome extends BaseView {
/** 是否正在播放体力消耗动画 */
private _isAnimating: boolean = false;
/** 进度游标 0% 时的本地 X 坐标,使用 prefab 当前摆放位置作为起点 */
private _progressAnchorStartX: number | null = null;
/**
* 页面首次加载时调用
*/
onViewLoad(): void {
console.log('[PageHome] onViewLoad');
this._cacheProgressAnchorStartX();
this.updateAchievementTitleInfo();
this._initButtons();
this._initWxShare();
// 检查隐私授权
@@ -302,6 +325,7 @@ export class PageHome extends BaseView {
onViewShow(): void {
console.log('[PageHome] onViewShow');
this.updateStaminaLabel();
this.updateAchievementTitleInfo();
// 保险恢复:防止动画中途被打断导致 IconLive 隐藏残留
const iconLive = this._findIconLive();
@@ -328,6 +352,69 @@ export class PageHome extends BaseView {
}
}
/**
* 更新首页称号进度区域
*/
private updateAchievementTitleInfo(): void {
const titleInfo = AchievementTitleManager.getTitleInfo(AuthManager.instance.completedLevelCount);
const progress = this._normalizeProgress(titleInfo.nextTitleProgress);
if (this.levelLabel) {
this.levelLabel.string = titleInfo.titleText;
}
if (this.titleProgressBar) {
this.titleProgressBar.progress = progress;
}
if (this.progressLabel) {
this.progressLabel.string = titleInfo.progressText;
}
this._updateProgressAnchor(progress);
}
private _cacheProgressAnchorStartX(): void {
if (this._progressAnchorStartX !== null || !this.progressAnchor) {
return;
}
this._progressAnchorStartX = this.progressAnchor.position.x;
}
private _updateProgressAnchor(progress: number): void {
if (!this.progressAnchor) {
return;
}
this._cacheProgressAnchorStartX();
const startX = this._progressAnchorStartX ?? this.progressAnchor.position.x;
const travelWidth = this._getProgressAnchorTravelWidth();
this.progressAnchor.setPosition(startX + travelWidth * progress, this.progressAnchor.position.y, this.progressAnchor.position.z);
const percentLabel = this.progressAnchor.getChildByName('Label')?.getComponent(Label);
if (percentLabel) {
percentLabel.string = `${Math.round(progress * 100)}%`;
}
}
private _getProgressAnchorTravelWidth(): number {
if (!this.titleProgressBar) {
return 0;
}
return Math.abs(this.titleProgressBar.totalLength * this.titleProgressBar.node.scale.x);
}
private _normalizeProgress(progress: number): number {
if (!Number.isFinite(progress) || progress <= 0) {
return 0;
}
return Math.min(1, progress);
}
/**
* 页面隐藏时调用
*/