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.
233 lines
8.9 KiB
233 lines
8.9 KiB
|
|
import WaiMaiQingDan_Config from "./WaiMaiQingDan_Config";
|
|
import Common5 from "../../../Platform/th/Common5";
|
|
|
|
import EventMgr from "../../../FrameWork/Event/EventMgr";
|
|
import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
|
|
import Game from "../../../Scripts/Game";
|
|
import Common from "../../../FrameWork/Util/Common";
|
|
const {ccclass, property} = cc._decorator;
|
|
|
|
enum CaiDanStatus{
|
|
Up,
|
|
Down
|
|
}
|
|
@ccclass
|
|
export default class WaiMaiQingDan extends cc.Component {
|
|
gameId:number = 0;
|
|
gameInfo = null;
|
|
touchZIdex = 999;
|
|
curDanHao = 0;//当前单号
|
|
|
|
|
|
onLoad () {
|
|
|
|
Common.Type = 0;
|
|
Common.subLevel = 0;
|
|
Common.GameSubTipConfigs=[Common5.gameConfig.zmGameConfig[Common5.selectGameNum].toolTip]
|
|
Common.GameSubAnswerConfigs=[Common5.gameConfig.zmGameConfig[Common5.selectGameNum].answer]
|
|
|
|
|
|
EventMgr.onEvent_custom(ryw_Event.timeOut, (tab) => {
|
|
Game.ins.showFail();
|
|
}, this);
|
|
this.gameId = Common5.gameConfig.zmGameConfig[Common5.selectGameNum].gameId
|
|
this.gameInfo = WaiMaiQingDan_Config.getInstance().getGoodsInfo(this.gameId)
|
|
}
|
|
|
|
start () {
|
|
this.initAllGoodsInfo()
|
|
}
|
|
//初始化所有物品
|
|
initAllGoodsInfo(){
|
|
let goodsNodeTab = this.node.getChildByName("goodsNode").children
|
|
for(var i=0;i<goodsNodeTab.length;i++){
|
|
let goodsName = goodsNodeTab[i].name
|
|
if(this.gameInfo.GoodsNode[goodsName]){
|
|
this.initGoodsNodeTouch(goodsNodeTab[i],this.gameInfo.GoodsNode[goodsName])
|
|
}
|
|
}
|
|
}
|
|
//初始化物品触摸事件
|
|
initGoodsNodeTouch(node:cc.Node,attr){
|
|
var attrs = {
|
|
startPos:node.getPosition(),//初始位置
|
|
attributeTab:attr
|
|
};
|
|
node.attr(attrs);
|
|
//开启触摸
|
|
if(this.gameInfo.GoodsNode[node.name].isCanTouch){
|
|
this.openTouchEvent(node)
|
|
}
|
|
}
|
|
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){
|
|
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){
|
|
Common5.playEffect("click")
|
|
event.target.zIndex = this.touchZIdex++
|
|
}
|
|
touchMoveNode(event){
|
|
//完成了组装
|
|
if(event.target.attributeTab.isFinishCompose){
|
|
return
|
|
}
|
|
let nodeLoc = event.getLocation()
|
|
let nodePos = event.target.parent.convertToNodeSpaceAR(nodeLoc)
|
|
event.target.setPosition(nodePos)
|
|
}
|
|
touchEndNode(event){
|
|
//这里是个补丁,不用合成直接打包的情况
|
|
if(this.gameInfo.GoodsNode[event.target.name].LinkName == "" && !event.target.attributeTab.isFinishCompose){
|
|
this.setComposeSpFrame(event.target,event.target.attributeTab.ComposeStr)
|
|
event.target.setPosition(event.target.startPos)
|
|
return
|
|
}
|
|
//完成了组装
|
|
if(event.target.attributeTab.isFinishCompose){
|
|
let flagIndex = this.getFinishGoodsFlagIndex(event.target.attributeTab.ComposeStr)
|
|
this.closeTouchEvent(event.target)
|
|
this.moveToWaiMaiXiang(event.target,flagIndex)
|
|
return
|
|
}
|
|
//当前类型节点是否与其他节点类型匹配
|
|
let curNodeTypeName = event.target.attributeTab.TypeName
|
|
for(var key in this.gameInfo.GoodsNode){
|
|
if(this.gameInfo.GoodsNode[key].LinkName && this.gameInfo.GoodsNode[key].LinkName != "" && this.gameInfo.GoodsNode[key].LinkName == curNodeTypeName){
|
|
//位置是否正确
|
|
let targetNode = this.getNodeByName(key)
|
|
if(targetNode.active && Common5.checkIntersectsBox(targetNode,event.target)){
|
|
console.log("合成成功")
|
|
Common5.playEffect("success2")
|
|
event.target.active = false
|
|
this.setComposeSpFrame(targetNode,event.target.attributeTab.ComposeStr)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
console.log("zindex还原")
|
|
event.target.zIndex = -1
|
|
event.target.setPosition(event.target.startPos)
|
|
}
|
|
//获取完成物品的flagIndex
|
|
getFinishGoodsFlagIndex(composeStr){
|
|
for(var key in this.gameInfo.ComposeSpFrame){
|
|
if(composeStr == this.gameInfo.ComposeSpFrame[key].TypeName){
|
|
return this.gameInfo.ComposeSpFrame[key].flagIndex
|
|
}
|
|
}
|
|
}
|
|
//获取物品节点
|
|
getNodeByName(nameStr){
|
|
let node = this.node.getChildByName("goodsNode").getChildByName(nameStr)
|
|
return node
|
|
}
|
|
//获取克隆的物品组合后的spriteFrame
|
|
getCloneComposeSpFrame(composeStr){
|
|
for(var key in this.gameInfo.ComposeSpFrame){
|
|
if(this.gameInfo.ComposeSpFrame[key].TypeName == composeStr){
|
|
let cloneNode = cc.instantiate(this.node.getChildByName("composeNode").getChildByName(key))
|
|
return cloneNode.getComponent(cc.Sprite).spriteFrame
|
|
}
|
|
}
|
|
}
|
|
//设置物品组合后的spriteFrame
|
|
setComposeSpFrame(targetNode,composeStr){
|
|
let composeFrame = this.getCloneComposeSpFrame(composeStr)
|
|
targetNode.getComponent(cc.Sprite).spriteFrame = composeFrame
|
|
//完成组合,类型名也变成合成后的名
|
|
targetNode.attributeTab.isFinishCompose = true
|
|
this.checkIsCanComposeAgain(targetNode,composeStr)
|
|
|
|
//播放合成特效
|
|
let composeSpine = this.node.getChildByName("composeSpine")
|
|
Common5.setNodeToTargetPos(composeSpine,targetNode)
|
|
composeSpine.active = true
|
|
composeSpine.getComponent(sp.Skeleton).setAnimation(0,"dianjiyanwu",false)
|
|
composeSpine.getComponent(sp.Skeleton).setCompleteListener((trackEntry,loopCount)=>{
|
|
composeSpine.active = false
|
|
})
|
|
|
|
|
|
}
|
|
//检查是否合成后的物品还可以合成(是的话,更改合成后的属性)
|
|
checkIsCanComposeAgain(targetNode,composeStr){
|
|
for(var key in this.gameInfo.GoodsNode){
|
|
if(this.gameInfo.GoodsNode[key].LinkName == composeStr){
|
|
targetNode.attributeTab.TypeName = composeStr
|
|
targetNode.attributeTab.LinkName = this.gameInfo.GoodsNode[key].TypeName
|
|
targetNode.attributeTab.ComposeStr = this.gameInfo.GoodsNode[key].ComposeStr
|
|
targetNode.attributeTab.isFinishCompose = false
|
|
return
|
|
}
|
|
}
|
|
}
|
|
//移动至外卖盒
|
|
moveToWaiMaiXiang(node,flagIndex){
|
|
let fixedArea = this.node.getChildByName("waiMaiXiangNode").getChildByName("fixedArea_"+this.curDanHao)
|
|
this.moveToTargetPosInTime(node,fixedArea,flagIndex)
|
|
}
|
|
//指定时间移动到特定位置
|
|
moveToTargetPosInTime(curNode,targetNode,flagIndex){
|
|
let timeNum = 0.4
|
|
//目标节点的本地坐标
|
|
let targetLocalPos = targetNode.getPosition()
|
|
//目标节点的世界坐标
|
|
let targetWorldPos = targetNode.parent.convertToWorldSpaceAR(targetLocalPos)
|
|
|
|
//目标节点相对于当前节点父节点的本地坐标
|
|
let localPos = curNode.parent.convertToNodeSpaceAR(targetWorldPos)
|
|
|
|
cc.tween(curNode)
|
|
.to(timeNum,{x:localPos.x,y:localPos.y})
|
|
.call(()=>{
|
|
Common5.playEffect("success")
|
|
this.setCaiDanBgUpOrDown(CaiDanStatus.Up)
|
|
})
|
|
.delay(0.2)
|
|
.call(()=>{
|
|
this.setCaiDanFlagVisible(flagIndex)
|
|
})
|
|
.start()
|
|
}
|
|
//设置菜单上标记
|
|
setCaiDanFlagVisible(flagIndex){
|
|
this.node.getChildByName("caiDanNode").getChildByName("caiDanBg").getChildByName("selectFlag_"+flagIndex).active = true
|
|
this.checkIsFinishTask()
|
|
}
|
|
checkIsFinishTask(){
|
|
this.curDanHao++
|
|
if(this.curDanHao >= this.gameInfo.CaiDanSum){
|
|
console.log("完成任务===")
|
|
Game.ins.showSuccess();
|
|
}
|
|
}
|
|
setCaiDanBgUpOrDown(status){
|
|
let caiDanBg = this.node.getChildByName("caiDanNode").getChildByName("caiDanBg")
|
|
let offsetY = 0
|
|
if(status == CaiDanStatus.Up){
|
|
offsetY = 0
|
|
}else if(status == CaiDanStatus.Down){
|
|
offsetY = -260
|
|
}
|
|
cc.tween(caiDanBg)
|
|
.to(0.3,{y:offsetY})
|
|
.start()
|
|
}
|
|
onClickKongBaiArea(){
|
|
this.setCaiDanBgUpOrDown(CaiDanStatus.Down)
|
|
}
|
|
onClickCaiDanArea(){
|
|
this.setCaiDanBgUpOrDown(CaiDanStatus.Up)
|
|
}
|
|
}
|
|
|