Files
sudoku/src/types/Candy.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-05-13 20:31:44 +08:00
import { DOCandy } from "./DOCandy";
2025-05-09 19:10:40 +08:00
const { regClass, property } = Laya;
@regClass()
export class Candy extends Laya.Script {
declare owner : Laya.Button;
2025-05-12 10:43:02 +08:00
private label_show: Laya.Label;
private label_left: Laya.Label;
2025-05-09 19:10:40 +08:00
2025-05-13 20:31:44 +08:00
private data: DOCandy
2025-05-12 21:18:27 +08:00
2025-05-13 20:31:44 +08:00
public onInit(label_obj: Laya.Box, handler: any, func: any): void {
2025-05-12 10:43:02 +08:00
this.label_show = label_obj.getChildByName("label") as Laya.Label
this.label_left = label_obj.getChildByName("label_left") as Laya.Label
2025-05-09 19:10:40 +08:00
this.owner.on(Laya.Event.CLICK, handler, func)
2025-05-13 20:31:44 +08:00
}
2025-05-12 21:18:27 +08:00
2025-05-13 20:31:44 +08:00
public setCandy(data: DOCandy): void {
this.data = data
2025-05-09 19:10:40 +08:00
this.updateCandy()
}
2025-05-13 20:31:44 +08:00
public getData(): DOCandy {
return this.data
2025-05-09 19:10:40 +08:00
}
public setLeft(left: number): void {
2025-05-13 20:31:44 +08:00
this.data.set_left(left)
2025-05-09 19:10:40 +08:00
this.updateCandy()
}
public getLeft(): number {
2025-05-13 20:31:44 +08:00
return this.data.get_left();
2025-05-09 19:10:40 +08:00
}
updateCandy(): void {
2025-05-13 20:31:44 +08:00
this.owner.active = this.getLeft() > 0
if (this.data.get_show() > 0) {
this.label_show.text = this.data.get_show().toString()
2025-05-12 10:43:02 +08:00
}
else {
this.label_show.text = ""
}
2025-05-13 20:31:44 +08:00
if (this.getLeft() > 0) {
this.label_left.text = this.getLeft().toString();
2025-05-12 10:43:02 +08:00
}
else {
this.label_left.text = ""
}
2025-05-09 19:10:40 +08:00
}
}