SamsaraGame/assets/Script/panel/FriendDetail.js
2025-04-24 17:03:28 +08:00

90 lines
2.3 KiB
JavaScript

import GameModel from "../ts/core/GameModel";
import GameUtil from "../ts/core/GameUtil";
import MsgAlert from "../ts/game/msg/MsgAlert"
cc.Class({
extends: cc.Component,
properties: {
nameLab: cc.Label,
levelLab: cc.Label,
headIcon: cc.Sprite,
roleidLab: cc.Label,
bgNode: cc.Node,
inviteNode: cc.Node
},
onLoad() {
this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this));
if (GameModel.player.mapid == 4004 || GameModel.player.mapid == 3001) {
this.inviteNode.active = false
this.bgNode.height = 160
}
let label = this.inviteNode.getChildByName("New Label")
if(GameModel.player.teamid > 0){
//invite node 變為邀請
label.getComponent(cc.Label).string = "邀請入隊"
}else{
//invite node 變為加入
label.getComponent(cc.Label).string = "申請入隊"
}
},
touchBegan(event) {
if (this.bgNode.getBoundingBoxToWorld().contains(event.getLocation())) {
return;
}
this.node.runAction(cc.sequence(cc.fadeOut(0.1), cc.removeSelf()));
},
loadInfo(info, node) {
console.log("loadInfo", info)
this.friendInfo = info;
this.nameLab.string = info.name;
if (info.level == -1) {
this.nameLab.node.color = cc.color(255, 0, 0);
this.levelLab.node.parent.active = false;
} else {
this.levelLab.node.parent.active = true;
this.nameLab.node.color = GameUtil.getReliveColor(info.relive);
this.levelLab.string = info.level;
}
this.roleidLab.string = info.roleid;
this.itemNode = node;
this.headIcon.spriteFrame = GameModel.getRoleHead(info.resid);
},
chatBtnClicked(e, d) {
let panelLogic = this.node.parent.parent.getComponent('FriendPanel');
panelLogic.selectedFriend(this.itemNode, this.friendInfo.roleid);
this.node.destroy();
},
delBtnClicked(e, d) {
GameModel.send('c2s_update_friends', {
roleid: this.friendInfo.roleid,
operation: 0
});
this.node.destroy();
},
inviteTeam() {
if (this.friendInfo.online == 0) {
MsgAlert.addMsg("對方不在線");
return
}
if(GameModel.player.teamid > 0){
MsgAlert.addMsg("已發送邀請");
GameModel.send('c2s_team_invite', {
toroleid: this.friendInfo.roleid,
});
}else{
MsgAlert.addMsg("已發送申請");
GameModel.send('c2s_requst_team', {
roleid: GameModel.player.roleid,
teamid: this.friendInfo.teamid
});
}
}
});