feat: 提交资源
This commit is contained in:
46
assets/games/scripts/currency/components/CurrencyItem.ts
Normal file
46
assets/games/scripts/currency/components/CurrencyItem.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8840c2d8-d822-482c-b68f-2a88cd9c8e72",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user