2025-05-22 19:12:00 +08:00
|
|
|
import { G_ShowScoreTips } from "../views/common/GUITips";
|
2025-05-14 19:22:21 +08:00
|
|
|
import { DOBlock } from "../models/DOBlock";
|
2025-05-26 19:57:17 +08:00
|
|
|
import { config } from "../constants/config";
|
2025-05-13 14:17:33 +08:00
|
|
|
|
2025-05-09 19:10:40 +08:00
|
|
|
const { regClass, property } = Laya;
|
|
|
|
|
|
|
|
|
|
@regClass()
|
|
|
|
|
export class Block extends Laya.Script {
|
2025-05-15 21:36:03 +08:00
|
|
|
declare owner : Laya.Sprite;
|
2025-05-09 19:10:40 +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-15 21:36:03 +08:00
|
|
|
private tips_bgs: Array<Laya.Sprite> = new Array();
|
2025-05-12 21:18:27 +08:00
|
|
|
private label_show: Laya.Label;
|
|
|
|
|
private tips_labels: Array<Laya.Label> = new Array();
|
2025-05-13 20:31:44 +08:00
|
|
|
|
|
|
|
|
private selected: boolean = false
|
|
|
|
|
|
|
|
|
|
private data: DOBlock
|
2025-05-12 21:18:27 +08:00
|
|
|
|
2025-05-15 21:36:03 +08:00
|
|
|
|
2025-05-12 21:18:27 +08:00
|
|
|
public onInit(XIndex: number, YIndex: number, XGroup: number, YGroup: number, label_obj: Laya.Box, handler: any, func: any): void {
|
|
|
|
|
this.XIndex = XIndex;
|
|
|
|
|
this.YIndex = YIndex;
|
|
|
|
|
this.XGroup = XGroup;
|
|
|
|
|
this.YGroup = YGroup;
|
2025-05-09 19:10:40 +08:00
|
|
|
|
2025-05-15 21:36:03 +08:00
|
|
|
var VBox = this.owner.getChildByName("VBox")
|
|
|
|
|
for (var i=0; i<VBox.numChildren; i++) {
|
|
|
|
|
var hbox = VBox.getChildAt(i)
|
|
|
|
|
for (var j=0; j<hbox.numChildren; j++) {
|
|
|
|
|
var sp = hbox.getChildAt(j) as Laya.Sprite
|
|
|
|
|
this.tips_bgs.push(sp)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-12 10:43:02 +08:00
|
|
|
this.label_show = label_obj.getChildByName("label_show") as Laya.Label
|
2025-05-16 21:10:37 +08:00
|
|
|
// this.label_show.text = XGroup + "" + YGroup
|
2025-05-15 21:36:03 +08:00
|
|
|
VBox = label_obj.getChildByName("VBox")
|
2025-05-12 10:43:02 +08:00
|
|
|
for (var i=0; i<VBox.numChildren; i++) {
|
|
|
|
|
var hbox = VBox.getChildAt(i);
|
|
|
|
|
for (var j=0; j<hbox.numChildren; j++) {
|
|
|
|
|
var Label = hbox.getChildAt(j) as Laya.Label
|
|
|
|
|
Label.text = ""
|
|
|
|
|
this.tips_labels.push(Label)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
this.owner.on(Laya.Event.CLICK, handler, func);
|
2025-05-12 21:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setSelected(selected: boolean): void {
|
|
|
|
|
this.selected = selected
|
|
|
|
|
this.updateBlock()
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-15 21:36:03 +08:00
|
|
|
public setBlockColor(color: string, alpha: number=1, animated: boolean=false, completedColor: string = "", completedAlpha: number=1): void {
|
2025-05-26 19:57:17 +08:00
|
|
|
var blockSize = 116
|
|
|
|
|
if (config.H_SCREEN)
|
|
|
|
|
blockSize = 96
|
2025-05-15 21:36:03 +08:00
|
|
|
this.owner.graphics.clear()
|
2025-05-26 19:57:17 +08:00
|
|
|
this.owner.graphics.drawRect(0, 0, blockSize, blockSize, color)
|
2025-05-15 21:36:03 +08:00
|
|
|
if (animated) {
|
|
|
|
|
Laya.Tween.to(this.owner, {alpha:alpha}, 500, Laya.Ease.elasticOut, Laya.Handler.create(this, () => {
|
|
|
|
|
this.owner.graphics.clear()
|
2025-05-26 19:57:17 +08:00
|
|
|
this.owner.graphics.drawRect(0, 0, blockSize, blockSize, completedColor)
|
2025-05-15 21:36:03 +08:00
|
|
|
this.owner.alpha = completedAlpha
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.owner.alpha = alpha
|
|
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
2025-05-12 21:18:27 +08:00
|
|
|
|
|
|
|
|
public setFadeAnimation(): void {
|
2025-05-15 21:36:03 +08:00
|
|
|
var color = this.label_show.color
|
|
|
|
|
var flag = true
|
|
|
|
|
Laya.timer.loop(200, this, ()=>{
|
|
|
|
|
flag = !flag
|
|
|
|
|
if (flag) {
|
|
|
|
|
this.label_show.color = color
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.label_show.color = "#ff0000"
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
Laya.Tween.to(this.label_show, {color:"#ff0000"}, 1000, Laya.Ease.strongIn, Laya.Handler.create(this, () => {
|
|
|
|
|
this.label_show.color = color
|
|
|
|
|
Laya.timer.clearAll(this)
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setTipsBgColor(visible: boolean, noteNumber: number=0, color: string="", alpha: number=1): void {
|
2025-05-26 19:57:17 +08:00
|
|
|
var blockSize = 38
|
|
|
|
|
if (config.H_SCREEN)
|
|
|
|
|
blockSize = 30
|
2025-05-15 21:36:03 +08:00
|
|
|
if (visible) {
|
|
|
|
|
var obj = this.tips_bgs[noteNumber-1]
|
|
|
|
|
obj.visible = true
|
|
|
|
|
obj.graphics.clear()
|
2025-05-26 19:57:17 +08:00
|
|
|
obj.graphics.drawRect(0, 0, blockSize, blockSize, color)
|
2025-05-15 21:36:03 +08:00
|
|
|
obj.alpha = alpha
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (var i=0; i<this.tips_bgs.length; i++) {
|
|
|
|
|
var obj = this.tips_bgs[i]
|
|
|
|
|
obj.visible = false
|
|
|
|
|
}
|
2025-05-12 21:18:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
|
2025-05-13 20:31:44 +08:00
|
|
|
public setBlock(data: DOBlock): void {
|
|
|
|
|
this.data = data;
|
2025-05-09 19:10:40 +08:00
|
|
|
this.updateBlock();
|
|
|
|
|
}
|
2025-05-13 20:31:44 +08:00
|
|
|
public getData(): DOBlock {
|
|
|
|
|
return this.data
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-22 17:17:47 +08:00
|
|
|
public setShowNumber(showNumber: number, score: number): boolean {
|
2025-05-17 16:36:42 +08:00
|
|
|
this.data.set_show(showNumber)
|
2025-05-22 17:17:47 +08:00
|
|
|
if (this.data.get_checked()) {
|
|
|
|
|
this.data.set_score(score)
|
|
|
|
|
if (score > 0)
|
2025-05-17 16:45:25 +08:00
|
|
|
G_ShowScoreTips(score.toString(), this.label_show)
|
2025-05-22 17:17:47 +08:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (this.data.get_score() != 0)
|
|
|
|
|
this.data.set_score(0)
|
2025-05-17 16:45:25 +08:00
|
|
|
}
|
2025-05-17 16:36:42 +08:00
|
|
|
this.data.clean_notes()
|
|
|
|
|
this.updateBlock()
|
2025-05-13 20:31:44 +08:00
|
|
|
return this.data.get_checked()
|
2025-05-13 14:17:33 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-12 21:18:27 +08:00
|
|
|
public addNoteNumber(noteNumber: number): void {
|
2025-05-15 21:36:03 +08:00
|
|
|
this.data.set_show(0)
|
|
|
|
|
var note_numbers = this.data.get_notes()
|
|
|
|
|
var find = note_numbers.indexOf(noteNumber)
|
|
|
|
|
|
|
|
|
|
if (find >= 0) {
|
|
|
|
|
this.data.remove_note(noteNumber)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.data.add_note(noteNumber)
|
2025-05-12 21:18:27 +08:00
|
|
|
}
|
2025-05-15 21:36:03 +08:00
|
|
|
this.updateBlock()
|
2025-05-12 21:18:27 +08:00
|
|
|
}
|
2025-05-17 16:36:42 +08:00
|
|
|
public setNotes(notes: Array<number>): void {
|
|
|
|
|
this.data.set_show(0)
|
|
|
|
|
this.data.clean_notes()
|
|
|
|
|
for (var i=0; i<notes.length; i++) {
|
|
|
|
|
this.data.add_note(notes[i])
|
|
|
|
|
}
|
|
|
|
|
this.updateBlock()
|
|
|
|
|
}
|
2025-05-12 21:18:27 +08:00
|
|
|
|
2025-05-09 19:10:40 +08:00
|
|
|
updateBlock(): void {
|
2025-05-15 21:36:03 +08:00
|
|
|
//设置文字颜色
|
|
|
|
|
if (this.selected) {
|
|
|
|
|
this.label_show.color = "#ffffff"
|
|
|
|
|
for (var i=0; i<this.tips_labels.length; i++) {
|
|
|
|
|
this.tips_labels[i].color = "#ffffff"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (this.data.get_show() == this.data.get_correct()) {
|
|
|
|
|
if (this.data.get_preset()) {
|
|
|
|
|
this.label_show.color = "#2d3138"
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.label_show.color = "#2559c0"
|
|
|
|
|
}
|
2025-05-12 10:43:02 +08:00
|
|
|
}
|
|
|
|
|
else {
|
2025-05-15 21:36:03 +08:00
|
|
|
this.label_show.color = "#cb3256"
|
|
|
|
|
}
|
|
|
|
|
for (var i=0; i<this.tips_labels.length; i++) {
|
|
|
|
|
this.tips_labels[i].color = "#2d3138"
|
2025-05-12 10:43:02 +08:00
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
2025-05-15 21:36:03 +08:00
|
|
|
|
|
|
|
|
for (var i=0; i<this.tips_labels.length; i++) {
|
|
|
|
|
this.tips_labels[i].text = ""
|
|
|
|
|
}
|
|
|
|
|
if (this.data.get_show() > 0) {
|
|
|
|
|
this.label_show.text = this.data.get_show().toString()
|
|
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
else {
|
2025-05-12 10:43:02 +08:00
|
|
|
this.label_show.text = "";
|
2025-05-13 20:31:44 +08:00
|
|
|
var note_numbers = this.data.get_notes()
|
|
|
|
|
for (var i=0; i<note_numbers.length; i++) {
|
|
|
|
|
var value = note_numbers[i]
|
2025-05-12 21:18:27 +08:00
|
|
|
var label = this.tips_labels[value-1]
|
|
|
|
|
label.text = value.toString()
|
|
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|