MatchMaster/assets/propWindow/script/PropWindowPanel.ts
2026-08-28 19:21:40 +08:00

39 lines
1.0 KiB
TypeScript

const { ccclass } = cc._decorator;
type PropWindowAction = (event?: cc.Event, customEventData?: string) => void;
interface PropWindowActions {
[name: string]: PropWindowAction;
}
/** propWindow prefab 的按钮桥接层。 */
@ccclass
export default class PropWindowPanel extends cc.Component {
private actions: PropWindowActions = null;
bind(actions: PropWindowActions) {
this.actions = actions || {};
}
clickBtn(event?: cc.Event, customEventData?: string) {
this.invoke("clickBtn", event, customEventData);
}
closePropBuy(event?: cc.Event, customEventData?: string) {
this.invoke("closePropBuy", event, customEventData);
}
private invoke(name: string, event?: cc.Event, customEventData?: string) {
const action = this.actions && this.actions[name];
if (action) {
action(event, customEventData);
return;
}
cc.warn("PropWindowPanel action is not bound:", name);
}
onDestroy() {
this.actions = null;
}
}