276 lines
8.6 KiB
JavaScript
276 lines
8.6 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '408c6+Pm/NAubkoaXGGE1iU', 'cmp.guildbat.main');
|
|
// Scripts/mod/guild/guildbat/cmp/cmp.guildbat.main.js
|
|
|
|
"use strict";
|
|
|
|
var GuildBatMod = require("guildbat.mod");
|
|
var BridgeWindow = require("bridge.window");
|
|
var GuildwarEvent = require("guildwar_event");
|
|
var GuildwarConst = require("guildbat.define");
|
|
var 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: function 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: function upChallengeCount() {
|
|
var count = this.mod.getGuildWarChallengeCount();
|
|
nx.gui.setString(this.chalengNum, "", count);
|
|
},
|
|
initPositData: function initPositData() {
|
|
//設置前三名排行
|
|
this.setThreeRanks();
|
|
this.setPkInfo();
|
|
this.upChallengeCount();
|
|
var end_time = this.mod.getENdTime();
|
|
nx.gui.setCdTxt(this.timeTxt, "", end_time - client.socket.getTime());
|
|
//設置敵對聯盟據點
|
|
this.initEnemyPosition();
|
|
},
|
|
initEnemyPosition: function initEnemyPosition() {
|
|
var list = this.mod.getEnemyGuildWarPositionList();
|
|
if (list.length == 0) return;
|
|
//需要设置最大区域
|
|
var max_data = game.configs.guild_war_data.data_position[list[list.length - 1].pos];
|
|
var max_y = 0 - max_data.pos_y + 100;
|
|
this.enyScrol.content.height = max_y;
|
|
for (var i in list) {
|
|
var data = list[i];
|
|
if (data) {
|
|
var cmp = this.enyPosCmps[data.pos];
|
|
if (cmp) {
|
|
cmp.setData(data);
|
|
} else {
|
|
var seat = cc.instantiate(this.fabSeat);
|
|
seat.parent = this.enyScrol.content;
|
|
var new_cmp = nx.gui.getComponent(seat, "", "cmp.guildbat.item.seat");
|
|
if (new_cmp) {
|
|
this.enyPosCmps[data.pos] = new_cmp;
|
|
new_cmp.setData(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
initMyPosition: function initMyPosition() {
|
|
var list = this.mod.getMyGuildWarPositionList();
|
|
if (list.length == 0) return;
|
|
//需要设置最大区域
|
|
var max_data = game.configs.guild_war_data.data_position[list[list.length - 1].pos];
|
|
var max_y = 0 - max_data.pos_y + 100;
|
|
this.myScrol.content.height = max_y;
|
|
for (var i in list) {
|
|
var data = list[i];
|
|
if (data) {
|
|
var cmp = this.myPosCmps[data.pos];
|
|
if (cmp) {
|
|
cmp.setData(data);
|
|
} else {
|
|
var seat = cc.instantiate(this.fabSeat);
|
|
seat.parent = this.myScrol.content;
|
|
var new_cmp = nx.gui.getComponent(seat, "", "cmp.guildbat.item.seat");
|
|
if (new_cmp) {
|
|
this.myPosCmps[data.pos] = new_cmp;
|
|
new_cmp.setData(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
//單個據點更新
|
|
updateWarPosition: function updateWarPosition(pos, data) {
|
|
if (this.cur_positions == GuildwarConst.positions.others) {
|
|
//是否我方
|
|
var enyCmp = this.enyPosCmps[pos];
|
|
if (enyCmp) {
|
|
enyCmp.setData(data);
|
|
}
|
|
} else {
|
|
var myCmp = this.myPosCmps[pos];
|
|
if (myCmp) {
|
|
myCmp.setData(data);
|
|
}
|
|
}
|
|
},
|
|
//基礎信息更新
|
|
updateAllBaseInfo: function updateAllBaseInfo() {
|
|
this.setPkInfo();
|
|
this.setThreeRanks();
|
|
},
|
|
//階段狀態更新
|
|
updateStatus: function 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: function 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"));
|
|
var desc = game.configs.guild_war_data.data_const.time_desc.desc;
|
|
nx.gui.setString(this.previewNd, "in", desc);
|
|
},
|
|
setPkInfo: function setPkInfo() {
|
|
var myBaseInfo = this.mod.getMyGuildWarBaseInfo();
|
|
var 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: function setThreeRanks() {
|
|
var rank_data = this.mod.getGuildWarTopThreeRank();
|
|
for (var i in rank_data) {
|
|
var data = rank_data[i];
|
|
var nd = nx.gui.find(this.rankNd, String(data.rank));
|
|
if (nd) {
|
|
nx.gui.setString(nd, "name", data.name);
|
|
}
|
|
}
|
|
},
|
|
onOpenConfigs: function onOpenConfigs() {
|
|
nx.gui.setString(this.posBtn, "txt", nx.text.getKey("GuildBatMyPos"));
|
|
this.mod.reqestGuildWarStatus();
|
|
},
|
|
onPreClosed: function onPreClosed() {
|
|
this.enyPosCmps = null;
|
|
this.myPosCmps = null;
|
|
},
|
|
openMetaView: function openMetaView() {
|
|
nx.bridge.createPanel("WndGuildBatMeta");
|
|
},
|
|
openBoxAward: function openBoxAward() {
|
|
nx.bridge.createPanel("WndGuildBatBox");
|
|
},
|
|
openRank: function openRank() {
|
|
this.mod.requestGuildWarRankData();
|
|
// nx.bridge.createPanel("WndGuildBatRank");
|
|
},
|
|
openChat: function openChat() {
|
|
var ChatCtrl = require("chat_controller");
|
|
ChatCtrl.getInstance().openChatPanel();
|
|
},
|
|
openTips: function openTips() {
|
|
var explain = game.configs.guild_war_data.data_explain;
|
|
TPC.getInstance().showDetailPanel(explain);
|
|
},
|
|
changeMyPositions: function 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: function openBatLog() {
|
|
nx.bridge.createPanel("WndGuildBatLog");
|
|
},
|
|
getPositionType: function getPositionType() {
|
|
return this.cur_positions || 0;
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |