Files
2026-05-23 22:10:14 +08:00

146 lines
3.9 KiB
JavaScript

const CampfightConst = require( "campfight.const" );
const CampfightMod = require("campfight.mod");
const BridgeCmp = require("bridge.component");
const NxTogs = require("nx.fx.togs");
const ItemLay = require("cmp.common.itemlayout");
const ReportCmp = require("cmp.campfight.report");
const HeroConst = require("hero_const");
const HeroController = require("hero_controller");
const PartnerConst = require("partner_const");
cc.Class({
extends: BridgeCmp,
properties: {
groupTog:{
default:null,
type:NxTogs
},
seats:{
default:null,
type:cc.Node
},
fabSeat:{
default:null,
type:cc.Prefab
},
// seatList:{
// default:null,
// type:ItemLay
// },
reportView:{
default:null,
type:cc.Node
},
ReportCmp:{
default:null,
type:ReportCmp
},
emptyTip:{
default:null,
type:cc.Node
}
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
this._super();
this.mod = CampfightMod.getInstance();
this.seatsCamps = {};
this.groupTog.posTog = this.onTogMenu.bind( this );
this.bindGEvent(CampfightConst.EVT_CAMP_BATUI,this.freshSeats.bind(this));
this.bindGEvent(CampfightConst.EVT_CAMP_UPSEAT,this.ChangeGroup.bind(this));
},
onTogMenu(_index){
this.mod.reqBatGroup(_index + 1,(_data)=>{
if(_data){
this.mod.setReqGroup(_index + 1);
}
});
this.ReportCmp.setCurGroup(_index + 1);
},
freshSeats(data){
if(nx.dt.objEmpty(data))return;
this.emptyTip.active = false;
if(nx.dt.arrEmpty(data.role_list)){
this.emptyTip.active = true;
}
data.role_list.sort(Utils.tableLowerSorter(["rank"]))
// this.seatList.rebuild(data.role_list);
//刷新座位
for(let d=0;d<8;d++){
let mdata = data.role_list[d];
let nd = nx.gui.find(this.seats,String(d));
if(mdata){
let cmp = this.seatsCamps[mdata.rank];
if(cmp){
cmp.setData(mdata);
}else{
if(nd){
let fab = cc.instantiate(this.fabSeat);
fab.parent = nd;
let newcmp = nx.gui.getComponent(fab,"","cmp.campfight.battle.item");
if(newcmp){
newcmp.setData(mdata);
this.seatsCamps[mdata.rank] = newcmp;
}
}
}
}else{
this.seatsCamps[d+1] = null;
if(nd){
nx.bridge.NodeChidrenDestroy(nd);
}
}
}
},
ChangeGroup(group){
if(group == 0){
this.groupTog.togTo(0,true);
this.mod.reqBatGroup(1,(_data)=>{
if(_data){
this.mod.setReqGroup(1);
}
});
}else{
this.groupTog.togTo(group - 1);
this.mod.reqBatGroup(group,(_data)=>{
if(_data){
this.mod.setReqGroup(group);
}
});
}
},
onEnable(){
this.mod.reqSelfGroup();//再次請求分組
},
onDisable(){
// this.seatList.rebuild([]);
this.seatsCamps = null;
// 监听事件释放
this.unbindGEvents();
},
//商店
onClickShop(){
},
//戰報
onClickReport(){
this.reportView.active = true;
},
onSetDefendForm(){
HeroController.getInstance().openFormGoFightPanel(true, PartnerConst.Fun_Form.YearDefend, {period:this.mod.getCurPeriod(),need_hide_top:true}, HeroConst.FormShowType.eFormSave)
}
// update (dt) {},
});