Files
sudoku/src/views/dc/CalendarUnit.ts

124 lines
3.3 KiB
TypeScript
Raw Normal View History

2025-05-28 18:47:51 +08:00
const { regClass, property } = Laya
2025-05-20 17:41:43 +08:00
@regClass()
export class CalendarUnit extends Laya.Script {
2025-05-28 18:47:51 +08:00
declare owner: Laya.Box
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Number)
public year: number = 0
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Number)
public month: number = 0
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Number)
public day: number = 0
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Boolean)
public open: boolean = false
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Number)
public progress: number = 0
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
private selected: boolean = false
2025-05-20 17:41:43 +08:00
2025-05-30 20:01:58 +08:00
@property(Laya.Image)
public obj_selected: Laya.Image
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Laya.Box)
public obj_pie: Laya.Box
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@property(Laya.Sprite)
public sprite_pie: Laya.Sprite
2025-05-20 17:41:43 +08:00
2025-05-30 11:02:53 +08:00
private pieSize: number
2025-05-28 18:47:51 +08:00
@property(Laya.Sprite)
public obj_mask: Laya.Sprite
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
@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 {
2025-05-30 16:52:51 +08:00
this.pieSize = this.sprite_pie.width / 2
2025-05-28 18:47:51 +08:00
}
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"
2025-05-28 20:29:24 +08:00
this.owner.on(Laya.Event.CLICK, this, () => {
2025-05-28 18:47:51 +08:00
})
this.obj_selected.visible = false
this.obj_pie.visible = false
this.obj_mask.visible = false
this.obj_star.visible = false
2025-05-20 17:41:43 +08:00
}
2025-05-28 18:47:51 +08:00
}
public setSelected(selected: boolean): void {
this.selected = selected
this.updateUnit()
}
2025-05-20 17:41:43 +08:00
2025-05-28 18:47:51 +08:00
updateUnit(): void {
2025-05-28 19:15:32 +08:00
if (this.open === false) {
2025-05-28 18:47:51 +08:00
return
2025-05-20 17:41:43 +08:00
}
2025-05-28 18:47:51 +08:00
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()
2025-05-30 11:02:53 +08:00
this.sprite_pie.graphics.drawPie(this.pieSize, this.pieSize, this.pieSize, 0, 360 * this.progress, "#ffffff")
2025-05-28 18:47:51 +08:00
this.sprite_mask.graphics.clear()
2025-06-13 15:11:08 +08:00
this.sprite_mask.graphics.drawCircle(this.obj_mask.width/2, this.obj_mask.width/2, this.obj_mask.width/2, "#1d5cdc")
2025-05-28 18:47:51 +08:00
} 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()
2025-05-30 11:02:53 +08:00
this.sprite_pie.graphics.drawPie(this.pieSize, this.pieSize, this.pieSize, 0, 360 * this.progress, "#2d3138")
2025-05-28 18:47:51 +08:00
this.sprite_mask.graphics.clear()
2025-06-13 15:11:08 +08:00
this.sprite_mask.graphics.drawCircle(this.obj_mask.width/2, this.obj_mask.width/2, this.obj_mask.width/2, "#ffffff")
2025-05-28 18:47:51 +08:00
} else {
this.obj_pie.visible = false
this.obj_mask.visible = false
}
2025-05-20 17:41:43 +08:00
}
2025-05-28 18:47:51 +08:00
}
}