pubgv3/assets/scripts/UI/UIFriend/SingleFriendList.js
guoqing.zhu 7d1b9146dd update
2022-05-30 19:46:41 +08:00

170 lines
2.7 KiB
JavaScript

var Utils = require('Utils');
var playerData = require('playerData');
cc.Class({
extends: cc.Component,
properties: {
addToBlack: {
default: null,
type: cc.Node,
},
delete: {
default: null,
type: cc.Node,
},
agree: {
default: null,
type: cc.Node,
},
refuse: {
default: null,
type: cc.Node,
},
addToFriend: {
default: null,
type: cc.Node,
},
addNewFriend: {
default: null,
type: cc.Node,
},
playerHead: {
default: null,
type: cc.Node,
},
playerName: {
default: null,
type: cc.Node,
},
inviteBtn: {
default: null,
type: cc.Node,
},
},
init(data) {
//
this.canInvite = true;
//
this.playerAccount = data.account_id;
if (data.name) {
this.playerName.getComponent(cc.Label).string = data.name;
} else if (data.nickname) {
this.playerName.getComponent(cc.Label).string = data.nickname;
}
if (data.head_id) {
Utils.setitem(
this,
data.head_id,
this.playerHead.getComponent(cc.Sprite)
);
} else if (data.avatar_url) {
Utils.setitem(
this,
data.avatar_url,
this.playerHead.getComponent(cc.Sprite)
);
}
},
saveData(data) {
this.tmpData = JSON.stringify(data);
},
setToFriendList() {
this.addToBlack.active = true;
this.delete.active = true;
},
setToApplyList() {
this.agree.active = true;
this.refuse.active = true;
},
setToBlackList() {
this.addToFriend.active = true;
},
setToAddFriend() {
this.addNewFriend.active = true;
},
setToInvite() {
this.inviteBtn.active = true;
},
// friendlist
onAddToBlacklist() {
cc.chatMgr.sendmsg('CMFriendAddBlack', {
user_info: JSON.parse(this.tmpData), //MFUserInfo
});
},
onDelete() {
cc.chatMgr.sendmsg('CMFriendDelete', {
friend_id: this.playerAccount,
});
},
// applylist
onAgree() {
cc.chatMgr.sendmsg('CMFriendAgree', {
apply: JSON.parse(this.tmpData),
});
},
onRefuse() {
cc.chatMgr.sendmsg('CMFriendRefuse', {
apply: JSON.parse(this.tmpData),
});
},
// blacklist
onAddToFriend() {
cc.chatMgr.sendmsg('CMFriendDeleteBlack', {
account_id: this.playerAccount,
});
},
onAddNewFriend() {
cc.chatMgr.sendmsg('CMFriendApply', {
friend_id: this.playerAccount,
msg: '',
});
},
onInviteFriend() {
if (this.canInvite) {
this.canInvite = false;
cc.Notifier.emit("inviteplayer")
var data = {
msg: 'InvitePlay',
player: playerData.name,
data: JSON.parse(this.tmpData),
};
cc.chatMgr.sendmsg('CMSendCustomMsg', {
target_list: this.playerAccount,
msg: JSON.stringify(data),
param1: 0,
param2: 0,
param3: 0,
});
} else {
cc.uiHelper.showTips('Already invited, try again later');
setTimeout(() => {
this.canInvite = true;
}, 15000);
}
},
});