Files
fc/dev/project/library/imports/ea/ea798ea2-5ff4-45b5-8ece-32ada25c62f6.js
T

333 lines
11 KiB
JavaScript
Raw Normal View History

2026-05-24 10:21:26 +08:00
"use strict";
cc._RF.push(module, 'ea7986iX/RFtY7OMq2iXGL2', 'cmp.item.chat.player');
// Scripts/mod/chat/cmp/cmp.item.chat.player.js
"use strict";
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");
var 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: function rebind(_idx, _data, _key) {
this._super();
this.setData(_data, _key);
},
setData: function 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;
}
}
var 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 updateWidget() {
var nod = nx.gui.find(this, "right/infos/srv");
var 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;
}
}
var 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);
}
var cmp = this.play_head.getComponent("cmp.common.header");
if (cmp) {
var 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) {
var 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);
}
var cormp = nx.gui.find(this.msgItem, "txt");
var _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);
var 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);
var honor_id = 0;
for (var i in this.data.ext_list) {
if (this.data.ext_list[i].type == 3) {
honor_id = this.data.ext_list[i].val;
}
}
var 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);
var _honor_id = 0;
for (var _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;
}
}
var _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));
}
}
}
var 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 getId() {
if (!this.data) return null;
return this.data.id;
},
upBtn: function upBtn() {
//小于1秒时
this.touchHead();
this.totalCount = 0;
this.updateTimer = 0;
},
touchHead: function touchHead() {
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 onClickItem(msg) {
if (nx.dt.objEmpty(this.data)) {
return false;
}
var parame = this.data.msg;
var paramtext = parame.indexOf("param='");
var href = parame.indexOf("href=");
if (href != -1) {
var str = parame.substring(href);
var arry = str.split(" ");
var temp = arry[0];
var params = temp.split("|");
var t1 = params[0].split("href=");
var link_type = t1[1];
var sev_id = params[1];
var share_id = params[2];
var pa = t1[1] + "|" + sev_id + "|" + share_id;
ChatHelp.getInstance().onChatTouched(link_type, pa, this.data);
}
}
// update (dt) {},
});
cc._RF.pop();