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

98 lines
2.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.

import AudioUtil from "../ts/core/AudioUtil";
import GameModel from "../ts/core/GameModel";
let GameDefine = require('../game/GameDefine');
cc.Class({
extends: cc.Component,
properties: {
lblTitle:cc.Label,
lblDesc:cc.Label,
scrollViewContent: cc.Node,
relationItem: cc.Prefab,
},
onLoad() {
},
start(){
let operationType = this.node.opType;
GameModel.player.send('c2s_relation_List',{
roleId: GameModel.player.roleid,
relationType: GameDefine.RelationType.Brother,
operationType: operationType
});
},
//初始化關係列表1添加新人2退出
initRelationList(data){
let relationList = data.relationList;
this.relationList = JSON.parse(relationList);
this.scrollViewContent.destroyAllChildren();
this.relationList.forEach((relation,index) => {
let relationItem = cc.instantiate(this.relationItem);
if(relationItem){
let relationItemLogic = relationItem.getComponent('RelationItem');
if(relationItemLogic){
relationItemLogic.initRelationData(relation,data.operationType);
}
relationItem.parent = this.scrollViewContent;
}
});
this.scrollViewContent.height = Math.max(this.scrollViewContent.height, this.relationList.length * 120);
},
leaveRelation(data){
let children = this.scrollViewContent.getChildren();
for(var i = 0;i < children.length;i++){
let playerPanel = children[i];
let membersPanel = playerPanel.getChildByName('MembersPanel');
let lblRelationId = Number(playerPanel.getChildByName('LblRelationId').getComponent(cc.Label).string);
if(lblRelationId == data.relationId){
if(data.leaveRoleId != GameModel.player.roleid){
let playerHead = membersPanel.getChildren().find(e=>{
let lblRoleId = Number(e.getChildByName('LblRoleId').getComponent(cc.Label).string);
return lblRoleId == data.leaveRoleId;
});
if(playerHead){
playerHead.destroy();
break;
}
}else{
playerPanel.destroy();
}
}
}
},
deleteRelationItem(data){
let children = this.scrollViewContent.getChildren();
for(var i = 0;i < children.length;i++){
let playerPanel = children[i];
let lblRelationId = Number(playerPanel.getChildByName('LblRelationId').getComponent(cc.Label).string);
if(lblRelationId == data.relationId){
playerPanel.destroy();
}
}
},
onCloseBtnClicked(e, d) {
AudioUtil.playCloseAudio();
this.node.destroy();
},
});