47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { _decorator, Component, Enum, Label } from "cc";
|
|
|
|
import { EventManager } from "@max-studio/core/event/EventManager";
|
|
import UIManager from "@max-studio/core/ui/UIManager";
|
|
import LogUtils from "@max-studio/core/utils/LogUtils";
|
|
|
|
import { ShopUI } from "../../uis/ShopUI";
|
|
import { CurrencyManager } from "../CurrencyManager";
|
|
import { CurrencyEventMessage, CurrencyType } from "../Types";
|
|
import { onEvent } from "@max-studio/core/decorators";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("CurrencyItem")
|
|
export class CurrencyItem extends Component {
|
|
@property({ type: Enum(CurrencyType) })
|
|
public type: CurrencyType = CurrencyType.ENERGY;
|
|
|
|
@property(Label)
|
|
public label: Label = null!;
|
|
|
|
protected onLoad(): void {
|
|
this.node.onClick(this.onGotoCurrencyShop, this);
|
|
}
|
|
|
|
private onGotoCurrencyShop() {
|
|
LogUtils.log("点击了货币商店:", this.type);
|
|
void UIManager.getInstance().openUI(ShopUI, this.type);
|
|
}
|
|
|
|
@onEvent(CurrencyEventMessage.CURRENCY_VALUE_CHANGED)
|
|
private onCurrencyValueChanged(type: CurrencyType, value: number) {
|
|
if (type !== this.type) {
|
|
return;
|
|
}
|
|
this.label.string = CurrencyManager.getInstance().formatCurrencyDisplay(this.type, value);
|
|
}
|
|
|
|
protected onDestroy(): void {
|
|
EventManager.getInstance().off(CurrencyEventMessage.CURRENCY_VALUE_CHANGED, this.onCurrencyValueChanged, this);
|
|
}
|
|
|
|
protected start(): void {
|
|
this.label.string = CurrencyManager.getInstance().formatCurrencyDisplay(this.type);
|
|
}
|
|
}
|