58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
const { ccclass, executeInEditMode } = cc._decorator;
|
|
|
|
type PropWindowAction = (event?: cc.Event, customEventData?: string) => void;
|
|
|
|
interface PropWindowActions {
|
|
[name: string]: PropWindowAction;
|
|
}
|
|
|
|
/** propWindow prefab 的按钮桥接层。 */
|
|
@ccclass
|
|
@executeInEditMode
|
|
export default class PropWindowPanel extends cc.Component {
|
|
private actions: PropWindowActions = null;
|
|
|
|
onLoad() {
|
|
// The supplied panel texture starts at the rim; draw the two rounded ears behind it.
|
|
const prop = this.node.getChildByName("prop");
|
|
if (!prop || prop.getChildByName("panelEars")) return;
|
|
const ears = new cc.Node("panelEars");
|
|
(ears as any)._objFlags |= (cc.Object as any).Flags.DontSave;
|
|
prop.addChild(ears);
|
|
ears.setSiblingIndex(0);
|
|
const graphics = ears.addComponent(cc.Graphics);
|
|
graphics.fillColor = cc.color(244, 229, 200);
|
|
[-1, 1].forEach(side => {
|
|
graphics.moveTo(side * 190, 628);
|
|
graphics.bezierCurveTo(side * 245, 710, side * 282, 713, side * 303, 628);
|
|
graphics.close();
|
|
graphics.fill();
|
|
});
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|