363 lines
12 KiB
JavaScript
363 lines
12 KiB
JavaScript
var SDKManage = require("SDKManage");
|
|
var NetManage = require("NetManage");
|
|
var playerData = require("playerData");
|
|
var gameConfig = require("gameConfig");
|
|
var Utils = require("Utils");
|
|
const BaseNet = require('../BaseNet');
|
|
|
|
function etos() {
|
|
return '<img src ="e' + arguments[0].match(/\d+/gi)[0] + '"/>';
|
|
}
|
|
|
|
var colortb = {
|
|
// 1 世界 2好友 3战队 o别人 m自己
|
|
o1: "#2BD6D6",
|
|
m1: "#2BD6D6",
|
|
o2: "#FFFFFF",
|
|
m2: "#FFFFFF",
|
|
o3: "#FFFFFF",
|
|
m3: "#FFFFFF",
|
|
};
|
|
|
|
var battlecolor = "#00ffff";
|
|
let m_data = null;
|
|
let m_roomID = null;
|
|
cc.Class({
|
|
extends: cc.viewcell,
|
|
|
|
properties: {
|
|
ly_up: {
|
|
default: null,
|
|
type: cc.Layout,
|
|
},
|
|
lb_name: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
lb_talk: {
|
|
default: null,
|
|
type: cc.RichText,
|
|
},
|
|
lb_zone: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
lb_talkNode: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
sp_head: {
|
|
default: null,
|
|
type: cc.Sprite,
|
|
},
|
|
sp_head_back: {
|
|
default: null,
|
|
type: cc.Sprite,
|
|
},
|
|
sp_sex: {
|
|
default: null,
|
|
type: cc.Sprite,
|
|
},
|
|
sp_vip: {
|
|
default: null,
|
|
type: cc.Sprite,
|
|
},
|
|
|
|
sp_rank: {
|
|
default: null,
|
|
type: cc.Sprite,
|
|
},
|
|
|
|
sp_lv: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
|
|
btn_join: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
nd_talkbg: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
m_item: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
m_offsetX: {
|
|
default: 0,
|
|
type: cc.Integer,
|
|
},
|
|
m_nameBg: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
m_paddingH: {
|
|
default: 30,
|
|
type: cc.Integer,
|
|
},
|
|
m_bgHeight: {
|
|
default: 40,
|
|
type: cc.Integer,
|
|
},
|
|
m_itemBg: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
|
|
start() {
|
|
this.iidex = 0;
|
|
|
|
this.m_chatPopPanelPrefab = null;
|
|
},
|
|
init: function (index, data, reload, group) {
|
|
if (index >= data.array.length) {
|
|
//越界
|
|
this.node.active = false;
|
|
return;
|
|
}
|
|
//this.btn_join.active = false
|
|
if (this.m_item) {
|
|
this.m_item.active = false;
|
|
}
|
|
|
|
this.node.width = data.width;
|
|
this.node.x = 0;
|
|
var sdata = data.array[index];
|
|
|
|
this.cdata = sdata;
|
|
this.m_data = sdata.sender.base_data;
|
|
//let rankScore = this.m_data.user_value1;
|
|
//let rankCfg = tonyInfo.instance().getRankCfgByScore(this.m_data.score);
|
|
//console.log("测试ItemData====",rankScore);
|
|
// this.setdata(sdata)
|
|
},
|
|
update(dt) {
|
|
if (this.cdata) {
|
|
this.setdata(this.cdata);
|
|
this.cdata = null;
|
|
}
|
|
},
|
|
|
|
showsenderinfo(userdata) {
|
|
var self = this;
|
|
self.sp_vip.spriteFrame = null;
|
|
|
|
this.lb_name.string = userdata.nickname;
|
|
Utils.setitem(this, userdata.avatar_url, this.sp_head);
|
|
Utils.setitem(this, userdata.head, this.sp_head_back);
|
|
},
|
|
|
|
setdata(data) {
|
|
let tmpState = 0;
|
|
if (this.lb_talkNode) {
|
|
this.lb_talkNode.active = false;
|
|
}
|
|
|
|
this.chat_channel = data.chat_channel;
|
|
|
|
var userdata = data.sender.base_data;
|
|
|
|
this.showsenderinfo(userdata);
|
|
this.account_id = userdata.account_id;
|
|
|
|
if (this.account_id == SDKManage.account_id) {
|
|
//todo 通过id 判断是否自己
|
|
this.setmode(true);
|
|
//this.nd_talkbg.color = new cc.color().fromHEX("#2BD6D6")
|
|
} else {
|
|
this.setmode(false);
|
|
//this.nd_talkbg.color = new cc.color().fromHEX("#2BD6D6")
|
|
}
|
|
|
|
this.lb_zone.string = '';
|
|
if (data.msg_type == 2) {
|
|
//纯文本
|
|
var str = data.msg_body;
|
|
var reg = /\(e\d+\)/gi;
|
|
str = str.replace(reg, etos);
|
|
this.lb_talk.string =
|
|
"<color=" + this.strcolor + ">" + str + "</color>";
|
|
} else if (data.msg_type == 1) {
|
|
//功能消息
|
|
|
|
let leftNode = this.m_item.getChildByName("left");
|
|
let rightNode = this.m_item.getChildByName("right");
|
|
leftNode.active = false;
|
|
rightNode.active = false;
|
|
let tmpNode = null;
|
|
if (this.account_id != SDKManage.account_id) {
|
|
//todo 通过id 判断是否自己
|
|
tmpNode = leftNode;
|
|
} else {
|
|
tmpNode = rightNode;
|
|
// this.btn_join.active = false;
|
|
}
|
|
tmpNode.active = true;
|
|
//this.btn_join.active = true
|
|
var jdata = JSON.parse(data.msg_body);
|
|
var tp = jdata.tp;
|
|
var tex = jdata.text;
|
|
let title = "测试Title";
|
|
if (jdata.title) {
|
|
title = jdata.title;
|
|
}
|
|
|
|
let titleNode = tmpNode.getChildByName("title");
|
|
let titleCom = titleNode.getComponent(cc.Label);
|
|
let tmpTxtNode = tmpNode.getChildByName("txt");
|
|
let tmpTxtCom = tmpTxtNode.getComponent(cc.Label);
|
|
titleCom.string = title;
|
|
tmpState = 1;
|
|
let roomID = jdata.roomid;
|
|
this.m_roomID = roomID;
|
|
this.m_item.active = true;
|
|
if (tp == 1) {
|
|
//战斗邀请
|
|
tmpTxtCom.string = "" + tex;
|
|
this.lb_zone.string = BaseNet.getZViewName(userdata.zid);
|
|
//tmpTxtCom.node.roomid = jdata.roomid
|
|
// tmpTxtCom.string = "<color=" + battlecolor + ">" + tex + "</color>"
|
|
//this.lb_talk.string = "<color=" + battlecolor + ">" + tex + "</color>" + "<on click=\"clickbattle\">"+ "<color=" + "#ff0000" + ">" + " 立即加入" + "</color>"+ "</on>"
|
|
//console.log("功能消息 ==========",this.account_id,SDKManage.account_id);
|
|
}
|
|
}
|
|
if (tmpState == 0) {
|
|
if (this.lb_talkNode) {
|
|
this.lb_talkNode.active = true;
|
|
}
|
|
//this.lb_talk._updateRenderData(true);
|
|
|
|
this.nd_talkbg.width = this.lb_talk._linesWidth[0] + 30;
|
|
let height = this.lb_talkNode.getContentSize().height;
|
|
let hCnt = Math.ceil(height / this.lb_talk.lineHeight);
|
|
if (hCnt >= 2) {
|
|
this.nd_talkbg.height =
|
|
this.m_bgHeight + (hCnt - 1) * this.m_paddingH;
|
|
}
|
|
}
|
|
},
|
|
|
|
onTure() {
|
|
if (playerData.teamuuid) {
|
|
cc.uiHelper.showTips("Please leave the current team first");
|
|
return;
|
|
}
|
|
if (this.m_roomID) {
|
|
cc.Notifier.emit("joinTeamRoom", "" + this.m_roomID);
|
|
}
|
|
|
|
// if (playerData.teamuuid) {
|
|
// if (playerData.team_list.length <= 1) {
|
|
// // cc.Notifier.emit('leaveflag', false)
|
|
// // NetManage.leaveTeam(playerData.teamuuid)
|
|
// playerData.teamuuid = null
|
|
// } else {
|
|
// cc.uiHelper.showTips('请先退出当前队伍')
|
|
// return
|
|
// }
|
|
// }
|
|
// playerData.callinvite = true
|
|
// playerData.teamuuid = this.lb_talk.node.roomid
|
|
// SDKManage.logEvent("invitation_ok", "邀请提示-点击同意")
|
|
// if (playerData.teamuuid) {
|
|
// var self = this
|
|
// var cb = function(res) {
|
|
// if (res.errcode == 0) {
|
|
// //console.log("callteam2")
|
|
// var cb2 = function() {
|
|
// cc.Notifier.emit('callteam')
|
|
// //cc.Notifier.emit('leaveflag', true)
|
|
// }
|
|
// var node_id = 1
|
|
// if (playerData.node_id != 0) {
|
|
// node_id = playerData.node_id
|
|
// }
|
|
// NetManage.getTeamInfo(playerData.teamuuid, playerData.node_id, cb2)
|
|
// } else {
|
|
// cc.uiHelper.showTips(cc.language.stringformat("notissetteam"));
|
|
// }
|
|
// }
|
|
// NetManage.joinTeam(playerData.teamuuid, playerData.cloth_id, playerData.hair_id, playerData.color_id,
|
|
// playerData.hat_id, playerData.rank, playerData.equip_id, cb, playerData.vip_level, playerData.head_kuang_id, playerData.nickname, playerData.avatar_id, playerData.sex)
|
|
// } else {
|
|
// playerData.teamuuid = null
|
|
// }
|
|
},
|
|
onBtnShowInfo() {
|
|
console.log("显示玩家信息======", this.m_data);
|
|
let accountID = SDKManage.account_id;
|
|
if (this.account_id == accountID) {
|
|
// cc.Notifier.emit("openSelfPlayerInfoUI");
|
|
return;
|
|
}
|
|
cc.Notifier.emit("chat_playerInfo", this.m_data);
|
|
},
|
|
|
|
setmode(isself) {
|
|
if (isself) {
|
|
let offsteX01 = -2;
|
|
this.ly_up.horizontalDirection = 1;
|
|
this.ly_up.node.anchorX = 1;
|
|
this.ly_up.node.x = 165 + offsteX01;
|
|
this.lb_name.node.anchorX = 1;
|
|
this.lb_talk.horizontalAlign = 2;
|
|
this.lb_talk.node.anchorX = 1;
|
|
this.lb_talk.node.x = this.ly_up.node.x - 20;
|
|
this.strcolor = colortb["m" + this.chat_channel];
|
|
this.lb_name.node.x = -70 + offsteX01;
|
|
this.sp_sex.node.x = -50 + offsteX01;
|
|
|
|
this.sp_lv.node.x = -1260 + offsteX01;
|
|
this.sp_rank.node.x = -1190 + offsteX01;
|
|
|
|
if (this.m_nameBg) {
|
|
this.m_nameBg.scaleX = -1;
|
|
this.m_nameBg.x = -86 + offsteX01;
|
|
}
|
|
if (this.m_itemBg) {
|
|
this.m_itemBg.scaleX = -0.5;
|
|
this.m_itemBg.x = 44 + offsteX01;
|
|
}
|
|
|
|
//this.nd_talkbg.x = this.lb_talk.node.x+20;
|
|
if (this.m_item) {
|
|
this.m_item.x = this.m_offsetX;
|
|
}
|
|
} else {
|
|
this.lb_name.node.x = 196;
|
|
this.sp_sex.node.x = 174;
|
|
this.ly_up.horizontalDirection = 0;
|
|
this.ly_up.node.anchorX = 0;
|
|
this.ly_up.node.x = -this.node.width / 2;
|
|
this.lb_name.node.anchorX = 0;
|
|
this.lb_talk.horizontalAlign = 0;
|
|
this.lb_talk.node.anchorX = 0;
|
|
this.lb_talk.node.x = this.ly_up.node.x + 80;
|
|
this.strcolor = colortb["o" + this.chat_channel];
|
|
// rankLv
|
|
this.sp_lv.node.x = -459;
|
|
this.sp_rank.node.x = -532;
|
|
if (this.m_itemBg) {
|
|
this.m_itemBg.scaleX = 0.5;
|
|
this.m_itemBg.x = -40;
|
|
}
|
|
|
|
if (this.m_nameBg) {
|
|
this.m_nameBg.scaleX = 1;
|
|
this.m_nameBg.x = 83;
|
|
}
|
|
|
|
if (this.m_item) {
|
|
this.m_item.x = -(this.node.width / 2 + this.m_offsetX);
|
|
}
|
|
}
|
|
},
|
|
});
|