Files
sudoku/src/types/Candy.ts
2025-05-13 20:31:44 +08:00

52 lines
1.3 KiB
TypeScript

import { DOCandy } from "./DOCandy";
const { regClass, property } = Laya;
@regClass()
export class Candy extends Laya.Script {
declare owner : Laya.Button;
private label_show: Laya.Label;
private label_left: Laya.Label;
private data: DOCandy
public onInit(label_obj: Laya.Box, handler: any, func: any): void {
this.label_show = label_obj.getChildByName("label") as Laya.Label
this.label_left = label_obj.getChildByName("label_left") as Laya.Label
this.owner.on(Laya.Event.CLICK, handler, func)
}
public setCandy(data: DOCandy): void {
this.data = data
this.updateCandy()
}
public getData(): DOCandy {
return this.data
}
public setLeft(left: number): void {
this.data.set_left(left)
this.updateCandy()
}
public getLeft(): number {
return this.data.get_left();
}
updateCandy(): void {
this.owner.active = this.getLeft() > 0
if (this.data.get_show() > 0) {
this.label_show.text = this.data.get_show().toString()
}
else {
this.label_show.text = ""
}
if (this.getLeft() > 0) {
this.label_left.text = this.getLeft().toString();
}
else {
this.label_left.text = ""
}
}
}