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

90 lines
2.1 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";
import MsgAlert from "../ts/game/msg/MsgAlert";
let GameDefine = require('../game/GameDefine');
cc.Class({
extends: cc.Component,
properties: {
nameEdit: cc.EditBox,
btnConfirm: cc.Button,
btnCancel: cc.Button,
btnClose: cc.Button
},
onLoad() {
},
GetNameLength(strName) {
let nCnt = 0;
let nLen = strName.length;
for (let i = 0; i < nLen; i++) {
if (/[a-zA-Z0-9]/.test(strName[i]))
nCnt += 1;
else
nCnt += 2;
}
return nCnt;
},
createBtnClicked(e, d) {
if (this.nameEdit.string == '' || this.nameEdit.string.length > 6){//this.GetNameLength(this.nameEdit.string) > 12) {
MsgAlert.addMsg('名稱不能為空並且最多6個字');
return;
}
/*
if (GameModel.player.teamInfo == null || GameModel.player.teamInfo.objlist == null) {
return;
}
let objs = [];
//獲取結拜同伴roldID
for(const teamObj in GameModel.player.teamInfo.objlist){
if(teamObj.livingtype == 1 && teamObj.roleid != GameModel.player.roleid){
objs.push(teamObj.roleid);
}
}*/
if (!GameModel.player.teamInfo.objlist || !Array.isArray(GameModel.player.teamInfo.objlist)) {
MsgAlert.addMsg('先組隊才能結拜');
return false;
}
//獲取隊伍成員列表
let members = [];
for (let index = 0; index < GameModel.player.teamInfo.objlist.length; index++) {
let obj = GameModel.player.teamInfo.objlist[index];
if(obj && obj.livingtype == 1){
members.push(obj.roleid);
}
}
GameModel.send('c2s_relation_new', {
roleId: GameModel.player.roleid,
relationType: GameDefine.RelationType.Brother,
relationName: this.nameEdit.string,
members: members
});
this.btnConfirm.interactable = false;
this.btnConfirm.node.runAction(cc.sequence(cc.delayTime(1),cc.callFunc(() =>{
this.btnConfirm.interactable = true;
})));
},
onCloseBtnClicked(e, d) {
AudioUtil.playCloseAudio();
this.node.destroy();
},
});