觉醒时刻
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.
 
 
 

147 lines
4.8 KiB

import User from "../../FrameWork/User/User";
import Common5 from "../../Platform/th/Common5";
const { ccclass, property } = cc._decorator;
@ccclass
export default class RoomBase extends cc.Component {
dialogIndex: number = 0;
duihuakuang1: cc.Node;
duihuakuang2: cc.Node;
start() {
// for (let i = 0; i < this.chatConfig.length; i++) {
// let effectUrl = this.chatConfig[i].effectUrl
// Common5.loadRemoteAudioEffect(effectUrl);
// }
// let head = this.node.getChildByName("对话框").getChildByName("头像");
// Common5.addUrlSprite_custom("head/" + User.getHeadImg(), head.getComponent(cc.Sprite));
this.dialogIndex = 0;
}
// 展示气泡
showQiPao(curLog, func?, aniFunc?) {
//cc.audioEngine.stopAllEffects();
if (!curLog) {
console.warn("警告:当前没有气泡消息")
return
}
if (curLog.effectUrl && curLog.effectUrl.length > 0) {
Common5.playRemoteAudioEffect(curLog.effectUrl);
// Common5.playEffectCustom("GameRes", curLog.effectUrl);
}
let string_ = curLog.str
let qiPaoPos_ = curLog.posi ?? curLog.qiPaoPos
let delayTime_ = curLog.delayTime ?? curLog.delay
if (aniFunc) {
aniFunc()
}
if (qiPaoPos_ != '-1') {
let node = this.node.getChildByName('qipao');
let qiPao = node.getChildByName(qiPaoPos_);
qiPao.stopAllActions()
this.showDialogStr(string_, qiPao.getChildByName("str"))
// 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 chatLog = this.node.getChildByName('chatLog')
chatLog.active = true
if (curLog.endStr) {
chatLog.getChildByName("str").getComponent(cc.Label).string = curLog.endStr
}else{
chatLog.getChildByName("str").getComponent(cc.Label).string = string_
}
//this.showDialogStr(string_, chatLog.getChildByName("str"))
chatLog.stopAllActions()
cc.tween(chatLog)
.delay(delayTime_)
.call(() => {
chatLog.active = false;
})
.start();
}
this.scheduleOnce(() => {
func && func();
}, delayTime_ + 0.2);
}
// 逐字显示
showDialogStr(str, dialogStr, finishFunc?) {
let curStr = ""
let curIndex = 0
let callFunc = () => {
curStr += str[curIndex++]
dialogStr.getComponent(cc.Label).string = curStr
if (curIndex >= str.length) {
finishFunc && finishFunc()
}
}
this.schedule(callFunc, 0.05, str.length - 1);
}
// 展示点击说话
showClickDialog(curLog, func?, aniFunc?) {
let text = curLog.str;
if (text.length > 7) {
text = curLog.str.slice(0, 6) + '...';
}
let dialog = this.node.getChildByName('对话框');
dialog.getChildByName('lab').getComponent(cc.Label).string = text;
dialog.active = true;
this["_clickDialog"] = curLog;
this["_clickDialogCallback"] = func;
this["_clickDialogAniCallback"] = aniFunc;
this.duihuakuang1 = dialog
if (curLog.str1) {
let text = curLog.str1;
if (text.length > 7) {
text = curLog.str1.slice(0, 6) + '...';
}
let node = cc.instantiate(dialog)
this.node.addChild(node)
let position = dialog.position.clone()
position.y += dialog.getContentSize().height
node.setPosition(position)
node.getChildByName('lab').getComponent(cc.Label).string = text;
this.duihuakuang2 = node
}
}
// 点击展示对话
onClickShowDialog(event) {
let target = event.target;
target.active = false;
if (this.duihuakuang1) {
this.duihuakuang1.active = false
}
if (this.duihuakuang2) {
this.duihuakuang2.active = false
}
let clickDialog = this["_clickDialog"];
let clickDialogCallback = this["_clickDialogCallback"];
let clickDialogAniCallback = this["_clickDialogAniCallback"];
if (clickDialog) {
this.showQiPao(clickDialog, () => {
clickDialogCallback && clickDialogCallback();
}, clickDialogAniCallback);
}
}
}