添加撤回逻辑
This commit is contained in:
@@ -4,6 +4,7 @@ import { Block } from "./Block";
|
||||
import { Candy } from "./Candy";
|
||||
import { DOStage } from "../models/DOStage";
|
||||
import { config } from "../constants/config";
|
||||
import { DataUndo } from "../types/global";
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
|
||||
@@ -48,8 +49,8 @@ export class Stage extends Laya.Script {
|
||||
private btn_hint_ad: Laya.Box
|
||||
private btn_hint_label: Laya.Label
|
||||
|
||||
private selectedBlock: Block;
|
||||
private data: DOStage;
|
||||
private selectedBlock: Block;
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
@@ -64,17 +65,17 @@ export class Stage extends Laya.Script {
|
||||
var block = hbox.getChildAt(j).getComponent(Block);
|
||||
this.blocks.push(block);
|
||||
var XGroup = 0;
|
||||
if (i==3 || i==4 || i==5)
|
||||
if (j==3 || j==4 || j==5)
|
||||
XGroup = 1
|
||||
if (i==6 || i==7 || i==8)
|
||||
if (j==6 || j==7 || j==8)
|
||||
XGroup = 2
|
||||
var YGroup = 0;
|
||||
if (j==3 || j==4 || j==5)
|
||||
if (i==3 || i==4 || i==5)
|
||||
YGroup = 1
|
||||
if (j==6 || j==7 || j==8)
|
||||
if (i==6 || i==7 || i==8)
|
||||
YGroup = 2
|
||||
var l_vbox = l_hbox.getChildAt(j) as Laya.Box
|
||||
block.onInit(i, j, XGroup, YGroup, l_vbox, this, this.onClickBlock)
|
||||
block.onInit(j, i, XGroup, YGroup, l_vbox, this, this.onClickBlock)
|
||||
}
|
||||
}
|
||||
for (var i=0; i<this.obj_candys.numChildren; i++) {
|
||||
@@ -93,8 +94,6 @@ export class Stage extends Laya.Script {
|
||||
this.btn_hint_normal = this.btn_hint.getChildByName("Image").getChildByName("normal") as Laya.Box
|
||||
this.btn_hint_ad = this.btn_hint.getChildByName("Image").getChildByName("ad") as Laya.Box
|
||||
this.btn_hint_label = this.btn_hint.getChildByName("Image").getChildByName("normal").getChildByName("label") as Laya.Label
|
||||
|
||||
this.selectedBlock = null;
|
||||
}
|
||||
|
||||
public onLoadStage(doStage: DOStage): void {
|
||||
@@ -124,15 +123,12 @@ export class Stage extends Laya.Script {
|
||||
block.setBlock(doBlock)
|
||||
block.setTipsBgColor(false)
|
||||
}
|
||||
var candys = doStage.get_candys()
|
||||
for (var i=0; i<candys.length; i++) {
|
||||
var doCandy = candys[i]
|
||||
var candy = this.candys[i]
|
||||
candy.setCandy(doCandy)
|
||||
}
|
||||
|
||||
this.onUpdateCandys()
|
||||
this.onClickNote(null)
|
||||
this.onUpdateHintStatus()
|
||||
|
||||
this.selectedBlock = this.blocks[this.data.get_select_index()]
|
||||
this.onApplyBlock(this.selectedBlock)
|
||||
}
|
||||
|
||||
onUpdateScore(): void {
|
||||
@@ -200,25 +196,49 @@ export class Stage extends Laya.Script {
|
||||
}
|
||||
}
|
||||
}
|
||||
onClickBlock(evt: Laya.Event): void {
|
||||
if (this.selectedBlock)
|
||||
this.selectedBlock.setSelected(false)
|
||||
var block = evt.target.getComponent(Block);
|
||||
block.setSelected(true)
|
||||
this.onSetBlock(block)
|
||||
|
||||
onApplyBlock(block: Block): void {
|
||||
this.selectedBlock.setSelected(false)
|
||||
this.selectedBlock = block
|
||||
this.selectedBlock.setSelected(true)
|
||||
this.onSetBlock(this.selectedBlock)
|
||||
this.data.set_select_index(this.selectedBlock.getData().get_index())
|
||||
}
|
||||
onClickBlock(evt: Laya.Event): void {
|
||||
var block = evt.target.getComponent(Block)
|
||||
this.onApplyBlock(block)
|
||||
}
|
||||
|
||||
|
||||
onClickUndo(evt: Laya.Event): void {
|
||||
onApplyUndo(undo: DataUndo): void {
|
||||
|
||||
}
|
||||
onClickUndo(evt: Laya.Event): void {
|
||||
var undo = this.data.pop_undo()
|
||||
if (undo) {
|
||||
// console.log("onClickUndo>>>>", JSON.stringify(undo))
|
||||
// this.selectedBlock = this.blocks[undo.index]
|
||||
// this.onApplyBlock(this.selectedBlock)
|
||||
// if (undo.type == config.UNDO_TYPE.NORMAL) {
|
||||
// var block = this.blocks[undo.index]
|
||||
|
||||
// this.selectedBlock.setShowNumber(undo.value)
|
||||
// this.onSetBlock(this.selectedBlock)
|
||||
// }
|
||||
// else if (undo.type == config.UNDO_TYPE.NOTE) {
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
onClickErase(evt: Laya.Event): void {
|
||||
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {
|
||||
this.selectedBlock.setShowNumber(0)
|
||||
this.onUpdateScore()
|
||||
this.onSetBlock(this.selectedBlock)
|
||||
if (this.selectedBlock.getData().get_checked() == false) {//未完成切有数字或者笔记才可以使用橡皮
|
||||
if (this.selectedBlock.getData().get_show() > 0 || this.selectedBlock.getData().get_notes().length > 0) {
|
||||
this.data.add_undo(config.UNDO_TYPE.NORMAL, this.selectedBlock.getData().get_index(), 0)
|
||||
this.selectedBlock.setShowNumber(0)
|
||||
this.onUpdateScore()
|
||||
this.onSetBlock(this.selectedBlock)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,10 +256,9 @@ export class Stage extends Laya.Script {
|
||||
onClickHint(evt: Laya.Event): void {
|
||||
var hint = this.data.get_hint()
|
||||
if (hint > 0) {
|
||||
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {//当前选中的格子没有完成
|
||||
if (this.selectedBlock.getData().get_checked() == false) {//当前选中的格子没有完成
|
||||
var correct = this.selectedBlock.getData().get_correct()
|
||||
var candy = this.candys[correct-1]
|
||||
this.onApplyCandy(candy)
|
||||
this.onApplyCandy(correct)
|
||||
this.data.set_hint(hint-1)
|
||||
this.onUpdateHintStatus()
|
||||
}
|
||||
@@ -256,10 +275,9 @@ export class Stage extends Laya.Script {
|
||||
if (index >= list.length)
|
||||
index = list.length -1
|
||||
var block = list[index]
|
||||
this.selectedBlock = block
|
||||
this.onApplyBlock(block)
|
||||
var correct = block.getData().get_correct()
|
||||
var candy = this.candys[correct-1]
|
||||
this.onApplyCandy(candy)
|
||||
this.onApplyCandy(correct)
|
||||
this.data.set_hint(hint-1)
|
||||
this.onUpdateHintStatus()
|
||||
}
|
||||
@@ -278,9 +296,8 @@ export class Stage extends Laya.Script {
|
||||
this.btn_hint_label.text = hint.toString()
|
||||
}
|
||||
|
||||
public onApplyCandy(candy: Candy): void {
|
||||
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {
|
||||
var showNumber = candy.getData().get_show()
|
||||
public onApplyCandy(showNumber: number): void {
|
||||
if (this.selectedBlock.getData().get_checked() == false) {
|
||||
if (this.data.get_note_open()) {
|
||||
var relateds = this.findRelatedBlocks(this.selectedBlock)
|
||||
var find = false
|
||||
@@ -304,16 +321,16 @@ export class Stage extends Laya.Script {
|
||||
}
|
||||
else {
|
||||
if (this.selectedBlock.getData().get_show() == showNumber) {
|
||||
this.data.add_undo(config.UNDO_TYPE.NORMAL, this.selectedBlock.getData().get_index(), 0)
|
||||
this.selectedBlock.setShowNumber(0);
|
||||
this.onSetBlock(this.selectedBlock)
|
||||
}
|
||||
else {
|
||||
var b = this.selectedBlock.setShowNumber(showNumber);
|
||||
this.data.add_undo(config.UNDO_TYPE.NORMAL, this.selectedBlock.getData().get_index(), showNumber)
|
||||
var b = this.selectedBlock.setShowNumber(showNumber)
|
||||
this.onUpdateScore()
|
||||
this.onSetBlock(this.selectedBlock, true)
|
||||
if (b) {
|
||||
var left = candy.getData().get_left();
|
||||
candy.setLeft(left-1);
|
||||
if (this.getIsComplete()) {
|
||||
console.log("完成关卡")
|
||||
UIManager.getInstance().loadGameDone()
|
||||
@@ -328,20 +345,39 @@ export class Stage extends Laya.Script {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.onUpdateCandys()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public onClickCandy(evt: Laya.Event): void {
|
||||
var candy = evt.target.getComponent(Candy);
|
||||
this.onApplyCandy(candy)
|
||||
this.onApplyCandy(candy.get_show())
|
||||
}
|
||||
|
||||
onKeyUp(evt: Laya.Event): void {
|
||||
var n = Number(evt.key)
|
||||
if (n && n > 0) {
|
||||
var candy = this.candys[n-1]
|
||||
this.onApplyCandy(candy)
|
||||
this.onApplyCandy(n)
|
||||
}
|
||||
}
|
||||
|
||||
onUpdateCandys(): void {
|
||||
var list: Map<number, number> = new Map()
|
||||
for (var i=1; i<=9; i++)
|
||||
list.set(i, 0)
|
||||
for (var i=0; i<this.blocks.length; i++) {
|
||||
var block = this.blocks[i]
|
||||
if (block.getData().get_checked() == false) {
|
||||
var correct = block.getData().get_correct()
|
||||
list.set(correct, list.get(correct)+1)
|
||||
}
|
||||
}
|
||||
for (var i=0; i<this.candys.length; i++) {
|
||||
var candy = this.candys[i]
|
||||
var show = i+1
|
||||
var left = list.get(show)
|
||||
candy.setCandy(show, left)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user