zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

711 lines
21 KiB
JavaScript

var SDKManage = require("SDKManage");
var NetManage = require("NetManage");
var playerData = require("playerData");
var gameConfig = require("gameConfig");
var Main = require("Main");
var pbheight = 110;
cc.Class({
extends: cc.Component,
properties: {
nd_friend: {
default: null,
type: cc.Node,
},
editbox: {
default: null,
type: cc.EditBox,
},
tableview_world: {
default: null,
type: cc.Node,
},
tableViewfriend: {
default: null,
type: cc.Node,
},
scollViewEmote: {
default: null,
type: cc.Node,
},
tableFriendList: {
default: null,
type: cc.Node,
},
nd_emot: {
default: null,
type: cc.Node,
},
nd_worldred: {
default: null,
type: cc.Node,
},
nd_guildred: {
default: null,
type: cc.Node,
},
nd_friendred: {
default: null,
type: cc.Node,
},
pb_friendinfo: {
default: null,
type: cc.Prefab,
},
moveContent: {
default: null,
type: cc.Node,
},
movePrefab: {
default: null,
type: cc.Prefab,
},
nd_guild: {
default: null,
type: cc.Node,
},
nd_team: {
default: null,
type: cc.Node,
},
nd_bg: {
default: [],
type: cc.Node,
},
lb_frinamechat: {
default: null,
type: cc.Label,
},
lb_friendnum: {
default: null,
type: cc.Label,
},
lb_labanum: {
default: null,
type: cc.Label,
},
pb_dalaba: {
default: null,
type: cc.Prefab,
},
emoteatlas: {
default: null,
type: cc.SpriteAtlas,
},
pb_chatemote: {
default: null,
type: cc.Prefab,
},
pb_charinfo: {
default: null,
type: cc.Prefab,
},
nd_emotepos: {
default: null,
type: cc.Node,
},
m_10105Com: {
default: null,
type: cc.Label,
},
emoteMax: 7,
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
this.editbox.node.on("editing-did-began", this.callbackbegin, this);
this.editbox.node.on("editing-did-ended", this.callbackend, this);
this.editbox.node.on("editing-return", this.callbackend, this);
this.nd_emot.on(
cc.Node.EventType.TOUCH_START,
this._touchnd_emot,
this
);
cc.Notifier.on("refreshchat", this, this.refreshchat.bind(this));
cc.Notifier.on("refreshchatred", this, this.refreshchatred.bind(this));
cc.Notifier.on("showplayerinfo", this, this.showplayerinfo.bind(this));
cc.Notifier.on("refreshdalaba", this, this.refreshdalaba.bind(this));
cc.Notifier.on("deleteItem", this, this.deleteItem.bind(this));
cc.Notifier.on("clickemote", this, this.doemot.bind(this));
cc.Notifier.on("callemote", this, this.callemote.bind(this));
cc.Notifier.on("closeemote", this, this._touchnd_emot.bind(this));
cc.Notifier.on("setemotepos", this, this.setemotepos.bind(this));
cc.Notifier.on("jointeam", this, this.joinTeam.bind(this));
cc.Notifier.on(
"SMGuildInfo",
this,
this.getGuildInfoCallBack.bind(this)
);
cc.Notifier.on("chat_playerInfo", this, this.getPlayerInfo.bind(this)); //查看玩家信息
cc.Notifier.on(
"friendlist",
this,
this.SMFriendListCallBack.bind(this)
); //好友列表
cc.Notifier.on("closechat", this, this.closechat.bind(this));
this.moveTextTime = 0;
cc.uiChat = this;
this.isCreate = false;
this.m_btnType = 1;
this.m_btnData = 0;
console.log("UIChatOnLoad");
},
start() {
this.nd_emot.active = false;
this.m_chatItemData = null; //单个玩家的信息
if (this.m_btnType == 1) {
this.callworld();
}
console.log("UIChatStart");
this.refreshchatred();
cc.chatMgr.sendmsg("CMFriendList");
this.nd_team.active = false;
this.nd_guild.active = false;
if (playerData.teamuuid) {
this.nd_team.active = true;
}
// if (playerData.guild_id != '0') {
// this.nd_guild.active = true
// }
this.lb_labanum.string = 0;
// for (var j = 0; j < playerData.bag_list.length; j++) {
// if (gameConfig.wai_itemConfig[playerData.bag_list[j].id].fuction == 23) {
// this.lb_labanum.string = playerData.bag_list[j].num
// this.dalabanum = playerData.bag_list[j].num
// break;
// }
// }
},
onDestroy() {
this.nd_emot.off(
cc.Node.EventType.TOUCH_START,
this._touchnd_emot,
this
);
cc.Notifier.off("refreshchat", this);
cc.Notifier.off("refreshchatred", this);
cc.Notifier.off("showplayerinfo", this);
cc.Notifier.off("refreshdalaba", this);
cc.Notifier.off("deleteItem", this);
cc.Notifier.off("clickemote", this);
cc.Notifier.off("callemote", this);
cc.Notifier.off("closeemote", this);
cc.Notifier.off("setemotepos", this);
cc.Notifier.off("jointeam", this);
cc.Notifier.off("chat_playerInfo", this);
cc.Notifier.off("SMGuildInfo", this);
cc.Notifier.off("friendlist", this);
cc.Notifier.off("closechat", this);
},
refreshchat(msg) {
var functionarr = [
this.callworld.bind(this),
this.callfriend.bind(this),
this.callguild.bind(this),
this.callteam.bind(this),
];
if (msg[this.mode - 1]) {
functionarr[this.mode - 1]();
}
},
deleteItem(obj) {
if (obj.errcode == 0) {
this.dalabanum = obj.num;
}
},
refreshdalaba() {
//console.log("ResetDalab01a",cc.talkmgr.dalabamsg);
this.moveTextTime = 0;
if (cc.talkmgr.dalabamsg && cc.talkmgr.dalabamsg.length != 0) {
var self = this;
var dalabadata = cc.talkmgr.dalabamsg;
self.addMoveText(dalabadata[0].sender, dalabadata[0].msg_body);
cc.talkmgr.dalabamsg.splice(0, 1);
}
},
refreshchatred() {
this.nd_friendred.active = playerData.chatfriendred;
this.nd_guildred.active = playerData.chatguildred;
this.nd_worldred.active = playerData.chatworldred;
},
showplayerinfo(obj) {
// var nd = cc.instantiate(this.pb_friendinfo)
// nd.zIndex = 2
// this.node.addChild(nd)
// nd.getComponent("UIFriendInfo").showAddBtn(obj)
},
setemotepos(obj) {
this.nd_emotepos.x = obj.x;
this.nd_emotepos.y = obj.y;
},
_touchnd_emot() {
this.nd_emot.active = false;
},
callbackbegin(editbox) {
// 回调的参数是 editbox 组件
// do whatever you want with the editbox
this.close_status = false;
},
callbackend(editbox) {
this.close_status = true;
},
showpick() {
for (var i = 0; i < this.nd_bg.length; i++) {
this.nd_bg[i].active = false;
if (i == this.mode - 1) {
this.nd_bg[i].active = true;
}
}
},
showTipNotSend(time) {
var tempstr = cc.language.stringformat("shuohuataikuai", [
Math.ceil(time),
]);
cc.uiHelper.showTips(tempstr);
this.editbox.string = "";
},
sendmsg() {
this.nd_emot.active = false;
if (this.editbox.string == "") {
cc.uiHelper.showTips(cc.language.stringformat("neitongweikong"));
return;
}
var str = this.editbox.string;
var target = "";
var members = [];
var tempstr = "";
if (this.mode == 1) {
var lasttalketime = playerData.worldtime;
var nowtime = new Date().getTime();
var delta = (nowtime - lasttalketime) / 1000;
if (delta < 40) {
this.showTipNotSend(40 - delta);
return;
} else {
playerData.worldtime = nowtime;
playerData.canWorldMsg = false;
}
} else if (this.mode == 2) {
target = this.sendid;
if (!playerData.canFriendMsg) {
this.showTipNotSend(playerData.friendtime);
return;
} else {
playerData.friendtime = 3;
playerData.canFriendMsg = false;
}
} else if (this.mode == 3) {
if (!playerData.canGuildMsg) {
this.showTipNotSend(playerData.guildtime);
return;
} else {
playerData.guildtime = 3;
playerData.canGuildMsg = false;
}
} else {
if (
this.mode == 4 &&
playerData.team_list &&
playerData.team_list.length != 0
) {
var data = playerData.team_list;
for (var i in data) {
members.push(data[i].account_id);
}
// if (!playerData.canTeamMsg) {
// this.showTipNotSend(playerData.teamtime)
// return
// }
}
}
cc.chatMgr.sendmsg("CMSendChatMsg", {
chat_channel: this.mode,
target: target,
msg_type: 2,
msg_body: str,
members: members,
});
this.editbox.string = "";
},
senddalaba() {
// var str = this.editbox.string
// var target = ''
// cc.chatMgr.sendmsg('CMSendChatMsg', {
// chat_channel: 5,
// target: target,
// msg_type: 2,
// msg_body: str,
// })
// this.editbox.string = ''
// if (Number(this.dalabanum) <= 0 || !this.dalabanum) {
// cc.uiHelper.showTips(cc.language.stringformat("lbbz"))
// return
// }
return;
var nd = cc.instantiate(this.pb_dalaba);
nd.zIndex = 2;
this.node.addChild(nd);
},
callworld() {
this.mode = 1;
this.showpick();
this.last_id = cc.talkmgr.getAllLastid();
cc.chatMgr.sendmsg("CMReadMsgAndOpenChatNotify", {
last_ids: this.last_id,
curr_channel: this.mode,
});
var worlddata = cc.talkmgr.woldmsg;
this.tableview_world.active = true;
this.nd_friend.active = false;
this.tableview_world
.getComponent("tableView")
.initTableView(worlddata.length, {
array: worlddata,
target: this,
width: this.tableview_world.width,
});
this.tableview_world.getComponent("tableView").scrollToOffset(
{
x: 0,
y: worlddata.length * pbheight,
},
0
);
},
callguild() {
this.mode = 3;
this.nd_guildred.active = false;
this.showpick();
this.last_id = cc.talkmgr.getAllLastid();
cc.chatMgr.sendmsg("CMReadMsgAndOpenChatNotify", {
last_ids: this.last_id,
curr_channel: this.mode,
});
var guilddata = cc.talkmgr.guildmsg;
//console.log("guildMsg========",guilddata);
this.tableview_world.active = true;
this.nd_friend.active = false;
this.tableview_world
.getComponent("tableView")
.initTableView(guilddata.length, {
array: guilddata,
target: this,
width: this.tableview_world.width,
isguild: true, //可能cell上要显示职位
});
this.tableview_world.getComponent("tableView").scrollToOffset(
{
x: 0,
y: guilddata.length * pbheight,
},
0
);
},
callteam() {
//console.log("更新小队========");
this.mode = 4;
this.showpick();
this.last_id = cc.talkmgr.getAllLastid();
cc.chatMgr.sendmsg("CMReadMsgAndOpenChatNotify", {
last_ids: this.last_id,
curr_channel: this.mode,
});
var teamdata = cc.talkmgr.teammsg;
this.tableview_world.active = true;
this.nd_friend.active = false;
this.tableview_world
.getComponent("tableView")
.initTableView(teamdata.length, {
array: teamdata,
target: this,
width: this.tableview_world.width,
});
this.tableview_world.getComponent("tableView").scrollToOffset(
{
x: 0,
y: teamdata.length * pbheight,
},
0
);
},
callfriend() {
this.mode = 2;
this.showpick();
this.last_id = cc.talkmgr.getAllLastid();
cc.chatMgr.sendmsg("CMReadMsgAndOpenChatNotify", {
last_ids: this.last_id,
curr_channel: this.mode,
});
this.tableview_world.active = false;
this.nd_friend.active = true;
var friendlist = []; //todo 获取好友列表
for (var m = 0; m < playerData.friend_list.length; m++) {
playerData.friend_list[m].m_defaultSelect = 0;
let baseData = playerData.friend_list[m].base_data;
let accountID = baseData.account_id;
//console.log("FriendData=====",accountID,this.m_btnData);
if (this.m_btnData) {
if (this.m_btnData == accountID) {
playerData.friend_list[m].m_defaultSelect = 1;
}
}
friendlist.push(playerData.friend_list[m]);
}
this.m_btnData = null;
for (var i = friendlist.length - 1; i >= 0; i--) {
if (friendlist[i].base_data["account_id"] == SDKManage.account_id) {
friendlist.splice(i, 1);
break;
}
}
friendlist.sort((a, b) => {
var aonline = parseInt(a.base_data["_online"]);
var bonline = parseInt(b.base_data["_online"]);
if (aonline == bonline) {
return (
a.temp_custom_data["value1"] - b.temp_custom_data["value1"]
);
} else {
return bonline - aonline;
}
});
if (friendlist.length > 0) {
if (!this.sendid) {
this.sendid = friendlist[0].base_data.account_id;
this.sendname = friendlist[0].base_data.nickname;
}
this.showfriend(this.sendid, this.sendname);
this.lb_friendnum.string = cc.language.stringformat(
"haoyoushuliang",
[friendlist.length]
);
} else {
this.lb_frinamechat.string = "";
this.lb_friendnum.string = cc.language.stringformat(
"haoyoushuliang",
["0"]
);
}
this.tableFriendList
.getComponent("tableView")
.initTableView(friendlist.length, {
array: friendlist,
target: this,
});
},
showfriend(account_id, name) {
this.sendid = account_id;
this.sendname = name;
this.lb_frinamechat.string = cc.language.stringformat(
"yusheiliaotian",
[name]
);
var last_id = cc.talkmgr.getLastidbyChannel(2, this.sendid);
cc.chatMgr.sendmsg("CMSetCurrPrivateChatTarget", {
last_id: last_id,
private_target: this.sendid,
});
var data = cc.talkmgr.getfriendmsg(account_id);
for (let i = 0; i < data.length; i++) {
data[i].tmpState = 1;
}
this.tableViewfriend
.getComponent("tableView")
.initTableView(data.length, {
array: data,
target: this,
width: this.tableViewfriend.width,
});
this.tableViewfriend.getComponent("tableView").scrollToOffset(
{
x: 0,
y: data.length * pbheight,
},
0
);
},
callemote() {
this.nd_emot.zIndex = 3;
if (this.nd_emot.active) {
this.nd_emot.active = false;
} else {
this.nd_emot.active = true;
if (!this.isCreate) {
//this.scollViewEmote.destroyAllChildren()
//this.emoteMax = 40
for (var i = 1; i <= this.emoteMax; i++) {
var nd = cc.instantiate(this.pb_chatemote);
nd.zIndex = 10;
this.scollViewEmote.addChild(nd);
nd.getComponent("chatEmote").showChatEmote("e" + i);
}
}
this.isCreate = true;
}
},
doemot(v2) {
var temp = this.editbox;
this.nd_emot.active = false;
var add = "(" + v2 + ")";
var str1 = temp.string;
var str2 = temp.string + add;
temp.string = str2;
if (temp.string != str2) {
temp.string = str1;
}
},
showChatPopPanel(_data, _guildName) {
if (!this.ndcharinfo) {
this.ndcharinfo = cc.instantiate(this.pb_charinfo);
this.node.addChild(this.ndcharinfo);
}
this.ndcharinfo.active = true;
this.ndcharinfo.getComponent("chatcharinfo").initdata(_data);
},
update10105CntCallBack() {
this.update10105Cnt();
},
SMFriendListCallBack() {
if (this.m_btnType == 2) {
this.callfriend();
this.m_btnType = 0;
}
},
getPlayerInfo(_data) {
let guildID = _data.guild_id;
this.m_chatItemData = _data;
if (guildID > 0) {
cc.chatMgr.sendmsg("CMGuildInfo", {
guild_id: guildID,
});
} else {
this.showChatPopPanel(_data, "暂无公会");
}
console.log("查看玩家信息", _data);
},
getGuildInfoCallBack(_data) {
let guildName = "皮卡猪的大森林";
guildName = _data.info.guild_name;
this.showChatPopPanel(this.m_chatItemData, guildName);
},
joinTeam(obj) {
if (obj.errcode != 0) {
playerData.teamuuid = null;
} else {
var node_id = 1;
if (playerData.node_id != 0) {
node_id = playerData.node_id;
}
this.close();
}
},
closePanel() {
this.close();
},
closechat() {
this.node.destroy();
},
close() {
cc.chatMgr.sendmsg("CMCloseChatNotify");
this.node.destroy();
},
addMoveText(sender, msg) {
console.log("测试创建大喇叭", msg);
if (!this.newText) {
this.newText = cc.instantiate(this.movePrefab);
this.moveContent.addChild(this.newText);
}
this.newText.getComponent("moveText_prefab").changeText(sender, msg, 2);
},
update(dt) {
this.moveTextTime += dt;
if (this.moveTextTime > 10) {
this.refreshdalaba();
}
// if (this.friendtime > 0) {
// this.friendtime -= dt
// if (this.friendtime <= 0) {
// this.friendtime = 0
// this.canFriendMsg = true
// }
// }
// if (this.guildtime > 0) {
// this.guildtime -= dt
// if (this.guildtime <= 0) {
// this.guildtime = 0
// this.canGuildMsg = true
// }
// }
// if (this.teamtime > 0) {
// this.teamtime -= dt
// if (this.teamtime <= 0) {
// this.teamtime = 0
// this.canTeamMsg = true
// }
// }
},
});