pubgv3/assets/scripts/UI/UIFriend/UIFriendNew.js
guoqing.zhu aedc9be7db update
2022-05-23 16:42:15 +08:00

277 lines
8.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var SDKManage = require("SDKManage");
var playerData = require("playerData");
const NetManage = require("../../manages/NetManage");
cc.Class({
extends: cc.Component,
properties: {
nd_friend: {
default: null,
type: cc.Node,
},
nd_apply: {
default: null,
type: cc.Node,
},
nd_blacklist: {
default: null,
type: cc.Node,
},
edit_find: {
default: null,
type: cc.EditBox,
},
pb_oneFriend: {
default: null,
type: cc.Prefab,
},
// contents
content_friend: {
default: null,
type: cc.Node,
},
friendScrollview: {
default: null,
type: cc.ScrollView,
},
},
// 游客不显示好友
onLoad() {
// get friendlist
cc.chatMgr.sendmsg("CMFriendList");
cc.Notifier.on("friendlist", this, this.getFriendList.bind(this));
cc.Notifier.on("SMFriendApplyList", this, this.getApplyList.bind(this));
cc.Notifier.on("dirtywordcheck", this, this.dirtywordcheck.bind(this));
// agree refuse
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));
//black
cc.Notifier.on("blacklist", this, this.SMFriendBlackList.bind(this));
cc.Notifier.on(
"SMFriendDeleteBlack",
this,
this.SMFriendDeleteBlack.bind(this)
);
this.setToFriend();
},
onDestroy() {
cc.Notifier.off("friendlist", this, this.getFriendList.bind(this));
cc.Notifier.off(
"SMFriendApplyList",
this,
this.getApplyList.bind(this)
);
cc.Notifier.off("dirtywordcheck", this, this.dirtywordcheck.bind(this));
cc.Notifier.off("SMFriendAgree", this, this.SMFriendAgree.bind(this));
cc.Notifier.off("SMFriendRefuse", this, this.SMFriendRefuse.bind(this));
cc.Notifier.off("SMFriendDelete", this, this.SMFriendDelete.bind(this));
cc.Notifier.off("blacklist", this, this.SMFriendBlackList.bind(this));
cc.Notifier.off(
"SMFriendDeleteBlack",
this,
this.SMFriendDeleteBlack.bind(this)
);
},
setToNone() {
if (this.edit_find) this.edit_find.string = "";
if (this.nd_friend) this.nd_friend.active = false;
this.nd_apply.active = false;
this.nd_blacklist.active = false;
this.content_friend.destroyAllChildren();
this.friendScrollview.stopAutoScroll();
this.friendScrollview.scrollToTop();
},
initOne(type, data, tmpData = {}) {
const node = cc.instantiate(this.pb_oneFriend);
switch (type) {
case 0:
// 好友列表
node.getComponent("SingleFriendList").setToFriendList();
break;
case 1:
// 申请列表
node.getComponent("SingleFriendList").setToApplyList();
break;
case 2:
// 黑名单
node.getComponent("SingleFriendList").setToBlackList();
break;
case 3:
// 添加好友
node.getComponent("SingleFriendList").setToAddFriend();
break;
}
node.getComponent("SingleFriendList").init(data);
if (tmpData) node.getComponent("SingleFriendList").saveData(tmpData);
this.content_friend.addChild(node);
},
setToFriend() {
this.setToNone();
cc.chatMgr.sendmsg("CMFriendList");
},
setToApply() {
this.setToNone();
cc.chatMgr.sendmsg("CMFriendApplyList");
},
setToBlackList() {
this.setToNone();
cc.chatMgr.sendmsg("CMFriendBlackList");
},
onClose() {
this.node.destroy();
},
onSearch() {
if (this.edit_find.string != "" && this.edit_find.string) {
NetManage.dirtyWordCheck(this.edit_find.string);
} else {
cc.uiHelper.showTips("User not found!");
}
},
// 钱包用户需要添加 6516_2006_的前缀并且需要lowcast toLowerCase()
// 游客不需要
dirtywordcheck(obj) {
if (obj.errcode == 0) {
if (this.edit_find.string != "" && this.edit_find.string) {
var tmp = "";
if (this.edit_find.string.startsWith("0x")) {
// 钱包地址
console.log("search by wallet");
tmp = `6516_2006_${this.edit_find.string.toLowerCase()}`;
NetManage.searchUserByAccountid(tmp, (res) => {
if (res.info.account_id != SDKManage.account_id) {
this.setToNone();
this.initOne(3, res.info);
}
});
} else if (
this.edit_find.string.startsWith("6513_2006_") ||
this.edit_find.string.startsWith("6516_2006_")
) {
// 账户id
console.log("search by account");
tmp = this.edit_find.string;
NetManage.searchUserByAccountid(tmp, (res) => {
if (res.info.account_id != SDKManage.account_id) {
this.setToNone();
this.initOne(3, res.info);
}
});
} else {
// nicknames
console.log("search by name");
tmp = this.edit_find.string;
NetManage.searchUserByName(tmp, (res) => {
console.log(JSON.stringify(res));
if (res.info.account_id != SDKManage.account_id) {
this.setToNone();
this.initOne(3, res.info);
}
});
}
}
} else {
cc.uiHelper.showTips("User not found!");
this.edit_find.string = "";
}
},
onClickToggle(event, data) {
switch (data) {
case "0":
this.setToFriend();
break;
case "1":
this.setToApply();
break;
case "2":
this.setToBlackList();
break;
}
},
getFriendList(msg) {
this.setToNone();
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;
}
}
for (let i = 0; i < this.friend_list.length; i += 1) {
this.initOne(0, this.friend_list[i].base_data, this.friend_list[i]);
}
},
getApplyList(msg) {
this.setToNone();
var apply_list = msg.apply_list;
for (let i = 0; i < apply_list.length; i += 1) {
this.initOne(1, apply_list[i].base_data, apply_list[i]);
}
},
SMFriendAgree(msg) {
if (msg.errcode == null || msg.errcode == 0) {
cc.uiHelper.showTips(cc.language.stringformat("addsuccess"));
cc.chatMgr.sendmsg("CMFriendApplyList");
} else {
cc.uiHelper.showTips(msg.errmsg);
}
},
SMFriendRefuse(msg) {
cc.chatMgr.sendmsg("CMFriendApplyList");
},
SMFriendDelete(msg) {
if (msg.errcode == null || msg.errcode == 0) {
cc.uiHelper.showTips(cc.language.stringformat("deletesuccess"));
}
cc.chatMgr.sendmsg("CMFriendList");
},
SMFriendBlackList() {
if (!playerData.black_list) {
return;
}
for (let i = 0; i < playerData.black_list.length; i += 1) {
this.initOne(
2,
playerData.black_list[i].base_data,
playerData.black_list[i]
);
}
},
SMFriendDeleteBlack(msg) {
if (msg.errcode == null || msg.errcode == 0) {
cc.uiHelper.showTips(cc.language.stringformat("deletesuccess"));
}
cc.chatMgr.sendmsg("CMFriendBlackList");
},
});