const GuildBatMod = require("guildbat.mod"); const BridgeWindow = require( "bridge.window" ); const GuildwarEvent = require("guildwar_event"); const GuildwarConst = require("guildbat.define"); const TPC = require("tips_controller"); cc.Class({ extends: BridgeWindow, properties: { rankNd:{ default:null, type:cc.Node }, previewNd:{ default:null, type:cc.Node }, mainNd:{ default:null, type:cc.Node }, pkinfo:{//雙方pk信息 default:null, type:cc.Node }, enyScrol:{ default:null, type:cc.ScrollView }, myScrol:{ default:null, type:cc.ScrollView }, fabSeat:{ default:null, type:cc.Node }, posBtn:{//陣地按鈕 default:null, type:cc.Node }, timeTxt:{ default:null, type:cc.Node }, chalengNum:{ default:null, type:cc.Node } }, // LIFE-CYCLE CALLBACKS: onLoad () { this.mod = GuildBatMod.getInstance(); this.cur_positions = GuildwarConst.positions.others;//默認敵方陣地 this.enyPosCmps = {}; this.myPosCmps = {}; this.bindGEvent(GuildwarEvent.GuildWarEnemyPositionDataInitEvent,this.initPositData.bind(this)); //階段狀態更新 this.bindGEvent(GuildwarEvent.UpdateGuildWarStatusEvent,this.updateStatus.bind(this)); this.bindGEvent(GuildwarEvent.UpdateGuildWarBaseInfoEvent,this.updateAllBaseInfo.bind(this)); //更新我方據點 this.bindGEvent(GuildwarEvent.GetGuildWarMyPositionDataEvent,this.initMyPosition.bind(this)); //單個據點更新 this.bindGEvent(GuildwarEvent.UpdateGuildWarPositionDataEvent,this.updateWarPosition.bind(this)); this.bindGEvent(GuildwarEvent.UpdateGuildwarChallengeCountEvent,this.upChallengeCount.bind(this)); }, upChallengeCount(){ let count = this.mod.getGuildWarChallengeCount(); nx.gui.setString(this.chalengNum,"",count); }, initPositData(){ //設置前三名排行 this.setThreeRanks(); this.setPkInfo(); this.upChallengeCount(); let end_time = this.mod.getENdTime(); nx.gui.setCdTxt(this.timeTxt,"",end_time - client.socket.getTime()); //設置敵對聯盟據點 this.initEnemyPosition(); }, initEnemyPosition(){ let list = this.mod.getEnemyGuildWarPositionList(); if(list.length == 0)return; //需要设置最大区域 let max_data = game.configs.guild_war_data.data_position[list[list.length - 1].pos]; let max_y = (0 - max_data.pos_y) + 100; this.enyScrol.content.height = max_y; for(let i in list){ let data = list[i]; if(data){ let cmp = this.enyPosCmps[data.pos]; if(cmp){ cmp.setData(data); }else{ let seat = cc.instantiate(this.fabSeat); seat.parent = this.enyScrol.content; let new_cmp = nx.gui.getComponent(seat,"","cmp.guildbat.item.seat"); if(new_cmp){ this.enyPosCmps[data.pos] = new_cmp; new_cmp.setData(data); } } } } }, initMyPosition(){ let list = this.mod.getMyGuildWarPositionList(); if(list.length == 0)return; //需要设置最大区域 let max_data = game.configs.guild_war_data.data_position[list[list.length - 1].pos]; let max_y = (0 - max_data.pos_y) + 100; this.myScrol.content.height = max_y; for(let i in list){ let data = list[i]; if(data){ let cmp = this.myPosCmps[data.pos]; if(cmp){ cmp.setData(data); }else{ let seat = cc.instantiate(this.fabSeat); seat.parent = this.myScrol.content; let new_cmp = nx.gui.getComponent(seat,"","cmp.guildbat.item.seat"); if(new_cmp){ this.myPosCmps[data.pos] = new_cmp; new_cmp.setData(data); } } } } }, //單個據點更新 updateWarPosition(pos,data){ if(this.cur_positions == GuildwarConst.positions.others){//是否我方 let enyCmp = this.enyPosCmps[pos]; if(enyCmp){ enyCmp.setData(data); } }else{ let myCmp = this.myPosCmps[pos]; if(myCmp){ myCmp.setData(data); } } }, //基礎信息更新 updateAllBaseInfo(){ this.setPkInfo(); this.setThreeRanks(); }, //階段狀態更新 updateStatus(status,flag){ if(status > 2){//參加活動狀態 //請求詳細數據 this.mod.requestGuildWarData(); if(status == 3){//匹配結果展示 this.previewNd.active = true; this.mainNd.active = false; nx.gui.setActive(this.previewNd,"view_btn",true); nx.gui.setString(this.previewNd,"ti1",cc.js.formatStr(nx.text.getKey("GuildBatOpen"),"12:00")); nx.gui.setString(this.previewNd,"in",nx.text.getKey("GuildBatOntime")); }else if(status == 4){//開戰中 if(flag == 1){//匹配到對手 this.previewNd.active = false; this.mainNd.active = true; }else{ this.emptyTip(); } }else if(status == 5){//結算 if(flag == 1){//匹配到對手 this.previewNd.active = false; this.mainNd.active = true; }else{ this.emptyTip(); } } }else{//場外時間 // if(status == 1){//空閑時間 // this.previewNd.active = false; // this.mainNd.active = false; // }else{//匹配中 // } this.emptyTip(); } }, emptyTip(){ this.previewNd.active = true; this.mainNd.active = false; nx.gui.setActive(this.previewNd,"view_btn",false); nx.gui.setString(this.previewNd,"ti1",nx.text.getKey("GuildBatNoOpen")); let desc = game.configs.guild_war_data.data_const.time_desc.desc; nx.gui.setString(this.previewNd,"in",desc); }, setPkInfo(){ let myBaseInfo = this.mod.getMyGuildWarBaseInfo(); let enyBaseInfo = this.mod.getEnemyGuildWarBaseInfo(); nx.gui.setString(this.pkinfo,"gud1",myBaseInfo.gname); nx.gui.setString(this.pkinfo,"gud2",enyBaseInfo.gname); nx.gui.setString(this.pkinfo,"num",myBaseInfo.hp); nx.gui.setString(this.pkinfo,"num2",enyBaseInfo.hp); }, //設置排行榜 setThreeRanks(){ let rank_data = this.mod.getGuildWarTopThreeRank(); for(let i in rank_data){ let data = rank_data[i]; let nd = nx.gui.find(this.rankNd,String(data.rank)); if(nd){ nx.gui.setString(nd,"name",data.name); } } }, onOpenConfigs() { nx.gui.setString(this.posBtn,"txt",nx.text.getKey("GuildBatMyPos")); this.mod.reqestGuildWarStatus(); }, onPreClosed() { this.enyPosCmps = null; this.myPosCmps = null; }, openMetaView(){ nx.bridge.createPanel("WndGuildBatMeta"); }, openBoxAward(){ nx.bridge.createPanel("WndGuildBatBox"); }, openRank(){ this.mod.requestGuildWarRankData(); // nx.bridge.createPanel("WndGuildBatRank"); }, openChat(){ let ChatCtrl = require("chat_controller"); ChatCtrl.getInstance().openChatPanel(); }, openTips(){ let explain = game.configs.guild_war_data.data_explain; TPC.getInstance().showDetailPanel(explain); }, changeMyPositions(){ if(this.cur_positions == GuildwarConst.positions.others){ this.enyScrol.node.active = false; this.myScrol.node.active = true; this.mod.requestMyGuildPositionData(); this.cur_positions = GuildwarConst.positions.myself; nx.gui.setString(this.posBtn,"txt",nx.text.getKey("GuildBatOthPos")); }else{ this.enyScrol.node.active = true; this.myScrol.node.active = false; this.cur_positions = GuildwarConst.positions.others; nx.gui.setString(this.posBtn,"txt",nx.text.getKey("GuildBatMyPos")); } }, openBatLog(){ nx.bridge.createPanel("WndGuildBatLog"); }, getPositionType(){ return this.cur_positions || 0; }, });