补充UI细节 添加每日挑战
This commit is contained in:
115
src/views/CalendarUnit.ts
Normal file
115
src/views/CalendarUnit.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@regClass()
|
||||
export class CalendarUnit extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
@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 {
|
||||
|
||||
}
|
||||
|
||||
public onInit(day: number, open: boolean, progress: number, label_obj: Laya.Label, handler: any, func: any): void {
|
||||
this.day = day;
|
||||
this.open = open
|
||||
this.progress = progress
|
||||
this.label_show = label_obj
|
||||
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
|
||||
|
||||
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(48, 48, 48, 0, 360*this.progress, "#ffffff")
|
||||
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()
|
||||
this.sprite_pie.graphics.drawPie(48, 48, 48, 0, 360*this.progress, "#2d3138")
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user