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

@@ -19,7 +19,7 @@ Git 历史采用 Conventional Commits且摘要多为中文例如 `feat:
<claude-mem-context>
# Memory Context
# $CMEM mp-xieyingeng 2026-05-01 10:06am GMT+8
# $CMEM mp-xieyingeng 2026-05-03 10:02pm GMT+8
Legend: 🎯session 🔴bugfix 🟣feature 🔄refactor ✅change 🔵discovery ⚖decision
Format: ID TIME TYPE TITLE

View File

@@ -277,7 +277,7 @@
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 547.853,
"y": 567.633,
"z": 0
},
"_lrot": {
@@ -392,7 +392,7 @@
"_target": null,
"_left": 0,
"_right": 0,
"_top": 375.64700000000005,
"_top": 355.86699999999996,
"_bottom": 0,
"_horizontalCenter": 0,
"_verticalCenter": 0,
@@ -459,7 +459,7 @@
"_lpos": {
"__type__": "cc.Vec3",
"x": -385.125,
"y": 779.698,
"y": 814.17,
"z": 0
},
"_lrot": {
@@ -1374,7 +1374,7 @@
"_target": null,
"_left": 0,
"_right": 0,
"_top": 250.30200000000002,
"_top": 215.83000000000004,
"_bottom": 0,
"_horizontalCenter": 0,
"_verticalCenter": 0,
@@ -1441,7 +1441,7 @@
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 53.53600000000006,
"y": 80.73400000000004,
"z": 0
},
"_lrot": {
@@ -1599,6 +1599,8 @@
"__id__": 0
},
"fileId": "43e1eZSk1K6rzr0HNnSI5f",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
@@ -1848,12 +1850,12 @@
"__prefab": {
"__id__": 78
},
"_alignFlags": 1,
"_alignFlags": 4,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 733.9639999999999,
"_bottom": 0,
"_bottom": 868.234,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
@@ -5398,6 +5400,8 @@
"__id__": 0
},
"fileId": "72VhslaLdGP6Y9ElOd+nNP",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
@@ -6026,6 +6030,18 @@
"liveLabel": {
"__id__": 41
},
"levelLabel": {
"__id__": 70
},
"titleProgressBar": {
"__id__": 220
},
"progressLabel": {
"__id__": 226
},
"progressAnchor": {
"__id__": 229
},
"_id": ""
},
{

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);
}
/**
* 页面隐藏时调用
*/