2025-05-28 18:47:51 +08:00
|
|
|
import type { DOBlock } from "../models/DOBlock"
|
|
|
|
|
import { G_ShowScoreTips } from "../views/common/GUITips"
|
2025-05-13 14:17:33 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
const { regClass, property } = Laya
|
2025-05-09 19:10:40 +08:00
|
|
|
|
|
|
|
|
@regClass()
|
|
|
|
|
export class Block extends Laya.Script {
|
2025-05-29 15:37:45 +08:00
|
|
|
declare owner: Laya.Box
|
2025-05-12 21:18:27 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
@property(Number)
|
|
|
|
|
public XIndex: number = 0
|
|
|
|
|
|
|
|
|
|
@property(Number)
|
|
|
|
|
public YIndex: number = 0
|
|
|
|
|
|
|
|
|
|
@property(Number)
|
|
|
|
|
public XGroup: number = 0
|
|
|
|
|
|
|
|
|
|
@property(Number)
|
|
|
|
|
public YGroup: number = 0
|
|
|
|
|
|
2025-05-29 15:37:45 +08:00
|
|
|
private sprite_show: Laya.Sprite
|
2025-05-30 11:02:53 +08:00
|
|
|
private blockSize: number
|
2025-05-30 19:09:06 +08:00
|
|
|
private obj_notes: Laya.Box
|
2025-05-28 18:47:51 +08:00
|
|
|
private label_show: Laya.Label
|
2025-05-29 15:37:45 +08:00
|
|
|
private tips_bgs: Array<Laya.Sprite> = []
|
2025-05-28 18:47:51 +08:00
|
|
|
private tips_labels: Array<Laya.Label> = []
|
2025-05-30 11:02:53 +08:00
|
|
|
private tipsSize: number
|
2025-05-28 18:47:51 +08:00
|
|
|
|
|
|
|
|
private selected: boolean = false
|
2025-05-09 19:10:40 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
private data: DOBlock
|
|
|
|
|
|
2025-05-29 15:37:45 +08:00
|
|
|
public onInit(XIndex: number, YIndex: number, XGroup: number, YGroup: number, handler: any, func: any): void {
|
2025-05-28 18:47:51 +08:00
|
|
|
this.XIndex = XIndex
|
|
|
|
|
this.YIndex = YIndex
|
|
|
|
|
this.XGroup = XGroup
|
|
|
|
|
this.YGroup = YGroup
|
|
|
|
|
|
2025-05-29 15:37:45 +08:00
|
|
|
this.sprite_show = this.owner.getChildByName("Sprite") as Laya.Sprite
|
2025-05-30 11:02:53 +08:00
|
|
|
this.blockSize = this.sprite_show.width
|
2025-05-29 15:37:45 +08:00
|
|
|
this.label_show = this.owner.getChildByName("label_show") as Laya.Label
|
|
|
|
|
|
2025-05-30 19:09:06 +08:00
|
|
|
const notes = this.owner.getChildByName("notes") as Laya.Box
|
|
|
|
|
this.obj_notes = notes
|
2025-05-29 15:37:45 +08:00
|
|
|
for (let i = 0; i < notes.numChildren; i++) {
|
|
|
|
|
const hbox = notes.getChildAt(i)
|
2025-05-28 20:29:24 +08:00
|
|
|
for (let j = 0; j < hbox.numChildren; j++) {
|
2025-05-29 15:37:45 +08:00
|
|
|
const sp = hbox.getChildAt(j).getChildByName("Sprite") as Laya.Sprite
|
2025-05-28 18:47:51 +08:00
|
|
|
this.tips_bgs.push(sp)
|
2025-05-29 15:37:45 +08:00
|
|
|
const Label = hbox.getChildAt(j).getChildByName("Label") as Laya.Label
|
2025-05-28 18:47:51 +08:00
|
|
|
Label.text = ""
|
|
|
|
|
this.tips_labels.push(Label)
|
2025-05-30 11:02:53 +08:00
|
|
|
this.tipsSize = sp.width
|
2025-05-28 18:47:51 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-29 19:15:32 +08:00
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
this.owner.on(Laya.Event.CLICK, handler, func)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setSelected(selected: boolean): void {
|
|
|
|
|
this.selected = selected
|
|
|
|
|
this.updateBlock()
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-30 19:09:06 +08:00
|
|
|
public setPaused(paused: boolean): void {
|
|
|
|
|
this.sprite_show.visible = !paused
|
|
|
|
|
this.obj_notes.visible = !paused
|
|
|
|
|
this.label_show.visible = !paused
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-28 18:47:51 +08:00
|
|
|
public setBlockColor(color: string, alpha: number = 1, animated: boolean = false, completedColor: string = "", completedAlpha: number = 1): void {
|
2025-05-29 15:37:45 +08:00
|
|
|
this.sprite_show.graphics.clear()
|
2025-05-30 11:02:53 +08:00
|
|
|
this.sprite_show.graphics.drawRect(0, 0, this.blockSize, this.blockSize, color)
|
2025-05-28 18:47:51 +08:00
|
|
|
if (animated) {
|
2025-05-29 15:37:45 +08:00
|
|
|
this.sprite_show.alpha = 0
|
2025-06-06 14:42:20 +08:00
|
|
|
Laya.Tween.to(this.sprite_show, { alpha }, 100, Laya.Ease.linearIn, Laya.Handler.create(this, () => {
|
|
|
|
|
Laya.Tween.to(this.sprite_show, { alpha: 0 }, 150, Laya.Ease.linearIn, Laya.Handler.create(this, () => {
|
|
|
|
|
Laya.Tween.to(this.sprite_show, { alpha }, 100, Laya.Ease.linearIn, Laya.Handler.create(this, () => {
|
|
|
|
|
Laya.Tween.to(this.sprite_show, { alpha: 0 }, 150, Laya.Ease.linearIn, Laya.Handler.create(this, () => {
|
2025-05-30 18:55:41 +08:00
|
|
|
this.sprite_show.graphics.clear()
|
|
|
|
|
this.sprite_show.graphics.drawRect(0, 0, this.blockSize, this.blockSize, completedColor)
|
|
|
|
|
this.sprite_show.alpha = completedAlpha
|
|
|
|
|
}))
|
|
|
|
|
}))
|
|
|
|
|
}))
|
|
|
|
|
}))
|
|
|
|
|
// Laya.Handler.create(this, () => {
|
|
|
|
|
// })
|
2025-05-28 18:47:51 +08:00
|
|
|
} else {
|
2025-05-29 15:37:45 +08:00
|
|
|
this.sprite_show.alpha = alpha
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
2025-05-28 18:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setFadeAnimation(): void {
|
|
|
|
|
Laya.timer.once(200, this, () => {
|
|
|
|
|
this.label_show.color = "#ff0000"
|
|
|
|
|
Laya.timer.once(100, this, () => {
|
|
|
|
|
this.label_show.color = "#2d3138"
|
|
|
|
|
Laya.timer.once(200, this, () => {
|
|
|
|
|
this.label_show.color = "#ff0000"
|
|
|
|
|
Laya.timer.once(100, this, () => {
|
|
|
|
|
this.updateBlock()
|
|
|
|
|
})
|
2025-05-15 21:36:03 +08:00
|
|
|
})
|
2025-05-28 18:47:51 +08:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setTipsBgColor(visible: boolean, noteNumber: number = 0, color: string = "", alpha: number = 1): void {
|
|
|
|
|
if (visible) {
|
2025-05-28 20:29:24 +08:00
|
|
|
const obj = this.tips_bgs[noteNumber - 1]
|
2025-05-28 18:47:51 +08:00
|
|
|
obj.visible = true
|
|
|
|
|
obj.graphics.clear()
|
2025-05-30 11:02:53 +08:00
|
|
|
obj.graphics.drawRect(0, 0, this.tipsSize, this.tipsSize, color)
|
2025-05-28 18:47:51 +08:00
|
|
|
obj.alpha = alpha
|
|
|
|
|
} else {
|
|
|
|
|
for (let i = 0; i < this.tips_bgs.length; i++) {
|
2025-05-28 20:29:24 +08:00
|
|
|
const obj = this.tips_bgs[i]
|
2025-05-28 18:47:51 +08:00
|
|
|
obj.visible = false
|
|
|
|
|
}
|
2025-05-15 21:36:03 +08:00
|
|
|
}
|
2025-05-28 18:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setBlock(data: DOBlock): void {
|
|
|
|
|
this.data = data
|
|
|
|
|
this.updateBlock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getData(): DOBlock {
|
|
|
|
|
return this.data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setShowNumber(showNumber: number, score: number): boolean {
|
|
|
|
|
this.data.set_show(showNumber)
|
|
|
|
|
if (this.data.get_checked()) {
|
|
|
|
|
this.data.set_score(score)
|
|
|
|
|
if (score > 0)
|
2025-05-30 11:02:53 +08:00
|
|
|
G_ShowScoreTips(`+${score}`, this.owner)
|
2025-05-28 18:47:51 +08:00
|
|
|
} else {
|
2025-05-28 20:12:56 +08:00
|
|
|
if (this.data.get_score() !== 0)
|
2025-05-28 18:47:51 +08:00
|
|
|
this.data.set_score(0)
|
2025-05-12 21:18:27 +08:00
|
|
|
}
|
2025-05-28 18:47:51 +08:00
|
|
|
this.data.clean_notes()
|
|
|
|
|
this.updateBlock()
|
|
|
|
|
return this.data.get_checked()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public addNoteNumber(noteNumber: number): void {
|
|
|
|
|
this.data.set_show(0)
|
|
|
|
|
const note_numbers = this.data.get_notes()
|
|
|
|
|
const find = note_numbers.indexOf(noteNumber)
|
|
|
|
|
|
|
|
|
|
if (find >= 0) {
|
|
|
|
|
this.data.remove_note(noteNumber)
|
|
|
|
|
} else {
|
|
|
|
|
this.data.add_note(noteNumber)
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
2025-05-28 18:47:51 +08:00
|
|
|
this.updateBlock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setNotes(notes: Array<number>): void {
|
|
|
|
|
this.data.set_show(0)
|
|
|
|
|
this.data.clean_notes()
|
|
|
|
|
for (let i = 0; i < notes.length; i++) {
|
|
|
|
|
this.data.add_note(notes[i])
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
2025-05-28 18:47:51 +08:00
|
|
|
this.updateBlock()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateBlock(): void {
|
|
|
|
|
// 设置文字颜色
|
|
|
|
|
if (this.selected) {
|
|
|
|
|
this.label_show.color = "#ffffff"
|
2025-05-28 20:29:24 +08:00
|
|
|
for (let i = 0; i < this.tips_labels.length; i++) {
|
2025-05-28 18:47:51 +08:00
|
|
|
this.tips_labels[i].color = "#ffffff"
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-05-28 19:15:32 +08:00
|
|
|
if (this.data.get_show() === this.data.get_correct()) {
|
2025-05-28 18:47:51 +08:00
|
|
|
if (this.data.get_preset()) {
|
|
|
|
|
this.label_show.color = "#2d3138"
|
|
|
|
|
} else {
|
|
|
|
|
this.label_show.color = "#2559c0"
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.label_show.color = "#cb3256"
|
|
|
|
|
}
|
2025-05-28 20:29:24 +08:00
|
|
|
for (let i = 0; i < this.tips_labels.length; i++) {
|
2025-05-28 18:47:51 +08:00
|
|
|
this.tips_labels[i].color = "#2d3138"
|
|
|
|
|
}
|
2025-05-13 14:17:33 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-28 20:29:24 +08:00
|
|
|
for (let i = 0; i < this.tips_labels.length; i++) {
|
2025-05-28 18:47:51 +08:00
|
|
|
this.tips_labels[i].text = ""
|
2025-05-12 21:18:27 +08:00
|
|
|
}
|
2025-05-28 18:47:51 +08:00
|
|
|
if (this.data.get_show() > 0) {
|
|
|
|
|
this.label_show.text = this.data.get_show().toString()
|
|
|
|
|
} else {
|
|
|
|
|
this.label_show.text = ""
|
|
|
|
|
const note_numbers = this.data.get_notes()
|
2025-05-28 20:29:24 +08:00
|
|
|
for (let i = 0; i < note_numbers.length; i++) {
|
2025-05-28 18:47:51 +08:00
|
|
|
const value = note_numbers[i]
|
|
|
|
|
const label = this.tips_labels[value - 1]
|
|
|
|
|
label.text = value.toString()
|
|
|
|
|
}
|
2025-05-17 16:36:42 +08:00
|
|
|
}
|
2025-05-28 18:47:51 +08:00
|
|
|
}
|
|
|
|
|
}
|