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