350 lines
12 KiB
JavaScript
350 lines
12 KiB
JavaScript
|
|
var PathTool = require("pathtool");
|
||
|
|
var PathTool = require("pathtool");
|
||
|
|
var ChatConst = require("chat_const");
|
||
|
|
var ChatItemController = require("chat_item_controller");
|
||
|
|
var ChatHelp = require("chat_help");
|
||
|
|
var ChatController = require("chat_controller")
|
||
|
|
var RoleController = require("role_controller")
|
||
|
|
const BridgeComp = require("nx.fx.sv.expand.item")
|
||
|
|
|
||
|
|
cc.Class({
|
||
|
|
extends: BridgeComp,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
notice:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
head_con:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
playerInfos:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
nameNd:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
vipNd:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
honorNd:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
fabHeader:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Prefab
|
||
|
|
},
|
||
|
|
fabSys:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Prefab
|
||
|
|
},
|
||
|
|
fabOther:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Prefab
|
||
|
|
},
|
||
|
|
fabSelf:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Prefab
|
||
|
|
},
|
||
|
|
right:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// LIFE-CYCLE CALLBACKS:
|
||
|
|
|
||
|
|
rebind(_idx,_data,_key){
|
||
|
|
this._super();
|
||
|
|
this.setData(_data,_key);
|
||
|
|
},
|
||
|
|
|
||
|
|
|
||
|
|
setData(data,channel){
|
||
|
|
|
||
|
|
if(nx.dt.objEmpty(data)){
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.data = data;
|
||
|
|
this.channel = channel;
|
||
|
|
this.role_vo = RoleController.getInstance().getRoleVo();
|
||
|
|
|
||
|
|
this.bubble_bid = 0;
|
||
|
|
if (this.channel === ChatConst.Channel.Friend) {
|
||
|
|
if (this.data.flag === 1 || this.data.flag === 11 || !this.data.flag) {
|
||
|
|
this.is_mine = true;
|
||
|
|
this.face_id = this.role_vo.face_id;
|
||
|
|
this.r_name = this.role_vo.name;
|
||
|
|
this.srv_id = this.role_vo.srv_id;
|
||
|
|
this.bubble_bid = this.role_vo.bubble_bid;
|
||
|
|
} else {
|
||
|
|
this.is_mine = false;
|
||
|
|
this.face_id = this.data.face_id;
|
||
|
|
this.r_name = this.data.name;
|
||
|
|
this.srv_id = this.data.srv_id;
|
||
|
|
this.bubble_bid = this.data.bubble_bid;
|
||
|
|
}
|
||
|
|
} else if (this.channel === ChatConst.Channel.System) {
|
||
|
|
|
||
|
|
} else {
|
||
|
|
if(this.data && this.data.role_list && this.data.role_list[0]){
|
||
|
|
var msg_role = this.data.role_list[0]
|
||
|
|
if (msg_role.rid === this.role_vo.rid && msg_role.srv_id === this.role_vo.srv_id) {
|
||
|
|
this.is_mine = true;
|
||
|
|
}else{
|
||
|
|
this.is_mine = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.face_id = this.data.role_list[0].face_id;
|
||
|
|
this.r_name = this.data.role_list[0].name;
|
||
|
|
this.srv_id = this.data.role_list[0].srv_id;
|
||
|
|
this.avatar = this.data.role_list[0].head_bid;
|
||
|
|
this.bubble_bid = this.data.role_list[0].bubble_bid || this.data.role_list[0].chat_bubble;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
let msg
|
||
|
|
if(this.data.len == 0){
|
||
|
|
msg = this.data.msg; //StringUtil.parseStr(this.data.msg,"handler").string
|
||
|
|
}else{
|
||
|
|
msg = this.data.msg
|
||
|
|
}
|
||
|
|
// 对数据进行初始化
|
||
|
|
this.msg = msg;
|
||
|
|
this.head_path = PathTool.queryIconPath(this.face_id);
|
||
|
|
this.chat_item_ctrl = ChatItemController.getInstance();
|
||
|
|
// this.updateInterval = 1;
|
||
|
|
// this.updateTimer = 0;
|
||
|
|
// this.totalCount = 0;
|
||
|
|
|
||
|
|
this.updateWidget();
|
||
|
|
},
|
||
|
|
|
||
|
|
// 更新布局
|
||
|
|
updateWidget: function() {
|
||
|
|
|
||
|
|
let nod = nx.gui.find( this,"right/infos/srv" );
|
||
|
|
let self = this;
|
||
|
|
if (self.channel == ChatConst.Channel.System) {
|
||
|
|
self.head_con.active = false;
|
||
|
|
self.notice.active = true;
|
||
|
|
self.playerInfos.active = false;
|
||
|
|
|
||
|
|
if(self.msgItem){
|
||
|
|
self.msgItem.destroy();
|
||
|
|
}
|
||
|
|
if(!self.sysItem){
|
||
|
|
self.node.scaleX = Math.abs(this.node.scaleX);
|
||
|
|
self.sysItem = cc.instantiate(this.fabSys);
|
||
|
|
self.sysItem.parent = this.right;
|
||
|
|
|
||
|
|
}
|
||
|
|
nx.gui.setString(this.sysItem,"txt",this.msg);
|
||
|
|
} else {
|
||
|
|
self.notice.active = false;
|
||
|
|
self.head_con.active = true;
|
||
|
|
self.playerInfos.active = true;
|
||
|
|
|
||
|
|
// 布局 是否为是我
|
||
|
|
if(self.sysItem){
|
||
|
|
self.sysItem.destroy();
|
||
|
|
}
|
||
|
|
if(self.msgItem){
|
||
|
|
self.msgItem.destroy();
|
||
|
|
}
|
||
|
|
if (self.is_mine) {
|
||
|
|
self.msgItem = cc.instantiate(self.fabSelf);
|
||
|
|
self.msgItem.parent = self.right;
|
||
|
|
if(self.node.scaleX > 0){
|
||
|
|
self.node.scaleX *= -self.node.scaleX;
|
||
|
|
self.nameNd.scaleX = -self.nameNd.scaleX;
|
||
|
|
nod.scaleX = -nod.scaleX;
|
||
|
|
self.vipNd.scaleX = -self.vipNd.scaleX;
|
||
|
|
self.honorNd.scaleX = -self.honorNd.scaleX;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
self.msgItem = cc.instantiate(self.fabOther);
|
||
|
|
self.msgItem.parent = self.right;
|
||
|
|
if(self.node.scaleX < 0){
|
||
|
|
self.node.scaleX *= -self.node.scaleX;
|
||
|
|
self.nameNd.scaleX = -self.nameNd.scaleX;
|
||
|
|
nod.scaleX = -nod.scaleX;
|
||
|
|
self.vipNd.scaleX = -self.vipNd.scaleX;
|
||
|
|
self.honorNd.scaleX = -self.honorNd.scaleX;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let rtTxt = nx.gui.getComponent(self.msgItem,"txt",cc.RichText);
|
||
|
|
|
||
|
|
// 设置表情
|
||
|
|
// var item_imgs = this.chat_item_ctrl.getImages(self.msg);
|
||
|
|
// let len = item_imgs.length;
|
||
|
|
// for (var img_i in item_imgs) {
|
||
|
|
// var item_path = cc.path.join("resDB/emoj",item_imgs[img_i]);
|
||
|
|
// cc.loader.loadRes(item_path,cc.SpriteFrame, (err,item_sf)=> {
|
||
|
|
// if(!err){
|
||
|
|
// len--;
|
||
|
|
// rtTxt.addSpriteFrame(item_sf);
|
||
|
|
// }
|
||
|
|
// });
|
||
|
|
// }
|
||
|
|
|
||
|
|
rtTxt.maxWidth = 0;
|
||
|
|
rtTxt.string = self.msg;
|
||
|
|
if ((rtTxt.node.width) >= 510) {
|
||
|
|
rtTxt.maxWidth = 510;
|
||
|
|
} else {
|
||
|
|
rtTxt.maxWidth = rtTxt.node.width;
|
||
|
|
}
|
||
|
|
self.msgItem.height = rtTxt.node.height * Math.abs(rtTxt.node.scaleX) + 30;
|
||
|
|
|
||
|
|
if(!this.play_head){
|
||
|
|
this.play_head = cc.instantiate(this.fabHeader);
|
||
|
|
this.play_head.parent = this.head_con;
|
||
|
|
this.play_head.position = cc.v2(0,0);
|
||
|
|
}
|
||
|
|
|
||
|
|
let cmp = this.play_head.getComponent("cmp.common.header");
|
||
|
|
if(cmp){
|
||
|
|
let headinfo = {};
|
||
|
|
if( !this.data.role_list ){
|
||
|
|
|
||
|
|
headinfo = {
|
||
|
|
face_id : this.face_id ,
|
||
|
|
avatar : this.data.head_bid ,
|
||
|
|
}
|
||
|
|
|
||
|
|
}else{
|
||
|
|
headinfo = {
|
||
|
|
face_id : nx.dt.arrNEmpty( this.data.role_list ) ? this.data.role_list[0].face_id : this.role_vo.face_id,
|
||
|
|
avatar : nx.dt.arrNEmpty( this.data.role_list ) ? this.data.role_list[0].head_bid : this.role_vo.avatar_base_id,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
cmp.setData( headinfo );
|
||
|
|
cmp.addCallBack(this.upBtn.bind(this));
|
||
|
|
}
|
||
|
|
|
||
|
|
//聊天框
|
||
|
|
if(this.bubble_bid){
|
||
|
|
let bud_cfg = game.configs.say_data.data_say_frame[this.bubble_bid];
|
||
|
|
if(this.is_mine){
|
||
|
|
nx.bridge.setChatBubble( this.msgItem, "", this.bubble_bid );
|
||
|
|
}else{
|
||
|
|
nx.bridge.setChatBubble( this.msgItem, "", this.bubble_bid );
|
||
|
|
}
|
||
|
|
let cormp = nx.gui.find(this.msgItem,"txt");
|
||
|
|
let _hex = "#"+bud_cfg.color;
|
||
|
|
cormp.color = cormp.color.fromHEX(_hex);
|
||
|
|
}else{
|
||
|
|
if(this.is_mine){
|
||
|
|
nx.bridge.setChatBubble( this.msgItem, "", 1000 );
|
||
|
|
}else{
|
||
|
|
nx.bridge.setChatBubble( this.msgItem, "", 1000 );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// var role_data = this.data;
|
||
|
|
// if (this.channel === ChatConst.Channel.Friend) {
|
||
|
|
// role_data = this.data;
|
||
|
|
// } else {
|
||
|
|
// if(this.data && this.data.role_list && this.data.role_list[0]){
|
||
|
|
// role_data = this.data.role_list[0];
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// name
|
||
|
|
nx.gui.setString(this.nameNd,"",this.r_name);
|
||
|
|
let sid = this.srv_id.split( "_" );
|
||
|
|
nx.gui.setString(this,"right/infos/srv", "[" + nx.text.format( "Srever",sid[1] ) + "]" );
|
||
|
|
if(this.channel == ChatConst.Channel.Friend){
|
||
|
|
nx.gui.setString(this.vipNd,"txt",this.data.vip_lev);
|
||
|
|
nx.gui.setActive(this.vipNd,"",(this.data.vip_lev > 0));
|
||
|
|
let honor_id = 0;
|
||
|
|
for(let i in this.data.ext_list){
|
||
|
|
if(this.data.ext_list[i].type == 3){
|
||
|
|
honor_id = this.data.ext_list[i].val;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
let honor_cfg = game.configs.honor_data.data_title[honor_id];
|
||
|
|
if(honor_cfg && honor_cfg.res_id){
|
||
|
|
nx.gui.setSpriteFrame(this.honorNd,"",cc.js.formatStr("resDB/honors/%s",honor_cfg.res_id));
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
nx.gui.setString(this.vipNd,"txt",this.data.role_list[0].vip_lev);
|
||
|
|
nx.gui.setActive(this.vipNd,"",(this.data.role_list[0].vip_lev > 0));
|
||
|
|
let honor_id = 0;
|
||
|
|
for(let i in this.data.role_list[0].ext_list){
|
||
|
|
if(this.data.role_list[0].ext_list[i].type == 3){
|
||
|
|
honor_id = this.data.role_list[0].ext_list[i].val;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
let honor_cfg = game.configs.honor_data.data_title[honor_id];
|
||
|
|
if(honor_cfg && honor_cfg.res_id){
|
||
|
|
nx.gui.setSpriteFrame(this.honorNd,"",cc.js.formatStr("resDB/honors/%s",honor_cfg.res_id));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
let lay = nx.gui.getComponent(this.right,"",cc.Layout);
|
||
|
|
lay.updateLayout();
|
||
|
|
self.node.height = self.channel == ChatConst.Channel.System ? self.right.height + 40 : self.right.height + 10 ;
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
getId:function(){
|
||
|
|
if(!this.data)return null;
|
||
|
|
return this.data.id;
|
||
|
|
},
|
||
|
|
|
||
|
|
upBtn:function(){
|
||
|
|
//小于1秒时
|
||
|
|
this.touchHead();
|
||
|
|
this.totalCount = 0;
|
||
|
|
this.updateTimer = 0;
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
touchHead:function(){
|
||
|
|
var rid, srv_id,name;
|
||
|
|
if (this.channel === ChatConst.Channel.Friend) {
|
||
|
|
return;
|
||
|
|
} else {
|
||
|
|
if(this.data && this.data.role_list && this.data.role_list[0]){
|
||
|
|
rid = this.data.role_list[0].rid;
|
||
|
|
srv_id = this.data.role_list[0].srv_id;
|
||
|
|
name = this.data.role_list[0].name;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if(rid == this.role_vo.rid)return;
|
||
|
|
ChatController.getInstance().openFriendInfo({srv_id :srv_id, rid :rid,channel:this.channel,name:name});
|
||
|
|
},
|
||
|
|
|
||
|
|
onClickItem: function(msg) {
|
||
|
|
if(nx.dt.objEmpty(this.data)){
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
let parame = this.data.msg;
|
||
|
|
let paramtext = parame.indexOf("param='")
|
||
|
|
let href = parame.indexOf("href=")
|
||
|
|
if (href != -1 )
|
||
|
|
{
|
||
|
|
let str = parame.substring(href)
|
||
|
|
let arry = str.split(" ");
|
||
|
|
let temp = arry[0]
|
||
|
|
let params = temp.split("|");
|
||
|
|
let t1 = params[0].split("href=")
|
||
|
|
let link_type = t1[1]
|
||
|
|
let sev_id = params[1]
|
||
|
|
let share_id =params[2]
|
||
|
|
let pa = t1[1]+"|"+sev_id+"|"+share_id
|
||
|
|
ChatHelp.getInstance().onChatTouched(link_type, pa, this.data);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// update (dt) {},
|
||
|
|
});
|