import GameModel from "../ts/core/GameModel"; import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil"; import WingUtil from "../ts/wing/WingUtil"; import MsgAlert from "../ts/game/msg/MsgAlert"; import AudioUtil from "../ts/core/AudioUtil"; import GameUtil from "../ts/core/GameUtil"; import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil"; import VIPUtil from "../ts/game/role/VIPUtil"; let CPubFunction = require('./PubFunction'); let CMainPlayerInfo = require('./MainPlayerInfo'); cc.Class({ extends: cc.Component, properties: { typeList: cc.Node, typeContent: cc.Node, typeItem: cc.Node, titleLab: cc.Label, goTeamBtnAdd: cc.Prefab, PartnerUI: cc.Prefab, svPartnerList: cc.Prefab, btnPartner: cc.Prefab, goPartnerCard_1: cc.Prefab, goPartnerCard_2: cc.Prefab, }, onLoad() { this.typeList.on(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this)); this.initTypeList(); }, start() { cc.find('tabTeam/btnClose', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "Close", 0)); // let btnTeam = cc.find('btnTeam', this.node); // btnTeam.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "OnTeam", 0)); // cc.find('btnFixedTeam', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "OnFixedTeam", 0)); cc.find('tabTeam/btnMyPartner', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "OpenPartnerUI", 0)); cc.find('tabTeam/btnCreateTeam', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "CreateTeam", 0)); cc.find('tabTeam/btnLeaveTeam', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "LeaveTeam", 0)); cc.find('tabTeam/btnMatch', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "ShowTeamList", 0)); cc.find('tabTeam/btnList', this.node).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "ShowRequestList", 0)); // this.vecTagTeamBtn = [cc.find('btnTeam', this.node), cc.find('btnFixedTeam', this.node)]; // this.vecTabNode = [cc.find('tabTeam', this.node), cc.find('tabFixedTeam', this.node)]; this.nCurSelect = 0; this.vecPartnerCard = []; GameModel.send('c2s_ask_partner_list', { nRoleID: GameModel.player.roleid }); }, CreateCardList() { SKUIUtil.destroyList(this.vecPartnerCard); let goContent = cc.find('tabTeam/nodCardPanel', this.node); cc.find('tabTeam/btnMatch', this.node).active = false; cc.find('tabTeam/btnCreateTeam', this.node).active = false; cc.find('tabTeam/btnLeaveTeam', this.node).active = false; cc.find('tabTeam/btnList', this.node).active = false; let stStart = { nX: 90, nY: -170 }; if (GameModel.player.teamid == 0) { cc.find('tabTeam/btnMatch', this.node).active = true; cc.find('tabTeam/btnCreateTeam', this.node).active = true; //----------- 主角 ------------- let goCard = this.CreateCard(GameModel.player); cc.find('picPtFlag', goCard).active = false; this.vecPartnerCard.push(goCard); //------------ 夥伴 ------------ let index=0; for (let item of CMainPlayerInfo.vecChuZhan) { if (item <= 0){ continue; } let stInfo = CMainPlayerInfo.GetPartner(item); let goCard = this.CreateCard(stInfo); goCard.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "OnClickCard", { nPos:index})); this.vecPartnerCard.push(goCard); index++; } //------------ 加號 ------------ if (this.vecPartnerCard.length < 5) { let goBtnAdd = CPubFunction.CreateSubNode(goContent, { nX: stStart.nX + this.vecPartnerCard.length * 150, nY: -170 }, this.goTeamBtnAdd, 'goTeamBtnAdd'); goBtnAdd.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "OnClickCard", { nPos: CMainPlayerInfo.GetFreeChuZhanPos() })); this.vecPartnerCard.push(goBtnAdd); } } else { this.titleLab.string = GameModel.player.teamInfo.type; cc.find('tabTeam/btnLeaveTeam', this.node).active = true; if (GameModel.player.isleader) { cc.find('tabTeam/btnList', this.node).active = true; } if (GameModel.player.teamInfo == null || GameModel.player.teamInfo.objlist == null) { return; } let partnerPos = 0; for (const obj of GameModel.player.teamInfo.objlist) { let goCard = this.CreateCard(obj); if (obj.livingtype == 1) { cc.find('picPtFlag', goCard).active = false; } else { goCard.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "OnClickCard", { nPos: partnerPos })); partnerPos++; } this.vecPartnerCard.push(goCard); } } }, CreateCard(objinfo) { let stStart = { nX: 90, nY: -170 }; let goPanel = cc.find('tabTeam/nodCardPanel', this.node); let prefab = objinfo.livingtype == 1 ? this.goPartnerCard_1 : this.goPartnerCard_2; let strPrefab = objinfo.livingtype == 1 ? 'goPartnerCard_1' : 'goPartnerCard_2'; let gap=0; if(this.vecPartnerCard){ gap=this.vecPartnerCard.length; }else{ cc.warn(`$警告:夥伴列表為空!`); } let goCard = CPubFunction.CreateSubNode(goPanel, { nX: stStart.nX + gap * 150, nY: -170 }, prefab, strPrefab); let roleNode = cc.find('role', goCard); CPubFunction.SetAnimation(roleNode,objinfo.resid, 'stand_1'); let stData = GameModel.conf_res_anchor[objinfo.resid]; if (stData) { roleNode.anchorY = stData.anchorY; } let nameRT=cc.find('labName', goCard).getComponent(cc.RichText); let title=`${objinfo.name}`; let vipLevel=VIPUtil.getVipLevel(objinfo.chargesum); if(vipLevel>0){ title=`${title}`; } nameRT.string = title; let level_lb=cc.find('labLevel', goCard).getComponent(cc.Label); GameUtil.setReliveLabel(level_lb,0,objinfo.relive,objinfo.level); SKUIUtil.setSpriteFrame(cc.find('picRace', goCard), 'Common/ui_common', CPubFunction.GetRaceFileName(objinfo.race)); let weaponNode=cc.find("weapon",roleNode); if(objinfo.account || objinfo.accountid){ roleNode.active=true; CPubFunction.addWeaponAnimation(objinfo.weapon,weaponNode,roleNode,this,objinfo.resid,"stand",1); // let wingId=objinfo.wingId; // if(wingId>=8000){ // wingId = SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", objinfo.wingId, "id", 0); // } //WingUtil.playAni(goCard,objinfo.roleid,1,"stand",0,wingId); }else{ roleNode.active=false; weaponNode.active=false; } return goCard; }, OpenPartnerUI() { CPubFunction.CreateSubNode(cc.find('Canvas/MainUI'), { nX: 0, nY: 0 }, this.PartnerUI, 'PartnerUI'); }, // OnTeam() { // CPubFunction.ChangeTeamNodeState(this.vecTabNode, 0); // CPubFunction.ChangeTeamButtonState(this.vecTagTeamBtn, 'Common/ui_common', 'ui_common_btn_tab1', 'ui_common_btn_tab2', 0); // }, // OnFixedTeam() //固定隊 // { // CPubFunction.ChangeTeamNodeState(this.vecTabNode, 1); // CPubFunction.ChangeTeamButtonState(this.vecTagTeamBtn, 'Common/ui_common', 'ui_common_btn_tab1', 'ui_common_btn_tab2', 1); // }, ClosePartnerList() { CPubFunction.FindAndDeleteNode(this.node, 'svPartnerList'); }, GetReservePartnerCnt() { let nCnt = 0; for (var it in CMainPlayerInfo.vecPartnerInfo) { let stInfo = CMainPlayerInfo.vecPartnerInfo[it]; if (CMainPlayerInfo.GetParterChuZhanPos(stInfo.id) == -1) nCnt++; } return nCnt; }, TeamChangePartnerState(e, nIndex) { this.ClosePartnerList(); CMainPlayerInfo.vecChuZhan[this.stOld.nPos] = CMainPlayerInfo.vecPartnerInfo[nIndex].id; GameModel.send('c2s_change_partner_state', { nPartnerID: CMainPlayerInfo.vecPartnerInfo[nIndex].id, nPos: this.stOld.nPos }); if (GameModel.player.teamid == 0) { this.CreateCardList(); } }, ShowRemainPartnerList(e, data) { let svPartnerList = CPubFunction.CreateSubNode(this.node, { nX: data.nX, nY: data.nY }, this.svPartnerList, 'svPartnerList'); cc.find('btnClose', svPartnerList).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "ClosePartnerList", 0)); let content = cc.find('ScrollView/view/content', svPartnerList); let nY = 30; let index=0; for (let stInfo of CMainPlayerInfo.vecPartnerInfo) { if (CMainPlayerInfo.GetParterChuZhanPos(stInfo.id) != -1){ index++; continue; } nY -= 90; let goPartner = CPubFunction.CreateSubNode(content, { nX: 140, nY: nY }, this.btnPartner, 'btnPartner'); SKUIUtil.setSpriteFrame(cc.find('HeadPic/Icon', goPartner), 'Common/huoban', 'huoban_' + stInfo.resid); cc.find('Name', goPartner).getComponent(cc.Label).string = stInfo.name; let level_lb=cc.find('Level', goPartner).getComponent(cc.Label); GameUtil.setReliveLabel(level_lb,0,stInfo.relive,stInfo.level); cc.find('picState', goPartner).active = false; goPartner.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "TeamUI", "TeamChangePartnerState", index)); index++; } let h=Math.max(content.height,index*90+30); content.height = h; }, OnClickCard(stEvetn, stData) { this.ShowRemainPartnerList(0, { nX: stEvetn.target.x - 275, nY: 0 }); this.stOld = stData; }, CreateTeam() { if (GameModel.player.prisonTime > 0){ MsgAlert.addMsg('傳說罪孽深重的人是創建不了隊伍的!'); return; } if (GameModel.player.teamid > 0) { return; } GameModel.send('c2s_create_team', { roleid: GameModel.player.roleid, type: this.titleLab.string }); }, LeaveTeam() { if (GameModel.player.teamid == 0) { return; } GameModel.send('c2s_leave_team', { roleid: GameModel.player.roleid, teamid: GameModel.player.teamid }); }, RequestTeam(teamid) { if (GameModel.player.teamid > 0) { return; } GameModel.send('c2s_requst_team', { roleid: GameModel.player.roleid, teamid: teamid }); }, MatchTeam() { if (GameModel.player.teamid > 0) { return; } GameModel.send('c2s_match_team', { roleid: GameModel.player.roleid }); }, ShowTeamList() { if (GameModel.player.prisonTime > 0) { MsgAlert.addMsg('老實點,天王老子也救不了你。'); return; } if (GameModel.player.teamid == 0) { cc.find('teamList', this.node).active = true; cc.find('teamList', this.node).getComponent('TeamList').getList(this.titleLab.string); } }, ShowRequestList() { if (GameModel.player.teamid > 0 && GameModel.player.isleader) { cc.find('requestList', this.node).active = true; cc.find('requestList', this.node).getComponent('TeamRequestList').getList(); } }, ShowTaskList() { if (GameModel.player.teamid > 0) { return; } this.typeList.active = true; }, touchBegan(event) { let touchPos = event.getLocation(); if (!this.typeList.getChildByName('listBg').getBoundingBoxToWorld().contains(touchPos)) { this.typeList.active = false; } }, initTypeList() { let typeList = ['無目標', '鍾馗抓鬼', '遊蕩妖魔', '三界妖王', '地煞星', '大雁塔', '尋芳', '地宮', '劇情任務']; let curListY = 0; let curListX = -240; this.typeContent.destroyAllChildren(); for (const type of typeList) { let item = cc.instantiate(this.typeItem); item.active = true; item.name = type; item.getChildByName('name').getComponent(cc.Label).string = type; item.x = curListX; item.y = curListY; curListX += 240; if (curListX > 240) { curListX = -240; curListY -= 85; } item.parent = this.typeContent; } if (curListX > -240) { curListY -= 85; } this.typeContent.height = -curListY; if (this.typeContent.height < this.typeContent.parent.height) { this.typeContent.height = this.typeContent.parent.height; } }, typeBtnClicked(e, d) { this.titleLab.string = e.target.name; }, Close() { AudioUtil.playCloseAudio(); this.node.destroy(); }, });