2025-05-13 14:17:33 +08:00
|
|
|
import { G_ShowScoreTips } from "../views/GUITips";
|
|
|
|
|
|
2025-05-09 19:10:40 +08:00
|
|
|
const { regClass, property } = Laya;
|
|
|
|
|
|
|
|
|
|
@regClass()
|
|
|
|
|
export class Block extends Laya.Script {
|
|
|
|
|
declare owner : Laya.Button;
|
|
|
|
|
|
|
|
|
|
@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-12 21:18:27 +08:00
|
|
|
private selected: boolean = false
|
2025-05-13 14:17:33 +08:00
|
|
|
private newSelect: boolean = false
|
2025-05-09 19:10:40 +08:00
|
|
|
private preset: boolean = false//预设格子
|
|
|
|
|
private checked: boolean = false//正确格子
|
|
|
|
|
private showNumber: number = 0;
|
|
|
|
|
private correctNumber: number = 0;
|
2025-05-13 14:17:33 +08:00
|
|
|
private score: number = 0
|
2025-05-12 21:18:27 +08:00
|
|
|
private note_numbers: Array<number> = new Array()
|
|
|
|
|
|
|
|
|
|
private label_show: Laya.Label;
|
|
|
|
|
private tips_labels: Array<Laya.Label> = new Array();
|
|
|
|
|
private animator: Laya.Animator2D
|
|
|
|
|
|
|
|
|
|
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-12 10:43:02 +08:00
|
|
|
this.label_show = label_obj.getChildByName("label_show") as Laya.Label
|
|
|
|
|
var VBox = label_obj.getChildByName("VBox")
|
|
|
|
|
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
|
|
|
this.animator = this.owner.getComponent(Laya.Animator2D)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setSelected(selected: boolean): void {
|
|
|
|
|
this.selected = selected
|
2025-05-13 14:17:33 +08:00
|
|
|
if (selected)
|
|
|
|
|
this.newSelect = true
|
2025-05-12 21:18:27 +08:00
|
|
|
this.updateBlock()
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setButtonSkin(skin: string): void {
|
|
|
|
|
this.owner.skin = skin
|
|
|
|
|
}
|
2025-05-12 21:18:27 +08:00
|
|
|
|
|
|
|
|
public setFadeAnimation(): void {
|
|
|
|
|
if (this.animator) {
|
|
|
|
|
this.animator.play("fade_to_red")
|
|
|
|
|
Laya.timer.frameOnce(40, this, ()=>{
|
|
|
|
|
this.animator.stop()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
|
|
|
|
|
public setBlock(preset: boolean, showNumber: number, correctNumber: number): void {
|
|
|
|
|
this.preset = preset;
|
|
|
|
|
this.checked = preset;
|
|
|
|
|
this.showNumber = showNumber;
|
|
|
|
|
this.correctNumber = correctNumber;
|
2025-05-13 14:17:33 +08:00
|
|
|
this.score = 0
|
2025-05-09 19:10:40 +08:00
|
|
|
this.updateBlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getIsPreset(): boolean {
|
|
|
|
|
return this.preset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getIsChecked(): boolean {
|
|
|
|
|
return this.checked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getShowNumber(): number {
|
|
|
|
|
return this.showNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setShowNumber(showNumber: number): boolean {
|
|
|
|
|
if (this.checked == false) {
|
|
|
|
|
if (showNumber == this.correctNumber)
|
|
|
|
|
this.checked = true;
|
|
|
|
|
this.showNumber = showNumber;
|
2025-05-13 14:17:33 +08:00
|
|
|
if (this.checked || showNumber == 0) {//正确或者擦除
|
2025-05-12 21:18:27 +08:00
|
|
|
this.note_numbers = new Array()
|
2025-05-13 14:17:33 +08:00
|
|
|
}
|
|
|
|
|
this.score = 0
|
|
|
|
|
if (this.newSelect) {
|
|
|
|
|
this.newSelect = false
|
|
|
|
|
if (this.checked) {
|
|
|
|
|
this.score = 150
|
|
|
|
|
G_ShowScoreTips(this.score.toString(), this.owner)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
this.updateBlock();
|
|
|
|
|
}
|
|
|
|
|
return this.checked
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-13 14:17:33 +08:00
|
|
|
public getCorrectNumber(): number {
|
|
|
|
|
return this.correctNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getScore(): number {
|
|
|
|
|
return this.score
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-12 21:18:27 +08:00
|
|
|
public addNoteNumber(noteNumber: number): void {
|
|
|
|
|
if (this.note_numbers.indexOf(noteNumber) < 0) {
|
|
|
|
|
this.note_numbers.push(noteNumber)
|
|
|
|
|
this.updateBlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-09 19:10:40 +08:00
|
|
|
updateBlock(): void {
|
2025-05-12 21:18:27 +08:00
|
|
|
for (var i=0; i<this.tips_labels.length; i++)
|
|
|
|
|
this.tips_labels[i].text = ""
|
2025-05-09 19:10:40 +08:00
|
|
|
if (this.showNumber > 0) {
|
2025-05-12 10:43:02 +08:00
|
|
|
this.label_show.text = this.showNumber.toString();
|
|
|
|
|
if (this.checked) {
|
|
|
|
|
this.label_show.color = "#000000"
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.label_show.color = "#ff0000"
|
|
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
|
|
|
|
else {
|
2025-05-12 10:43:02 +08:00
|
|
|
this.label_show.text = "";
|
2025-05-12 21:18:27 +08:00
|
|
|
for (var i=0; i<this.note_numbers.length; i++) {
|
|
|
|
|
var value = this.note_numbers[i]
|
|
|
|
|
var label = this.tips_labels[value-1]
|
|
|
|
|
label.text = value.toString()
|
|
|
|
|
if (this.selected) {
|
|
|
|
|
label.color = "#ffffff"
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
label.color = "#000000"
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-09 19:10:40 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|