feat: 支持首页 UI

This commit is contained in:
richarjiang
2026-04-27 09:29:50 +08:00
parent 950572ad74
commit fbea31b9ea
22 changed files with 2201 additions and 506 deletions

View File

@@ -1,7 +1,10 @@
import { _decorator, Node, Button } from 'cc';
import { _decorator, Node, Button, Label } 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';
const { ccclass, property } = _decorator;
/**
@@ -10,12 +13,19 @@ const { ccclass, property } = _decorator;
*/
@ccclass('PageHome')
export class PageHome extends BaseView {
/** 默认体力上限 */
private static readonly DEFAULT_STAMINA_MAX = 50;
@property({ type: Node, tooltip: '开始游戏按钮' })
startGameBtn: Node | null = null;
@property({ type: Node, tooltip: 'PK按钮' })
pkBtn: Node | null = null;
/** 体力值显示标签 */
@property(Label)
liveLabel: Label | null = null;
/**
* 页面首次加载时调用
*/
@@ -85,7 +95,7 @@ export class PageHome extends BaseView {
*/
private _onPkClick(): void {
console.log('[PageHome] PK按钮点击');
ViewManager.instance.open('PageWriteLevels');
ToastManager.show('功能正在开发中,敬请期待吧!');
}
/**
@@ -93,6 +103,25 @@ export class PageHome extends BaseView {
*/
onViewShow(): void {
console.log('[PageHome] onViewShow');
this.updateStaminaLabel();
}
/**
* 获取体力上限
*/
private _getStaminaMax(stamina: StaminaInfo): number {
return typeof stamina.max === 'number' ? stamina.max : PageHome.DEFAULT_STAMINA_MAX;
}
/**
* 更新体力值显示
*/
private updateStaminaLabel(): void {
if (this.liveLabel) {
const stamina = StaminaManager.instance.getStamina();
const maxStamina = this._getStaminaMax(stamina);
this.liveLabel.string = `${stamina.current}/${maxStamina}`;
}
}
/**