// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import { ryw_Event } from "../../FrameWork/Event/EventEnum"; import EventMgr from "../../FrameWork/Event/EventMgr"; import User from "../../FrameWork/User/User"; import AppPlatform from "../../FrameWork/Util/AppPlatform"; import Common5 from "../../Platform/th/Common5"; import UiBase from "../GameBase/UiBase"; import TaskManager from "../JuQingChat/TaskManager"; import ChallengeManager from "../Manager/ChallengeManager"; import LevelUpManager from "../Manager/LevelUpManager"; import UserManager from "../Manager/UserManager"; const { ccclass, property } = cc._decorator; @ccclass export default class qipao extends UiBase { dialogIndex: number = 0; duihuakuang1: cc.Node; duihuakuang2: cc.Node; selectIndex: number = 0; chatConfig = [ { effectUrl: '', delayTime: 3, str: '建议直接一口价哦,选择出价有可能竞争不过,价格会更高哦!', posi: 'qipao2' }, { effectUrl: '', delayTime: 3, str: '哥哥,是不是还有秘书没有解锁啊', posi: 'qipao1' }, ] // LIFE-CYCLE CALLBACKS: // onLoad () {} start() { } /** * * @param index chatConfig下标 * @param isme 是自己的点击气泡还是默认气泡 * @param position 气泡位置 * @param func 说完话的回调 * @param aniFunc 说话时候的回调 */ init(index, isme, position, func?, aniFunc?) { if (isme) { this.showClickDialog(this.chatConfig[index], func, aniFunc) } else { this.showQiPao(this.chatConfig[index], func, aniFunc) } this.node.setPosition(cc.v2(position.x, position.y)) } // 展示气泡 showQiPao(curLog, func?, aniFunc?) { //cc.audioEngine.stopAllEffects(); if (!curLog) { 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; let qiPao = node.getChildByName(qiPaoPos_); qiPao.stopAllActions() this.showDialogStr(string_, qiPao.getChildByName("str")) // qiPao.getChildByName("str").getComponent(cc.Label).string = string_ qiPao.active = true // let scale = qiPao.scale qiPao.scale = 0 cc.tween(qiPao) .to(0.2, { scale: 1 / this.node.scale }) .delay(delayTime_) .call(() => { // qiPao.active = false; this.node.removeFromParent() this.node.destroy() }) .start(); } else { let chatLog = this.node.getChildByName('chatLog') chatLog.active = true if (curLog.endStr) { chatLog.getChildByName("str").getComponent(cc.Label).string = curLog.endStr } else { if (this.selectIndex == 1) { chatLog.getChildByName("str").getComponent(cc.Label).string = curLog.str1 } 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; this.node.removeFromParent() this.node.destroy() }) .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) node.name = "第二个选择" 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 } if (target.name == "第二个选择") { this.selectIndex = 1 } else { this.selectIndex = 0 } let clickDialog = this["_clickDialog"]; let clickDialogCallback = this["_clickDialogCallback"]; let clickDialogAniCallback = this["_clickDialogAniCallback"]; if (clickDialog) { this.showQiPao(clickDialog, () => { clickDialogCallback && clickDialogCallback(); }, clickDialogAniCallback); } } // update (dt) {} }