import GameModel from "../../ts/core/GameModel"; import GameUtil from "../../ts/core/GameUtil"; import VIPUtil from "../../ts/game/role/VIPUtil"; import SKUIUtil from "../../ts/gear_2.3.4/util/SKUIUtil"; cc.Class({ extends: cc.Component, properties: { headSprite: cc.Sprite, headBorderNode: cc.Node, nameRT: cc.RichText, talkBgNode: cc.Node, richTextNode: cc.Node, yuyinNode: cc.Node, fontRes: cc.Font }, ctor() { this.roleid = 0; this.voice_index = 0; }, start() { this.yuyinNode.active = false; }, loadInfo(info) { this.roleid = info.roleid; let vipLevel = VIPUtil.getVipLevel(info.chargesum || 0); let prefix = vipLevel > 0 ? `` : ``; this.nameRT.node.color = GameUtil.getReliveColor(info.relive || 0); this.nameRT.string = `${prefix}${info.name}`; this.scheduleOnce(() => { this.headSprite.spriteFrame = GameModel.getRoleHead(info.resid); if (info.portrait) SKUIUtil.setHeadBorder(this.headBorderNode, info.portrait); else SKUIUtil.setHeadBorder(this.headBorderNode, 555100); }, 0) if (info.msg.length > 0) { this.setMsg(info.msg); } else { if (info.voice >= 0) { this.voice_index = info.voice; this.yuyinNode.active = true; this.setMsg(' [語音消息] '); } } }, setMsg(msg) { let richText = this.richTextNode.getComponent('CustomRichText'); richText.string = msg;//info.msg; richText.font = this.fontRes this.talkBgNode.width = richText.node.width + 25; this.talkBgNode.height = richText.node.height + 16; let bottom = this.talkBgNode.y - this.talkBgNode.height; if (-bottom > this.node.height) { this.node.height = -bottom; } }, onclicked(e, d) { if (this.voice_index < 0) { return; } this.playNodeVoice(); }, playVoiceAct() { var ani = this.yuyinNode.getComponent(cc.Animation); ani.play(); }, playNodeVoice(callback) { this.playVoiceAct(); GameModel.voiceMgr.playVoice(this.voice_index, () => { this.stopVoice(); if (callback) { callback(); } }); }, stopVoice() { var ani = this.yuyinNode.getComponent(cc.Animation); ani.stop(); }, });