You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
324 lines
12 KiB
324 lines
12 KiB
import DaDianScript from "../../../FrameWork/Base/DaDianScript";
|
|
import WordGameBaseComponent from "../../../FrameWork/Base/WordGameBaseComptent";
|
|
import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
|
|
import EventMgr from "../../../FrameWork/Event/EventMgr";
|
|
|
|
import Common from "../../../FrameWork/Util/Common";
|
|
import Common5 from "../../../Platform/th/Common5";
|
|
import Game from "../../../Scripts/Game";
|
|
import CccGame from "../../../WordGame/gameComScript/CccGame/CccGame";
|
|
import logPrefabScript from "../../../WordGame/gameComScript/logPrefabScript";
|
|
// import NiXiRenShengConfig from "./NiXiRenShengConfig";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class NiXiRenShengScript extends WordGameBaseComponent {
|
|
|
|
@property(cc.Node)
|
|
layerNode: cc.Node[] = [];
|
|
|
|
@property(cc.Node)
|
|
chooseLayer: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
chooseContent: cc.Node = null;
|
|
|
|
//当前层级下标
|
|
curLayerIndex = 0;
|
|
//当前进度
|
|
curSchedule = [];
|
|
touchTargetNodeSet: Set<string> = null;
|
|
|
|
|
|
//文本配置
|
|
titleArrayConfig: string[] = [];
|
|
duihuaArrayConfig: any[] = [];
|
|
chooseListConfig: any = null;
|
|
|
|
|
|
|
|
start() {
|
|
super.start();
|
|
DaDianScript.userEnterDaDian();
|
|
this.openTouchEvent(this.node.getChildByName('bg'));
|
|
Common5.getJsonFromBundle(Common5.selectGameInfo.bundle,'script/NiXiRenShengConfig',(assest)=>{
|
|
this.jsonData = assest.json
|
|
this.initParameters();
|
|
this.initComponent();
|
|
})
|
|
Common5.playMusicCustom('nixirensheng', 'sound/背景')
|
|
|
|
}
|
|
|
|
initParameters() {
|
|
this.curLayerIndex = 0;
|
|
this.curSchedule = [];
|
|
this.touchTargetNodeSet = new Set();
|
|
this.titleArrayConfig = this.jsonData.titleArray //NiXiRenShengConfig.getInstance().getGameConfig('titleArray') as string[];
|
|
this.duihuaArrayConfig = this.jsonData.duihuaArray //NiXiRenShengConfig.getInstance().getGameConfig('duihuaArray') as any[];
|
|
this.chooseListConfig = this.jsonData.chooseList //NiXiRenShengConfig.getInstance().getGameConfig('chooseList');
|
|
Common.Type = this.curLayerIndex;
|
|
Common.subLevel = this.curLayerIndex;
|
|
Common.GameSubTipConfigs = this.jsonData.tipsArray //NiXiRenShengConfig.getInstance().getGameConfig('tipsArray');
|
|
Common.GameSubAnswerConfigs = this.jsonData.answersArray //NiXiRenShengConfig.getInstance().getGameConfig('answersArray');
|
|
|
|
EventMgr.onEvent_custom(ryw_Event.NormalTouchEndCheck, (data_) => {
|
|
this.normalTouchCallback(data_.targetNode);
|
|
}, this);
|
|
|
|
EventMgr.onEvent_custom(ryw_Event.NormalTouchMoveCheck, (data_) => {
|
|
this.normalTouchCallback(data_.targetNode);
|
|
}, this);
|
|
|
|
}
|
|
|
|
initComponent() {
|
|
for (const node of this.layerNode) {
|
|
node.active = false;
|
|
}
|
|
|
|
let title = this.titleArrayConfig[this.curLayerIndex];
|
|
let lab = this.node.getChildByName("标题").getChildByName("lab");
|
|
lab.getComponent(cc.Label).string = title;
|
|
|
|
|
|
Game.ins.setGameTitle(title)
|
|
|
|
for (let index = 0; index < this.chooseContent.children.length; index++) {
|
|
const element = this.chooseContent.children[index];
|
|
let funcGroup = CccGame.onNodeTouchMoreClickEvent(element, false, 1, { touchIndex: index });
|
|
funcGroup.setCompleteListener((data_) => {
|
|
this.nodeTouchClickCallback(data_.targetNode);
|
|
});
|
|
}
|
|
|
|
this.refreshLayer();
|
|
}
|
|
|
|
refreshLayer() {
|
|
let node = this.layerNode[this.curLayerIndex];
|
|
node.active = true;
|
|
|
|
if (this.curLayerIndex == 4) {
|
|
this.showDuiHua(this.duihuaArrayConfig[0], () => {
|
|
this.endGameView(0);
|
|
});
|
|
} else {
|
|
this.node.getChildByName("logLayer").active = true;
|
|
let chooseLog = this.chooseListConfig[this.curLayerIndex].chooseLog;
|
|
let log = this.node.getChildByName("logLayer").getChildByName("str");
|
|
log.getComponent(cc.Label).string = chooseLog;
|
|
|
|
this.chooseLayer.active = true;
|
|
let chooseIconList = this.chooseListConfig[this.curLayerIndex].chooseIconList;
|
|
for (let index = 0; index < chooseIconList.length; index++) {
|
|
const element = chooseIconList[index];
|
|
let icon = this.chooseContent.children[index].getChildByName("icon");
|
|
Common5.getSpriteFrameFromBundle("nixirensheng", element.url, icon.getComponent(cc.Sprite));
|
|
let nameTmp = element.url.split("/");
|
|
console.log("btnname:", nameTmp[nameTmp.length - 1]);
|
|
this.chooseContent.children[index].name = nameTmp[nameTmp.length - 1];
|
|
}
|
|
|
|
let chooseSays = this.chooseListConfig[this.curLayerIndex].chooseSays;
|
|
this.node.getChildByName("mask").active = true;
|
|
this.showDuiHua(chooseSays[0], () => {
|
|
if (chooseSays[1]) {
|
|
this.showDuiHua(chooseSays[1], () => {
|
|
this.node.getChildByName("mask").active = false;
|
|
});
|
|
} else {
|
|
this.node.getChildByName("mask").active = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
if (this.curLayerIndex == 3) {
|
|
let role = this.layerNode[this.curLayerIndex].getChildByName('美女');
|
|
role.children[this.curSchedule[2] - 1].active = true;
|
|
}
|
|
}
|
|
|
|
nodeTouchClickCallback(targetNode: cc.Node) {
|
|
console.log("+++++++++++++++++++++>" + targetNode.name);
|
|
this.chooseLayer.active = false;
|
|
let chooseInfo = this.chooseListConfig[this.curLayerIndex].chooseIconList[targetNode['touchIndex']];
|
|
if (this.curLayerIndex == 3 && targetNode['touchIndex'] == 0) {
|
|
// if (this.touchTargetNodeSet.has("开关")) {
|
|
// }
|
|
|
|
let role2 = this.layerNode[this.curLayerIndex].getChildByName('外卖员');
|
|
role2.getChildByName('手').active = false;
|
|
role2.getChildByName('手拿蛋糕').active = true;
|
|
this.showDuiHua(this.duihuaArrayConfig[1], () => {
|
|
this.endGameView(1);
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (chooseInfo.expression) {
|
|
let role = this.layerNode[this.curLayerIndex].getChildByName('美女');
|
|
for (const iterator of role.children) {
|
|
iterator.active = false;
|
|
}
|
|
role.getChildByName(chooseInfo.expression).active = true;
|
|
}
|
|
|
|
if (chooseInfo.Log) {
|
|
this.showDuiHua(chooseInfo.Log);
|
|
}
|
|
|
|
this.determine(targetNode['touchIndex']);
|
|
|
|
}
|
|
|
|
determine(touchIndex: number) {
|
|
this.curSchedule.push(touchIndex);
|
|
|
|
this.scheduleOnce(() => {
|
|
if (this.curSchedule.length < 3) {
|
|
this.nextLayer();
|
|
} else if (this.curSchedule.length == 3) {
|
|
if (this.curSchedule[0] == 1 && this.curSchedule[1] == 2) {
|
|
if (this.curSchedule[2] == 1 || this.curSchedule[2] == 2) {
|
|
this.nextLayer();
|
|
return;
|
|
}
|
|
}
|
|
this.curLayerIndex++;
|
|
this.nextLayer();
|
|
} else if (this.curSchedule.length == 4) {
|
|
this.endGameView(0);
|
|
}
|
|
}, 3.5);
|
|
}
|
|
|
|
normalTouchCallback(targetNode) {
|
|
console.log("+++++++++++++++++++++>" + targetNode.name);
|
|
this.touchTargetNodeSet.add(targetNode.name);
|
|
}
|
|
|
|
//显示对话
|
|
showDuiHua(curLog, func?) {
|
|
console.log("curLog==", curLog);
|
|
|
|
if (curLog.effectUrl) {
|
|
Common5.playEffectCustom("nixirensheng", curLog.effectUrl);
|
|
}
|
|
|
|
let string_ = curLog.str
|
|
let qiPaoPos_ = curLog.qiPaoPos
|
|
let delayTime_ = curLog.delayTime || 3;
|
|
|
|
let node = this.layerNode[this.curLayerIndex];
|
|
if (qiPaoPos_ != -1) {
|
|
let qiPao = node.getChildByName("qiPao").getChildByName("qiPao_" + qiPaoPos_);
|
|
qiPao.stopAllActions()
|
|
qiPao.getChildByName("str").getComponent(cc.Label).string = string_
|
|
qiPao.active = true
|
|
qiPao.scale = 0
|
|
cc.tween(qiPao)
|
|
.to(0.2, { scale: 1 })
|
|
.delay(delayTime_)
|
|
.call(() => {
|
|
qiPao.active = false
|
|
})
|
|
.start();
|
|
}
|
|
else {
|
|
let logPrefab = this.node.getChildByName('logPrefab')
|
|
let script_: logPrefabScript = logPrefab.getComponent('logPrefabScript')
|
|
script_.setDailogShow(string_, delayTime_)
|
|
}
|
|
|
|
this.scheduleOnce(() => {
|
|
if (func) {
|
|
func();
|
|
}
|
|
}, delayTime_);
|
|
}
|
|
|
|
nextLayer() {
|
|
this.curLayerIndex++;
|
|
//Common.subLevel = this.curLayerIndex;
|
|
this.node.getChildByName("logLayer").active = false;
|
|
for (let i = 0; i < this.layerNode.length; i++) {
|
|
if (this.layerNode[i].active) {
|
|
cc.tween(this.layerNode[i])
|
|
.delay(1.0)
|
|
.to(1, { opacity: 0 })
|
|
.call(() => {
|
|
this.layerNode[i].active = false;
|
|
this.refreshLayer();
|
|
})
|
|
.start();
|
|
} else {
|
|
this.layerNode[i].active = false;
|
|
}
|
|
};
|
|
}
|
|
|
|
endGameView(touchIndex: number) {
|
|
this.node.getChildByName("mask").active = true;
|
|
Game.ins.stopTime();
|
|
|
|
this.node.getChildByName("logLayer").active = false;
|
|
for (let i = 0; i < this.layerNode.length; i++) {
|
|
if (this.layerNode[i].active) {
|
|
cc.tween(this.layerNode[i])
|
|
.delay(1.0)
|
|
.to(1, { opacity: 0 })
|
|
.call(() => {
|
|
let endLayer = this.node.getChildByName("endLayer");
|
|
endLayer.active = true;
|
|
endLayer.getChildByName(touchIndex.toString()).active = true;
|
|
|
|
if (touchIndex == 0) {
|
|
this.scheduleOnce(() => {
|
|
Game.ins.showFail();
|
|
}, 3);
|
|
} else {
|
|
this.scheduleOnce(() => {
|
|
Game.ins.showSuccess();
|
|
}, 3);
|
|
}
|
|
})
|
|
.start();
|
|
} else {
|
|
this.layerNode[i].active = false;
|
|
}
|
|
};
|
|
}
|
|
|
|
openTouchEvent(node) {
|
|
node.on(cc.Node.EventType.TOUCH_START, this.touchStartNode, this)
|
|
node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this)
|
|
node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this)
|
|
node.on(cc.Node.EventType.TOUCH_END, this.touchEndNode, this)
|
|
}
|
|
|
|
closeTouchEvent(node: cc.Node) {
|
|
node.off(cc.Node.EventType.TOUCH_START, this.touchStartNode, this)
|
|
node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this)
|
|
node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this)
|
|
node.off(cc.Node.EventType.TOUCH_END, this.touchEndNode, this)
|
|
}
|
|
|
|
touchStartNode(event) {
|
|
let target = event.target;
|
|
console.log('touchStartNode');
|
|
}
|
|
|
|
touchMoveNode(event) {
|
|
|
|
}
|
|
|
|
touchEndNode(event) {
|
|
let target = event.target
|
|
let logPrefab = this.node.getChildByName('logPrefab')
|
|
logPrefab.getChildByName('duihua').active = false;
|
|
}
|
|
|
|
//update(dt) { }
|
|
}
|
|
|