觉醒时刻
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.
juexingshike/assets/Scripts/JuQingChat/JuQingDialog.ts

150 lines
5.5 KiB

1 week ago
import User from "../../FrameWork/User/User";
import Common5 from "../../Platform/th/Common5";
import PrefabManage from "../PrefabManager/PrefabManage";
import JuQingManager from "./JuQingManager";
const {ccclass, property} = cc._decorator;
@ccclass
export default class JuQingDialog extends cc.Component {
@property(cc.Node)
dialogStr: cc.Node = null;
@property(cc.Node)
leftAvatar: cc.Node = null;
@property(cc.Node)
rightAvatar: cc.Node = null;
@property(cc.Node)
leftPersonNameStr: cc.Node = null;
@property(cc.Node)
rightPersonNameStr: cc.Node = null;
@property(cc.Node)
leftDiKuang: cc.Node = null;
@property(cc.Node)
rightDiKuang: cc.Node = null;
@property(cc.Node)
guideNode: cc.Node = null;
curDialogIndex:number = 0
isCanClickNext:boolean = false
isFinishDialog:boolean = false
curDialogConfig = null
curPersonConfig = null
unLockTaskId:number = -1
unLockJuQingIndex:string = ""
nextJuQingID:number = 0
curJuQingUnLockIndex:string = ''
onLoad () {
}
start () {
this.curJuQingUnLockIndex = JuQingManager.getCurJuQingUnLockIndex()
this.curDialogConfig = JuQingManager.getJuQingJsonByIndexStr(this.curJuQingUnLockIndex)
this.curPersonConfig = JuQingManager.getPersonJsonByIndexStr(this.curJuQingUnLockIndex)
for(let i=0;i<this.curDialogConfig.length;i++){
if(this.curDialogConfig[i].indexStr == this.curJuQingUnLockIndex){
this.curDialogIndex = this.curDialogConfig[i].id
break
}
}
//手机对话假引导
if(this.curJuQingUnLockIndex == 'DH_1'){
this.guideNode.active = true
}
this.showDialogStr()
}
showDialogStr(){
if(!this.curDialogConfig[this.curDialogIndex]){
this.node.removeFromParent()
this.node.destroy()
PrefabManage.showSpecialTextTips('数据错误')
return
}
this.showSpineNode()
this.isCanClickNext = false
let curStr = ""
let curIndex = 0
let str = this.curDialogConfig[this.curDialogIndex].contentDesc
let callFunc = ()=>{
curStr += str[curIndex++]
this.dialogStr.getComponent(cc.Label).string = curStr
if(curIndex >= str.length){
if(this.curDialogConfig[this.curDialogIndex].isFinish){
this.isFinishDialog = true
// this.unLockTaskId = this.curDialogConfig[this.curDialogIndex].unLockTaskId
this.unLockJuQingIndex = this.curDialogConfig[this.curDialogIndex].unLockJuQingIndex
this.nextJuQingID = this.curDialogConfig[this.curDialogIndex].nextJuQingID
}
this.curDialogIndex = this.curDialogConfig[this.curDialogIndex].next
this.isCanClickNext = true
}
}
this.schedule( callFunc , 0.04,str.length-1)
}
showSpineNode(){
let speaker = this.curDialogConfig[this.curDialogIndex].speaker
if(speaker == 'other'){
this.leftPersonNameStr.active = true
this.leftPersonNameStr.getComponent(cc.Label).string = this.curPersonConfig.chatPersonName
this.leftDiKuang.active = true
this.rightDiKuang.active = false
this.rightPersonNameStr.active = false
this.leftAvatar.active = true
this.rightAvatar.active = false
Common5.getSpriteFrameFromBundle("GameRes","JuQingChat/texture/人物头像/"+this.curPersonConfig.chatPersonName,this.leftAvatar.getChildByName("spFrame").getComponent(cc.Sprite));
}else{
this.rightPersonNameStr.active = true
this.rightPersonNameStr.getComponent(cc.Label).string = '我'
this.leftPersonNameStr.active = false
this.leftDiKuang.active = false
this.rightDiKuang.active = true
this.leftAvatar.active = false
this.rightAvatar.active = true
Common5.getSpriteFrameFromBundle("CommonRes",
"texture/"+User.getHeadImg(),this.rightAvatar.getChildByName("spFrame").getComponent(cc.Sprite)
);
}
}
onBtnNextClick(){
Common5.playEffect("sound/按键点击")
if(!this.isCanClickNext){
return
}
this.guideNode.active = false
if(this.isFinishDialog){
JuQingManager.finishCurJuQing(this.curJuQingUnLockIndex,this.unLockJuQingIndex)
this.node.removeFromParent()
return
}
this.showDialogStr()
}
onBtnClose(){
while(!this.isFinishDialog){
if(this.curDialogConfig[this.curDialogIndex].isFinish){
this.isFinishDialog = true
this.unLockTaskId = this.curDialogConfig[this.curDialogIndex].unLockTaskId
this.unLockJuQingIndex = this.curDialogConfig[this.curDialogIndex].unLockJuQingIndex
this.nextJuQingID = this.curDialogConfig[this.curDialogIndex].nextJuQingID
}
this.curDialogIndex = this.curDialogConfig[this.curDialogIndex].next
}
//console.log('JuQingDialog onBtnClose this.unLockTaskId',this.unLockTaskId)
//console.log('JuQingDialog onBtnClose this.unLockJuQingIndex',this.unLockJuQingIndex)
//console.log('JuQingDialog onBtnClose this.nextJuQingID',this.nextJuQingID)
JuQingManager.finishCurJuQing(this.curJuQingUnLockIndex,this.unLockJuQingIndex)
this.node.removeFromParent()
return
}
}