606 lines
14 KiB
JavaScript
606 lines
14 KiB
JavaScript
var gameConfig = require('gameConfig');
|
|
var playerData = require('playerData');
|
|
var SDKManage = require('SDKManage');
|
|
var NetManage = require('NetManage');
|
|
var Main = require('Main');
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
nd_friendlist: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
tableview_friend: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
tableview_recommend: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
nd_friendbg: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
nd_friendpick: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
mask: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
nd_applylist: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
tableview_apply: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
nd_applybg: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
nd_applypick: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
editbox: {
|
|
default: null,
|
|
type: cc.EditBox,
|
|
},
|
|
|
|
nd_delfriend: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
lb_delname: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
|
|
pb_friendinfo: {
|
|
default: null,
|
|
type: cc.Prefab,
|
|
},
|
|
|
|
lb_friendnum: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
|
|
lb_blacknum: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
|
|
nd_blacklist: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
tableview_black: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
nd_blackbg: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
nd_blackpick: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
|
|
pb_addblacktip: {
|
|
default: null,
|
|
type: cc.Prefab,
|
|
},
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
onLoad() {
|
|
cc.Notifier.on('selectuser', this, this.selectuser.bind(this));
|
|
cc.Notifier.on('friendlist', this, this.SMFriendList.bind(this));
|
|
cc.Notifier.on('SMFriendApply', this, this.SMFriendApply.bind(this));
|
|
cc.Notifier.on(
|
|
'SMFriendApplyList',
|
|
this,
|
|
this.SMFriendApplyList.bind(this)
|
|
);
|
|
cc.Notifier.on('delfriend', this, this.delfriend.bind(this));
|
|
cc.Notifier.on('SMFriendAgree', this, this.SMFriendAgree.bind(this));
|
|
cc.Notifier.on('SMFriendRefuse', this, this.SMFriendRefuse.bind(this));
|
|
cc.Notifier.on('SMFriendDelete', this, this.SMFriendDelete.bind(this));
|
|
cc.Notifier.on(
|
|
'SMDeleteFriendNotify',
|
|
this,
|
|
this.SMDeleteFriendNotify.bind(this)
|
|
);
|
|
cc.Notifier.on(
|
|
'SMUserInfoUpdate',
|
|
this,
|
|
this.SMUserInfoUpdate.bind(this)
|
|
);
|
|
cc.Notifier.on('showplayerinfo', this, this.showplayerinfo.bind(this));
|
|
cc.Notifier.on('blacklist', this, this.SMFriendBlackList.bind(this));
|
|
cc.Notifier.on(
|
|
'SMFriendDeleteBlack',
|
|
this,
|
|
this.SMFriendDeleteBlack.bind(this)
|
|
);
|
|
cc.Notifier.on(
|
|
'SMFriendAddBlack',
|
|
this,
|
|
this.SMFriendAddBlack.bind(this)
|
|
);
|
|
cc.Notifier.on(
|
|
'onbtnAddblacktip',
|
|
this,
|
|
this.onbtnAddblacktip.bind(this)
|
|
);
|
|
cc.Notifier.on(
|
|
'SMRecommandFriend',
|
|
this,
|
|
this.SMRecommandFriend.bind(this)
|
|
);
|
|
cc.Notifier.on(
|
|
'selectUserByName',
|
|
this,
|
|
this.selectUserByName.bind(this)
|
|
);
|
|
this.editbox.node.on('editing-did-began', this.callbackbegin, this);
|
|
this.editbox.node.on('editing-did-ended', this.callbackend, this);
|
|
cc.Notifier.on('dirtywordcheck', this, this.dirtywordcheck.bind(this));
|
|
this.lb_friendnum.string =
|
|
cc.language.stringformat('friendnum') + '0 / 30';
|
|
this.lb_blacknum.string =
|
|
cc.language.stringformat('blacknum') + '0 / 10';
|
|
|
|
this.friend_list = [];
|
|
this.num = 0;
|
|
this.time = 0;
|
|
this.close_status = true;
|
|
this.user_name = cc.language.stringformat('nickname');
|
|
},
|
|
onDestroy() {
|
|
cc.Notifier.off('selectuser', this);
|
|
cc.Notifier.off('friendlist', this);
|
|
cc.Notifier.off('SMFriendApply', this);
|
|
cc.Notifier.off('SMFriendApplyList', this);
|
|
cc.Notifier.off('delfriend', this);
|
|
cc.Notifier.off('SMFriendAgree', this);
|
|
cc.Notifier.off('SMFriendRefuse', this);
|
|
cc.Notifier.off('SMFriendDelete', this);
|
|
cc.Notifier.off('SMUserInfoUpdate', this);
|
|
cc.Notifier.off('showplayerinfo', this);
|
|
cc.Notifier.off('blacklist', this);
|
|
cc.Notifier.off('SMFriendDeleteBlack', this);
|
|
cc.Notifier.off('SMFriendAddBlack', this);
|
|
cc.Notifier.off('onbtnAddblacktip', this);
|
|
cc.Notifier.off('SMRecommandFriend', this);
|
|
cc.Notifier.off('SMDeleteFriendNotify', this);
|
|
cc.Notifier.off('selectUserByName', this);
|
|
cc.Notifier.off('dirtywordcheck', this);
|
|
},
|
|
|
|
start() {
|
|
// if (playerData.friend_red != 1) {
|
|
// this.onBtnFriend();
|
|
// } else {
|
|
// this.onBtnApply();
|
|
// }
|
|
// var date = new Date();
|
|
|
|
cc.chatMgr.sendmsg('CMRecommandFriend');
|
|
},
|
|
|
|
SMRecommandFriend(msg) {
|
|
var recommend_list = msg.friend_list;
|
|
if (recommend_list.length > 3) {
|
|
recommend_list.length = 3;
|
|
}
|
|
|
|
this.tableview_recommend
|
|
.getComponent('tableView')
|
|
.initTableView(recommend_list.length, {
|
|
array: recommend_list,
|
|
target: this,
|
|
});
|
|
},
|
|
|
|
onBtnRecommend() {
|
|
|
|
cc.Notifier.emit('changerecommend');
|
|
cc.chatMgr.sendmsg('CMRecommandFriend');
|
|
},
|
|
|
|
onBtnFriend() {
|
|
this.nd_friendbg.active = false;
|
|
this.nd_friendpick.active = true;
|
|
this.nd_applybg.active = true;
|
|
this.nd_applypick.active = false;
|
|
this.nd_friendlist.active = true;
|
|
this.nd_applylist.active = false;
|
|
this.nd_blacklist.active = false;
|
|
this.nd_blackbg.active = true;
|
|
this.nd_blackpick.active = false;
|
|
|
|
this.nd_delfriend.active = false;
|
|
|
|
cc.chatMgr.sendmsg('CMFriendList');
|
|
},
|
|
|
|
onBtnApply() {
|
|
this.nd_friendbg.active = true;
|
|
this.nd_friendpick.active = false;
|
|
this.nd_applybg.active = false;
|
|
this.nd_applypick.active = true;
|
|
this.nd_friendlist.active = false;
|
|
this.nd_applylist.active = true;
|
|
this.nd_blacklist.active = false;
|
|
this.nd_blackbg.active = true;
|
|
this.nd_blackpick.active = false;
|
|
|
|
this.nd_delfriend.active = false;
|
|
|
|
cc.chatMgr.sendmsg('CMFriendApplyList');
|
|
},
|
|
|
|
onBtnBlack() {
|
|
this.nd_friendbg.active = true;
|
|
this.nd_friendpick.active = false;
|
|
this.nd_applybg.active = true;
|
|
this.nd_applypick.active = false;
|
|
this.nd_friendlist.active = false;
|
|
this.nd_applylist.active = false;
|
|
this.nd_blacklist.active = true;
|
|
this.nd_blackbg.active = false;
|
|
this.nd_blackpick.active = true;
|
|
|
|
this.nd_delfriend.active = false;
|
|
|
|
cc.chatMgr.sendmsg('CMFriendBlackList');
|
|
},
|
|
|
|
SMFriendBlackList() {
|
|
if (!playerData.black_list) {
|
|
return;
|
|
}
|
|
this.blacknum = playerData.black_list.length;
|
|
if (this.blacknum <= 10) {
|
|
this.lb_blacknum.string =
|
|
cc.language.stringformat('blacknum') + this.blacknum + ' / 10';
|
|
} else {
|
|
this.lb_blacknum.string =
|
|
cc.language.stringformat('blacknum') + '10 / 10';
|
|
}
|
|
this.tableview_black
|
|
.getComponent('tableView')
|
|
.initTableView(playerData.black_list.length, {
|
|
array: playerData.black_list,
|
|
target: this,
|
|
});
|
|
},
|
|
|
|
SMFriendList(msg) {
|
|
this.friend_list = [];
|
|
for (var m = 0; m < msg.friend_list.length; m++) {
|
|
this.friend_list.push(msg.friend_list[m]);
|
|
}
|
|
for (var i = this.friend_list.length - 1; i >= 0; i--) {
|
|
if (
|
|
this.friend_list[i].base_data['account_id'] ==
|
|
SDKManage.account_id
|
|
) {
|
|
this.friend_list.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
this.friend_list.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;
|
|
}
|
|
});
|
|
|
|
this.num = this.friend_list.length;
|
|
if (this.num <= 30) {
|
|
this.lb_friendnum.string =
|
|
cc.language.stringformat('friendnum') + this.num + ' / 30';
|
|
} else {
|
|
this.lb_friendnum.string =
|
|
cc.language.stringformat('friendnum') + '30 / 30';
|
|
}
|
|
this.tableview_friend
|
|
.getComponent('tableView')
|
|
.initTableView(this.friend_list.length, {
|
|
array: this.friend_list,
|
|
target: this,
|
|
});
|
|
},
|
|
|
|
SMFriendApplyList(msg) {
|
|
var apply_list = msg.apply_list;
|
|
this.tableview_apply
|
|
.getComponent('tableView')
|
|
.initTableView(apply_list.length, {
|
|
array: apply_list,
|
|
target: this,
|
|
});
|
|
},
|
|
|
|
getChannelID() {
|
|
var ChannelId = 6000;
|
|
if (cc.sys.platform == cc.sys.WECHAT_GAME) {
|
|
ChannelId = 6001;
|
|
} else if (cc.sys.platform == cc.sys.QQ_PLAY) {
|
|
ChannelId = 6002;
|
|
} else if (window.qg == cc.sys.QQ_PLAY) {
|
|
ChannelId = 6003;
|
|
} else {
|
|
ChannelId = 6000;
|
|
}
|
|
return ChannelId;
|
|
},
|
|
|
|
SMFriendApply(msg) {
|
|
if (msg.errcode == 1) {
|
|
cc.uiHelper.showTips(msg.errmsg);
|
|
} else if (msg.errcode == 21) {
|
|
cc.uiHelper.showTips(msg.errmsg);
|
|
this.editbox.string = '';
|
|
} else {
|
|
cc.uiHelper.showTips(cc.language.stringformat('hasinvite'));
|
|
this.editbox.string = '';
|
|
}
|
|
},
|
|
|
|
|
|
|
|
onBtnSelectFriend() {
|
|
if (
|
|
this.editbox.string == '' ||
|
|
this.editbox.string.indexOf(' ') != -1
|
|
) {
|
|
cc.uiHelper.showTips(cc.language.stringformat('strnotkong'));
|
|
} else if (
|
|
this.editbox.string == cc.language.stringformat('nickname')
|
|
) {
|
|
cc.uiHelper.showTips(cc.language.stringformat('weijinzi'));
|
|
this.editbox.string = '';
|
|
} else if (this.editbox.string.indexOf(' ') != -1) {
|
|
cc.uiHelper.showTips(cc.language.stringformat('weijinzi'));
|
|
this.editbox.string = '';
|
|
} else {
|
|
NetManage.dirtyWordCheck(this.editbox.string);
|
|
}
|
|
},
|
|
|
|
dirtywordcheck(obj) {
|
|
if (obj.errcode == 0) {
|
|
if (this.num >= 30) {
|
|
cc.uiHelper.showTips(cc.language.stringformat('friendnummax'));
|
|
this.editbox.string = '';
|
|
return;
|
|
}
|
|
if (this.editbox.string != '' && this.editbox.string) {
|
|
NetManage.selectUserByName(this.editbox.string);
|
|
}
|
|
} else {
|
|
cc.uiHelper.showTips(cc.language.stringformat('weijinzi'));
|
|
this.editbox.string = '';
|
|
}
|
|
},
|
|
|
|
selectUserByName(obj) {
|
|
if (obj.errcode == 0) {
|
|
|
|
this.editbox.string = '';
|
|
cc.chatMgr.sendmsg('CMFriendApply', {
|
|
friend_id: obj.fri_accountid,
|
|
msg: '',
|
|
});
|
|
} else {
|
|
cc.uiHelper.showTips(cc.language.stringformat('notplayer'));
|
|
this.editbox.string = '';
|
|
}
|
|
},
|
|
|
|
selectuser(obj) {
|
|
if (obj.errcode == 0) {
|
|
this.user_name = obj.name;
|
|
cc.chatMgr.sendmsg('CMFriendApply', {
|
|
friend_id: this.accountid,
|
|
msg: '',
|
|
});
|
|
} else {
|
|
cc.uiHelper.showTips(cc.language.stringformat('notplayer'));
|
|
this.editbox.string = '';
|
|
}
|
|
},
|
|
|
|
SMFriendAgree(msg) {
|
|
if (msg.errcode == null || msg.errcode == 0) {
|
|
cc.uiHelper.showTips(cc.language.stringformat('addsuccess'));
|
|
var num = this.num + 1;
|
|
if (num <= 30) {
|
|
this.lb_friendnum.string =
|
|
cc.language.stringformat('friendnum') + num + ' / 30';
|
|
} else {
|
|
this.lb_friendnum.string =
|
|
cc.language.stringformat('friendnum') + '30 / 30';
|
|
}
|
|
cc.chatMgr.sendmsg('CMFriendApplyList');
|
|
} else {
|
|
cc.uiHelper.showTips(msg.errmsg);
|
|
}
|
|
},
|
|
|
|
SMFriendRefuse(msg) {
|
|
cc.chatMgr.sendmsg('CMFriendApplyList');
|
|
},
|
|
|
|
delfriend(name) {
|
|
this.nd_delfriend.active = true;
|
|
this.lb_delname.string = name;
|
|
},
|
|
|
|
onBtnTrueDel() {
|
|
cc.chatMgr.sendmsg('CMFriendDelete', {
|
|
friend_id: this.accountid,
|
|
});
|
|
},
|
|
|
|
onBtnCancelDel() {
|
|
this.nd_delfriend.active = false;
|
|
},
|
|
|
|
SMFriendDelete(msg) {
|
|
if (msg.errcode == null || msg.errcode == 0) {
|
|
cc.uiHelper.showTips(cc.language.stringformat('deletesuccess'));
|
|
}
|
|
this.nd_delfriend.active = false;
|
|
cc.chatMgr.sendmsg('CMFriendList');
|
|
},
|
|
|
|
SMFriendDeleteBlack(msg) {
|
|
if (msg.errcode == null || msg.errcode == 0) {
|
|
cc.uiHelper.showTips(cc.language.stringformat('deletesuccess'));
|
|
}
|
|
cc.chatMgr.sendmsg('CMFriendBlackList');
|
|
},
|
|
|
|
SMFriendAddBlack(msg) {
|
|
|
|
cc.Notifier.emit('closefriendinfo');
|
|
cc.chatMgr.sendmsg('CMFriendList');
|
|
cc.chatMgr.sendmsg('CMFriendBlackList');
|
|
},
|
|
|
|
SMDeleteFriendNotify(msg) {
|
|
if (this.friend_list == null) {
|
|
return;
|
|
}
|
|
for (var i = this.friend_list.length - 1; i >= 0; i--) {
|
|
if (
|
|
this.friend_list[i].base_data['account_id'] ==
|
|
msg.user_list[0] ||
|
|
this.friend_list[i].base_data['account_id'] ==
|
|
SDKManage.account_id
|
|
) {
|
|
this.friend_list.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
this.num = this.friend_list.length;
|
|
if (this.num <= 30) {
|
|
this.lb_friendnum.string =
|
|
cc.language.stringformat('friendnum') + this.num + ' / 30';
|
|
} else {
|
|
this.lb_friendnum.string =
|
|
cc.language.stringformat('friendnum') + '30 / 30';
|
|
}
|
|
this.tableview_friend
|
|
.getComponent('tableView')
|
|
.initTableView(this.friend_list.length, {
|
|
array: this.friend_list,
|
|
target: this,
|
|
});
|
|
},
|
|
|
|
SMUserInfoUpdate(msg) {
|
|
if (msg.user_infos[0].base_data['account_id'] == SDKManage.account_id) {
|
|
return;
|
|
}
|
|
var flag = 0;
|
|
for (var i = 0; i < this.friend_list.length; i++) {
|
|
if (
|
|
this.friend_list[i].base_data['account_id'] ==
|
|
msg.user_infos[0].base_data['account_id']
|
|
) {
|
|
flag = 1;
|
|
this.friend_list[i].base_data = msg.user_infos[0].base_data;
|
|
}
|
|
}
|
|
if (flag == 0) {
|
|
var num = this.num + 1;
|
|
if (num <= 30) {
|
|
this.lb_friendnum.string =
|
|
cc.language.stringformat('friendnum') + num + ' / 30';
|
|
} else {
|
|
this.lb_friendnum.string =
|
|
cc.language.stringformat('friendnum') + '30 / 30';
|
|
}
|
|
this.friend_list.push(msg.user_infos[0]);
|
|
}
|
|
this.tableview_friend
|
|
.getComponent('tableView')
|
|
.initTableView(this.friend_list.length, {
|
|
array: this.friend_list,
|
|
target: this,
|
|
});
|
|
},
|
|
|
|
close() {
|
|
if (!this.close_status) {
|
|
return;
|
|
}
|
|
cc.director.emit('checkred');
|
|
this.node.destroy();
|
|
},
|
|
|
|
showplayerinfo(obj) {
|
|
// var nd = cc.instantiate(this.pb_friendinfo)
|
|
// nd.zIndex = 2
|
|
// this.node.addChild(nd)
|
|
// nd.getComponent("UIFriendInfo").showAddBtn(obj)
|
|
},
|
|
|
|
callbackbegin(editbox) {
|
|
|
|
this.close_status = false;
|
|
},
|
|
|
|
callbackend(editbox) {
|
|
this.close_status = true;
|
|
},
|
|
|
|
onBtnInviteFriend() {
|
|
SDKManage.Share('addfriend', 'wxAddFriend=1');
|
|
},
|
|
|
|
onbtnAddblacktip(obj) {
|
|
var nd = cc.instantiate(this.pb_addblacktip);
|
|
nd.zIndex = 2;
|
|
this.node.addChild(nd);
|
|
nd.getComponent('addblacktip').showblacktip(obj);
|
|
},
|
|
|
|
onClose() {
|
|
this.node.destroy();
|
|
},
|
|
});
|