2025-05-26 19:57:17 +08:00
|
|
|
import { config } from "../../constants/config";
|
|
|
|
|
|
2025-05-20 17:41:43 +08:00
|
|
|
const { regClass, property } = Laya;
|
|
|
|
|
|
|
|
|
|
@regClass()
|
|
|
|
|
export class CalendarUnit extends Laya.Script {
|
|
|
|
|
declare owner : Laya.Box;
|
|
|
|
|
|
2025-05-21 10:15:23 +08:00
|
|
|
@property(Number)
|
|
|
|
|
public year: number = 0;
|
|
|
|
|
@property(Number)
|
|
|
|
|
public month: number = 0;
|
2025-05-20 17:41:43 +08:00
|
|
|
@property(Number)
|
|
|
|
|
public day: number = 0;
|
|
|
|
|
@property(Boolean)
|
|
|
|
|
public open: boolean = false;
|
|
|
|
|
@property(Number)
|
|
|
|
|
public progress: number = 0;
|
|
|
|
|
|
|
|
|
|
private selected: boolean = false
|
|
|
|
|
|
|
|
|
|
@property(Laya.Sprite)
|
|
|
|
|
public obj_selected: Laya.Sprite;
|
|
|
|
|
|
|
|
|
|
@property(Laya.Box)
|
|
|
|
|
public obj_pie: Laya.Box;
|
|
|
|
|
@property(Laya.Sprite)
|
|
|
|
|
public sprite_pie: Laya.Sprite;
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-21 10:15:23 +08:00
|
|
|
public onInit(label_obj: Laya.Label): void {
|
|
|
|
|
this.label_show = label_obj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
2025-05-20 17:41:43 +08:00
|
|
|
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, (evt: Laya.Event)=>{
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
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
|
|
|
|
|
|
2025-05-26 19:57:17 +08:00
|
|
|
var blockSize = 48
|
|
|
|
|
if (config.H_SCREEN)
|
|
|
|
|
blockSize = 33
|
|
|
|
|
|
2025-05-20 17:41:43 +08:00
|
|
|
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-26 19:57:17 +08:00
|
|
|
this.sprite_pie.graphics.drawPie(blockSize, blockSize, blockSize, 0, 360*this.progress, "#ffffff")
|
2025-05-20 17:41:43 +08:00
|
|
|
this.sprite_mask.graphics.clear()
|
|
|
|
|
this.sprite_mask.graphics.drawCircle(0.5, 0.5, 0.5, "#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()
|
2025-05-26 19:57:17 +08:00
|
|
|
this.sprite_pie.graphics.drawPie(blockSize, blockSize, blockSize, 0, 360*this.progress, "#2d3138")
|
2025-05-20 17:41:43 +08:00
|
|
|
this.sprite_mask.graphics.clear()
|
|
|
|
|
this.sprite_mask.graphics.drawCircle(0.5, 0.5, 0.5, "#ffffff")
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.obj_pie.visible = false
|
|
|
|
|
this.obj_mask.visible = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|