37 lines
875 B
TypeScript
37 lines
875 B
TypeScript
|
|
const { regClass, property } = Laya;
|
||
|
|
|
||
|
|
@regClass()
|
||
|
|
export class Candy extends Laya.Script {
|
||
|
|
declare owner : Laya.Button;
|
||
|
|
|
||
|
|
@property(Laya.Label)
|
||
|
|
public label_left: Laya.Label;
|
||
|
|
|
||
|
|
private showNumber: number = 0;
|
||
|
|
private left: number = 0;
|
||
|
|
|
||
|
|
public onInit(showNumber: number, handler: any, func: any): void {
|
||
|
|
this.showNumber = showNumber
|
||
|
|
this.owner.on(Laya.Event.CLICK, handler, func)
|
||
|
|
this.updateCandy()
|
||
|
|
}
|
||
|
|
|
||
|
|
public getShowNumber(): number {
|
||
|
|
return this.showNumber;
|
||
|
|
}
|
||
|
|
|
||
|
|
public setLeft(left: number): void {
|
||
|
|
this.left = left;
|
||
|
|
this.updateCandy()
|
||
|
|
}
|
||
|
|
|
||
|
|
public getLeft(): number {
|
||
|
|
return this.left;
|
||
|
|
}
|
||
|
|
|
||
|
|
updateCandy(): void {
|
||
|
|
this.owner.active = this.left > 0
|
||
|
|
this.owner.label = this.showNumber.toString();
|
||
|
|
this.label_left.text = this.left.toString();
|
||
|
|
}
|
||
|
|
}
|