Files
sudoku/src/views/dc/CalendarUnit.ts
2025-06-13 18:13:16 +08:00

124 lines
3.3 KiB
TypeScript

const { regClass, property } = Laya
@regClass()
export class CalendarUnit extends Laya.Script {
declare owner: Laya.Box
@property(Number)
public year: number = 0
@property(Number)
public month: number = 0
@property(Number)
public day: number = 0
@property(Boolean)
public open: boolean = false
@property(Number)
public progress: number = 0
private selected: boolean = false
@property(Laya.Image)
public obj_selected: Laya.Image
@property(Laya.Box)
public obj_pie: Laya.Box
@property(Laya.Sprite)
public sprite_pie: Laya.Sprite
private pieSize: number
@property(Laya.Sprite)
public obj_mask: Laya.Sprite
@property(Laya.Sprite)
public sprite_mask: Laya.Sprite
@property(Laya.Image)
public obj_star: Laya.Image
@property(Laya.Label)
public label_show: Laya.Label
// 组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
this.pieSize = this.sprite_pie.width / 2
}
public setCalendarUnit(year: number, month: number, day: number, open: boolean, progress: number, handler: any, func: any): void {
this.selected = false
this.year = year
this.month = month
this.day = day
this.open = open
this.progress = progress
if (open) {
if (progress >= 1) {
this.label_show.text = ""
} else {
this.label_show.text = this.day.toString()
}
this.label_show.color = "#2d3138"
this.owner.on(Laya.Event.CLICK, handler, func)
this.updateUnit()
} else {
this.label_show.text = this.day.toString()
this.label_show.color = "#d3d5db"
this.owner.on(Laya.Event.CLICK, this, () => {
})
this.obj_selected.visible = false
this.obj_pie.visible = false
this.obj_mask.visible = false
this.obj_star.visible = false
}
}
public setSelected(selected: boolean): void {
this.selected = selected
this.updateUnit()
}
updateUnit(): void {
if (this.open === false) {
return
}
this.obj_star.visible = this.progress >= 1
if (this.selected) {
this.label_show.color = "#ffffff"
this.obj_selected.visible = true
if (this.progress > 0) {
this.obj_pie.visible = true
this.obj_mask.visible = true
this.sprite_pie.graphics.clear()
this.sprite_pie.graphics.drawPie(this.pieSize, this.pieSize, this.pieSize, 0, 360 * this.progress, "#ffffff")
this.sprite_mask.graphics.clear()
this.sprite_mask.graphics.drawCircle(this.obj_mask.width / 2, this.obj_mask.width / 2, this.obj_mask.width / 2, "#1d5cdc")
} else {
this.obj_pie.visible = false
this.obj_mask.visible = false
}
} else {
this.label_show.color = "#2d3138"
this.obj_selected.visible = false
if (this.progress > 0 && this.progress < 1) {
this.obj_pie.visible = true
this.obj_mask.visible = true
this.sprite_pie.graphics.clear()
this.sprite_pie.graphics.drawPie(this.pieSize, this.pieSize, this.pieSize, 0, 360 * this.progress, "#2d3138")
this.sprite_mask.graphics.clear()
this.sprite_mask.graphics.drawCircle(this.obj_mask.width / 2, this.obj_mask.width / 2, this.obj_mask.width / 2, "#ffffff")
} else {
this.obj_pie.visible = false
this.obj_mask.visible = false
}
}
}
}