137 lines
3.7 KiB
TypeScript
137 lines
3.7 KiB
TypeScript
import {
|
|
_decorator,
|
|
Component,
|
|
Node,
|
|
Label,
|
|
Sprite,
|
|
Button,
|
|
tween,
|
|
Vec3,
|
|
} from "cc";
|
|
import Utils from "../../../Main/Common/Utils";
|
|
import li_BaseView from "../../../Main/Common/li_BaseView";
|
|
import { GButton } from "../../../Main/Common/GButton";
|
|
import PlayerDataManager from "../../../Main/Manager/PlayerDataManager";
|
|
import { DataManager, DataId } from "../../data/DataManager";
|
|
import { PlayerData } from "../../data/PlayerData";
|
|
import { AccountData } from "../../data/AccountData";
|
|
import { WalletData } from "../../data/WalletData";
|
|
import LanguageUtils, {
|
|
LanguageType,
|
|
} from "../../../Main/Common/LanguageUtils";
|
|
import AudioManager from "../../../Main/Manager/AudioManager";
|
|
import { NavigationManager } from "../../manager/NavigationManager";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("PersonalPanel")
|
|
export class PersonalPanel extends li_BaseView {
|
|
private _nodeTab: any = {};
|
|
|
|
@property(Label)
|
|
private userNameLabel: Label = null;
|
|
|
|
@property(Label)
|
|
private userIdLabel: Label = null;
|
|
|
|
@property(Label)
|
|
private balanceLabel: Label = null;
|
|
|
|
@property(Label)
|
|
private vipStatusLabel: Label = null;
|
|
|
|
@property(Sprite)
|
|
private avatarSprite: Sprite = null;
|
|
|
|
private playerData: PlayerData = null;
|
|
private accountData: AccountData = null;
|
|
private walletData: WalletData = null;
|
|
|
|
protected start(): void {
|
|
Utils.parseNode(this.node, this._nodeTab);
|
|
this.initUI();
|
|
this.registerListener();
|
|
this.refresh();
|
|
}
|
|
|
|
onEnable() {
|
|
this.initData();
|
|
|
|
this.refresh();
|
|
}
|
|
|
|
private initData(): void {
|
|
this.playerData = DataManager.I.getDataById<PlayerData>(DataId.Player);
|
|
this.accountData = DataManager.I.getDataById<AccountData>(DataId.Account);
|
|
this.walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
|
}
|
|
|
|
private initUI(): void {}
|
|
|
|
private registerListener(): void {
|
|
// 注册关闭按钮
|
|
if (this._nodeTab.closeBtn) {
|
|
GButton.BandClick(this._nodeTab.closeBtn, this.close, this);
|
|
}
|
|
if (this._nodeTab.WalletBtn) {
|
|
GButton.BandClick(this._nodeTab.WalletBtn, this.openPurchase, this);
|
|
}
|
|
|
|
// 注册设置按钮
|
|
if (this._nodeTab.settingBtn) {
|
|
GButton.BandClick(this._nodeTab.settingBtn, this.openSettings, this);
|
|
}
|
|
}
|
|
|
|
private refresh(): void {
|
|
this.updateUserInfo();
|
|
this.updateBalance();
|
|
this.updateVipStatus();
|
|
}
|
|
|
|
private updateUserInfo(): void {
|
|
// 更新用户名
|
|
if (this.userNameLabel && this.playerData) {
|
|
const userName = this.playerData.name || "未设置";
|
|
this.userNameLabel.string = userName;
|
|
}
|
|
|
|
// 更新用户ID
|
|
if (this.userIdLabel && this.accountData) {
|
|
const userId = this.accountData.accId || "游客";
|
|
this.userIdLabel.string = `uid: ${userId}`;
|
|
}
|
|
|
|
// 头像暂时留空,等待资源配置
|
|
if (this.avatarSprite) {
|
|
// TODO: 设置默认头像或从数据中获取头像
|
|
}
|
|
}
|
|
|
|
private updateBalance(): void {
|
|
if (this.balanceLabel && this.walletData) {
|
|
const balance = this.walletData.getOriginalBalance();
|
|
this.balanceLabel.string = `余额: ${balance}`;
|
|
}
|
|
}
|
|
|
|
private updateVipStatus(): void {
|
|
if (this.vipStatusLabel && this.walletData) {
|
|
const vipExpire = this.walletData.vipExpire;
|
|
if (vipExpire && vipExpire > Date.now()) {
|
|
const expireDate = new Date(vipExpire);
|
|
this.vipStatusLabel.string = `VIP至: ${expireDate.toLocaleDateString()}`;
|
|
} else {
|
|
this.vipStatusLabel.string = "普通用户";
|
|
}
|
|
}
|
|
}
|
|
|
|
private openSettings(): void {
|
|
// TODO: 打开设置面板
|
|
NavigationManager.Instance.openSubPanel("SettingPanel", this.node);
|
|
}
|
|
private openPurchase() {
|
|
NavigationManager.Instance.openSubPanel("PurchasePanel", this.node);
|
|
}
|
|
}
|