还有谁挑战
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.

217 lines
7.2 KiB

3 months ago
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 ItemIconList from "../../../WordGame/gameComScript/ItemIconList/ItemIconList";
import logPrefabScript from "../../../WordGame/gameComScript/logPrefabScript";
// import JieHunBiaoPeiConfig from "./JieHunBiaoPeiConfig";
const { ccclass, property } = cc._decorator;
@ccclass
export default class JieHunBiaoPeiScript extends WordGameBaseComponent {
@property(cc.Node)
ItemIconList: cc.Node = null;
@property(cc.Node)
checkNodeList: cc.Node = null;
@property(cc.Node)
targetNodeList: cc.Node[] = [];
//当前层级下标
curLayerIndex = 0;
//当前进度
curSchedule: Set<number> = null;
//文本配置
duihuaArrayConfig: any[] = [];
unitListConfig: any = null;
//计时
Timer = 0;
start() {
super.start();
DaDianScript.userEnterDaDian();
this.openTouchEvent(this.node.getChildByName('bg'));
Common5.stopMusic()
// this.initParameters();
// this.initComponent();
Common5.getJsonFromBundle(Common5.selectGameInfo.bundle,'script/JieHunBiaoPeiConfig',(assest)=>{
this.jsonData = assest.json
this.initParameters();
this.initComponent();
})
}
//初始化参数
initParameters() {
this.curSchedule = new Set();
this.duihuaArrayConfig = this.jsonData.duihuaArray// JieHunBiaoPeiConfig.getInstance().getGameConfig('duihuaArray');
this.unitListConfig = this.jsonData.unitList// JieHunBiaoPeiConfig.getInstance().getGameConfig('unitList');
Common.Type = 0;
Common.subLevel = 0;
Common.GameSubTipConfigs = this.jsonData.tipsArray//JieHunBiaoPeiConfig.getInstance().getGameConfig('tipsArray');
Common.GameSubAnswerConfigs = this.jsonData.answersArray//JieHunBiaoPeiConfig.getInstance().getGameConfig('answersArray');
EventMgr.onEvent_custom(ryw_Event.itemIconTouchTrue, (data_) => {
this.itemIconTouchCallback(data_.targetNode);
}, this);
EventMgr.onEvent_custom(ryw_Event.timeOut, (tab) => {
this.endGameView(0);
}, this);
}
//初始化组件
initComponent() {
let lab = this.node.getChildByName("标题").getChildByName("lab");
lab.getComponent(cc.Label).string = this.jsonData.titleArray//JieHunBiaoPeiConfig.getInstance().getGameConfig('titleArray');
Game.ins.setGameTitle('把物品分配给正确的人')
let scrZhuang: ItemIconList = this.ItemIconList.getComponent("ItemIconList");
scrZhuang.setIconListData(this.unitListConfig.unitIconList, this.checkNodeList.children, this.targetNodeList);
}
itemIconTouchCallback(targetNode: any) {
console.log("+++++++++++++++++++>" + targetNode.iconIndex);
this.curSchedule.add(targetNode.iconIndex);
if (this.curSchedule.size == this.unitListConfig.unitLog.length) {
let jianzhi = this.node.getChildByName("popUpNode").getChildByName("jianzhi");
let xi = this.node.getChildByName("layerNode").getChildByName("喜字");
let xi2 = this.node.getChildByName("layerNode").getChildByName("背景2").getChildByName("喜字");
let pos = Common5.getNodeToTargetPos(xi, xi2);
jianzhi.getComponent(sp.Skeleton).setAnimation(0, "jianzhi", false);
this.scheduleOnce(() => {
jianzhi.active = false;
cc.tween(xi)
.set({ active: true })
.to(2, { scale: 0.6, position: pos })
.call(() => {
this.showDuiHua(this.unitListConfig.unitLog[targetNode.iconIndex]);
this.scheduleOnce(() => {
this.endGameView(1);
}, 3);
})
.start();
}, 5);
return;
}
this.showDuiHua(this.unitListConfig.unitLog[targetNode.iconIndex]);
if (this.curSchedule.size == this.unitListConfig.unitLog.length - 1) {
this.node.getChildByName("caozuo").active = true;
}
}
//对话
showDuiHua(curLog, func?) {
console.log("curLog==", curLog);
if (curLog.effectUrl) {
Common5.playEffectCustom("jiehunbiaopei", curLog.effectUrl);
}
let string_ = curLog.str
let qiPaoPos_ = curLog.qiPaoPos
let delayTime_ = curLog.delayTime || 3;
if (qiPaoPos_ != -1) {
let qiPaoList = this.node.getChildByName("qiPao");
let qiPao = qiPaoList.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_);
}
endGameView(touchIndex) {
this.node.getChildByName("mask").active = true;
Game.ins.stopTime();
if (touchIndex == 0) {
this.scheduleOnce(() => {
Game.ins.showFail();
}, 2);
} else {
this.scheduleOnce(() => {
Game.ins.showSuccess();
},2);
}
}
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;
}
onClick(event) {
let target = event.target;
console.log("+++++++++++++++++++>" + target.name);
switch (target.name) {
case "button":
break;
default:
break;
}
}
//update(dt) { }
}