添加道具功能

This commit is contained in:
2025-05-12 21:18:27 +08:00
parent 45d7df0184
commit 2ca60b215b
40 changed files with 3148 additions and 240 deletions

View File

@@ -4,9 +4,6 @@ const { regClass, property } = Laya;
export class Block extends Laya.Script {
declare owner : Laya.Button;
private label_show: Laya.Label;
private tips_labels: Array<Laya.Label> = new Array();
@property(Number)
public XIndex: number = 0;
@property(Number)
@@ -16,12 +13,23 @@ export class Block extends Laya.Script {
@property(Number)
public YGroup: number = 0;
private selected: boolean = false
private preset: boolean = false//预设格子
private checked: boolean = false//正确格子
private showNumber: number = 0;
private correctNumber: number = 0;
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;
public onInit(label_obj: Laya.Box, XIndex: number, YIndex: number, XGroup: number, YGroup: number, handler: any, func: any): void {
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++) {
@@ -32,16 +40,27 @@ export class Block extends Laya.Script {
this.tips_labels.push(Label)
}
}
this.XIndex = XIndex;
this.YIndex = YIndex;
this.XGroup = XGroup;
this.YGroup = YGroup;
this.owner.on(Laya.Event.CLICK, handler, func);
this.animator = this.owner.getComponent(Laya.Animator2D)
}
public setSelected(selected: boolean): void {
this.selected = selected
this.updateBlock()
}
public setButtonSkin(skin: string): void {
this.owner.skin = skin
}
public setFadeAnimation(): void {
if (this.animator) {
this.animator.play("fade_to_red")
Laya.timer.frameOnce(40, this, ()=>{
this.animator.stop()
})
}
}
public setBlock(preset: boolean, showNumber: number, correctNumber: number): void {
this.preset = preset;
@@ -63,18 +82,32 @@ export class Block extends Laya.Script {
return this.showNumber;
}
public getCorrectNumber(): number {
return this.correctNumber;
}
public setShowNumber(showNumber: number): boolean {
console.log("setShowNumber >>>>>", showNumber, this.correctNumber, this.XIndex, this.YIndex)
if (this.checked == false) {
if (showNumber == this.correctNumber)
this.checked = true;
this.showNumber = showNumber;
if (this.checked || showNumber == 0)//正确或者擦除
this.note_numbers = new Array()
this.updateBlock();
}
return this.checked
}
public addNoteNumber(noteNumber: number): void {
if (this.note_numbers.indexOf(noteNumber) < 0) {
this.note_numbers.push(noteNumber)
this.updateBlock();
}
}
updateBlock(): void {
for (var i=0; i<this.tips_labels.length; i++)
this.tips_labels[i].text = ""
if (this.showNumber > 0) {
this.label_show.text = this.showNumber.toString();
if (this.checked) {
@@ -86,6 +119,17 @@ export class Block extends Laya.Script {
}
else {
this.label_show.text = "";
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"
}
}
}
}

View File

@@ -10,11 +10,13 @@ export class Candy extends Laya.Script {
private showNumber: number = 0;
private left: number = 0;
public onInit(label_obj: Laya.Box, showNumber: number, handler: any, func: any): void {
public onInit(showNumber: number, label_obj: Laya.Box, handler: any, func: any): void {
this.showNumber = showNumber
this.label_show = label_obj.getChildByName("label") as Laya.Label
this.label_left = label_obj.getChildByName("label_left") as Laya.Label
this.showNumber = showNumber
this.owner.on(Laya.Event.CLICK, handler, func)
this.updateCandy()
}