完善撤回逻辑
This commit is contained in:
@@ -24,12 +24,8 @@ export const config = {
|
||||
BLUE: "#2559c0",
|
||||
},
|
||||
|
||||
UNDO_TYPE: {
|
||||
NORMAL: 1,
|
||||
NOTE: 2,
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ export class DOBlock {
|
||||
}
|
||||
public set_show(show: number): void {
|
||||
this.data.show = show
|
||||
if (show == this.get_correct())
|
||||
this.checked = true
|
||||
this.checked = show == this.get_correct()
|
||||
StorageManager.getInstance().onChanged()
|
||||
}
|
||||
|
||||
|
||||
@@ -129,8 +129,14 @@ export class DOStage {
|
||||
public get_undos(): Array<DataUndo> {
|
||||
return this.data.undos
|
||||
}
|
||||
public add_undo(type: number, index: number, value: number): void {
|
||||
var dataUndo: DataUndo = {type: type, index: index, value: value}
|
||||
public add_undo(index: number, show: number=0, notes: Array<number>=new Array()): void {
|
||||
var _notes: Array<number>
|
||||
if (notes) {
|
||||
_notes = new Array()
|
||||
for (var i=0; i<notes.length; i++)
|
||||
_notes.push(notes[i])
|
||||
}
|
||||
var dataUndo: DataUndo = {index: index, show: show, notes: _notes}
|
||||
console.log("add_undo >>>>>>>>>>>>>>>>>>>>>>>>>>>>", JSON.stringify(dataUndo))
|
||||
this.data.undos.push(dataUndo)
|
||||
StorageManager.getInstance().onChanged()
|
||||
|
||||
@@ -10,9 +10,9 @@ export interface DataBlock {
|
||||
|
||||
//撤回数据结构
|
||||
export interface DataUndo {
|
||||
type: number,
|
||||
index: number,
|
||||
value: number,
|
||||
show: number,
|
||||
notes?: Array<number>,
|
||||
}
|
||||
|
||||
//关卡数据
|
||||
|
||||
@@ -119,20 +119,18 @@ export class Block extends Laya.Script {
|
||||
}
|
||||
|
||||
public setShowNumber(showNumber: number): boolean {
|
||||
if (this.data.get_checked() == false) {
|
||||
this.data.set_show(showNumber)
|
||||
var score: number = 0
|
||||
if (this.newSelect) {
|
||||
this.newSelect = false
|
||||
if (this.data.get_checked()) {
|
||||
score = 150
|
||||
this.data.set_score(score)
|
||||
G_ShowScoreTips(score.toString(), this.label_show)
|
||||
}
|
||||
}
|
||||
this.data.clean_notes()
|
||||
this.updateBlock()
|
||||
}
|
||||
this.data.set_show(showNumber)
|
||||
// var score: number = 0
|
||||
// if (this.newSelect) {
|
||||
// this.newSelect = false
|
||||
// if (this.data.get_checked()) {
|
||||
// score = 150
|
||||
// this.data.set_score(score)
|
||||
// G_ShowScoreTips(score.toString(), this.label_show)
|
||||
// }
|
||||
// }
|
||||
this.data.clean_notes()
|
||||
this.updateBlock()
|
||||
return this.data.get_checked()
|
||||
}
|
||||
|
||||
@@ -149,6 +147,14 @@ export class Block extends Laya.Script {
|
||||
}
|
||||
this.updateBlock()
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
||||
updateBlock(): void {
|
||||
//设置文字颜色
|
||||
|
||||
@@ -52,6 +52,7 @@ export class Stage extends Laya.Script {
|
||||
private data: DOStage;
|
||||
private selectedBlock: Block;
|
||||
|
||||
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
|
||||
@@ -209,32 +210,28 @@ export class Stage extends Laya.Script {
|
||||
this.onApplyBlock(block)
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
|
||||
// }
|
||||
console.log("onClickUndo>>>>", JSON.stringify(undo))
|
||||
this.selectedBlock = this.blocks[undo.index]
|
||||
this.onApplyBlock(this.selectedBlock)
|
||||
if (undo.notes && undo.notes.length > 0) {
|
||||
this.selectedBlock.setNotes(undo.notes)
|
||||
}
|
||||
else {
|
||||
this.selectedBlock.setShowNumber(undo.show)
|
||||
}
|
||||
this.onSetBlock(this.selectedBlock)
|
||||
}
|
||||
}
|
||||
|
||||
onClickErase(evt: Laya.Event): void {
|
||||
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)
|
||||
if (this.selectedBlock.getData().get_checked() == false) {//未完成且有数字或者笔记才可以使用橡皮
|
||||
var show = this.selectedBlock.getData().get_show()
|
||||
var notes = this.selectedBlock.getData().get_notes()
|
||||
if (show > 0 || notes.length > 0) {
|
||||
this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes)
|
||||
this.selectedBlock.setShowNumber(0)
|
||||
this.onUpdateScore()
|
||||
this.onSetBlock(this.selectedBlock)
|
||||
@@ -288,6 +285,7 @@ export class Stage extends Laya.Script {
|
||||
this.data.set_hint(9)
|
||||
this.onUpdateHintStatus()
|
||||
}
|
||||
|
||||
}
|
||||
onUpdateHintStatus(): void {
|
||||
var hint = this.data.get_hint()
|
||||
@@ -297,6 +295,8 @@ export class Stage extends Laya.Script {
|
||||
}
|
||||
|
||||
public onApplyCandy(showNumber: number): void {
|
||||
var show = this.selectedBlock.getData().get_show()
|
||||
var notes = this.selectedBlock.getData().get_notes()
|
||||
if (this.selectedBlock.getData().get_checked() == false) {
|
||||
if (this.data.get_note_open()) {
|
||||
var relateds = this.findRelatedBlocks(this.selectedBlock)
|
||||
@@ -308,25 +308,26 @@ export class Stage extends Laya.Script {
|
||||
}
|
||||
}
|
||||
if (find == false) {
|
||||
this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes)
|
||||
this.selectedBlock.addNoteNumber(showNumber)
|
||||
this.onSetBlock(this.selectedBlock)
|
||||
}
|
||||
else {
|
||||
for (var i=0; i<relateds.length; i++) {
|
||||
var obj = relateds[i]
|
||||
if (obj.getData().get_show() == showNumber) {
|
||||
if (obj.getData().get_show() == showNumber && obj.getData().get_index() != this.selectedBlock.getData().get_index()) {
|
||||
obj.setFadeAnimation()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes)
|
||||
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 {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user