Files
fc/dev/project/assets/Scripts/mod/partner/cmps/bag/cmp.partner.page.js
T

267 lines
7.0 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
/******************************************************************
*
* 伙伴背包页
*
******************************************************************/
const FxTogs = require( "nx.fx.togs" );
const FxSVC = require( "nx.fx.sv.expand" );
const MenuPage = require( "cmp.com.menu.page" );
const HeroConst = require( "hero_const" );
const HeroEvent = require( "hero_event" );
const HeroControl = require( "hero_controller" );
const HCT = HeroConst.CampType;
cc.Class( {
extends: MenuPage,
properties: {
togCamp: { default: null, type: FxTogs },
svcList: { default: null, type: FxSVC },
},
// 载入
onLoad: function() {
this._super();
// 事件监听
this.bindGEvent( HeroEvent.Buy_Hero_Max_Count_Event, this.onBuyMaxHeroCount.bind( this ) );
this.bindGEvent( HeroEvent.Del_Hero_Event, this.onADHeros.bind( this ) );
this.bindGEvent( HeroEvent.Hero_Data_Add, this.onADHeros.bind( this ) );
this.bindGEvent( HeroEvent.All_Hero_Base_Info_Event, this.onHeroInfoFresh.bind( this ) );
this.bindGEvent( HeroEvent.Hero_Data_Update, this.onHeroInfoFreshSingle.bind( this ) );
this.bindGEvent( HeroEvent.Equip_Update_Event, this.onHeroInfoFreshSingle.bind( this ) );
this.curCamp = -1;
// Tog监听
this.togCamp.posTog = this.onTogCamp.bind( this );
this.togCamp.togTo( 0 );
nx.bridge.vset( "ShowPartner", {} );
this.scheduleOnce( () => {
this.onTogCamp( HCT.eNone );
}, 0.02 );
},
// 重载:关闭前
onPreClosed: function() {
this.unscheduleAllCallbacks();
this.svcList.rebuild( [] );
},
// 购买伙伴上限返回
onBuyMaxHeroCount: function() {
},
// 伙伴增删
onADHeros: function( _lst ) {
let upd = false;
for( let i in _lst ) {
let ho = _lst[ i ];
if( ho && ( ho.camp_type == this.curCamp || this.curCamp == 0 ) ) {
upd = true;
break;
}
}
if( upd ) {
this.freshList();
}
},
// 所有英雄基础信息获取事件
onHeroInfoFresh: function() {
// 整体刷新
this.freshList();
},
onHeroInfoFreshSingle: function( _data ){
let nodes = nx.gui.find( this.svcList.bindSCV, "view/content" ).children;
nodes.forEach( _nod =>{
if( _nod ){
let cmp = _nod.svItem;
if( cmp ){
if( cmp.mdata.partner_id == _data.partner_id ){
cmp.rebind( cmp.index, _data, cmp.key );
}
if( cmp.mdata.is_in_form > 0 ){
cmp.checkTip();
}
}
}
} )
},
// 整体刷新
freshList: function() {
let HC = HeroControl.getInstance();
let mod = HC.getModel();
this.partners = mod.getHeroListByCamp( this.curCamp );
this.partners.sort( Utils.tableUpperSorter( [ "sortidd", "star", "quality", "lev" ]) );
nx.gui.setActive( this.svcList, "empty", false );
this.svcList.rebuild( this.partners );
// 引导辅助
if( nx.bridge.plot && nx.bridge.plot.isDoing() ) {
// console.log( "檢測引導" );
this.position20401();
}
},
// 阵营切换
onTogCamp: function( _index ) {
let idx = parseInt( _index ) || 0;
if( this.curCamp == idx ) {
return;
}
nx.debug( `[Hero]阵营切换:${ this.curCamp } -> ${ idx }` );
this.curCamp = idx;
// 整体刷新
this.freshList();
},
// 选中切换
onFocusChanged: function( _item ) {
nx.audio.playSFX( "audios/effects/touchitem" );
// 空
if( nx.dt.objEmpty( _item ) ||
nx.dt.objEmpty( _item.mdata ) ) {
return;
}
// // 聚焦
// this.svcList.cleanFocus();
// this.svcList.addFocus( _item.index );
let HC = HeroControl.getInstance();
if( HC ) {
HC.openHeroMainInfoWindow( true, _item.mdata, this.partners );
}
},
// ============================================
// 引导辅助
// ============================================
// 特定英雄定位
position20401: function() {
// console.log( "當前的引導" + JSON.stringify( nx.bridge.plot ) );
let info = nx.bridge.plot.vget( "info" );
let step = nx.bridge.plot.vget( "step" );
let units = "";
let unit = null;
if( info && info.steps ){
unit = info.steps[step + 1].unit
if( unit ){
units = unit.split( '_' )
}
}
let node = null;
let have = 0;
let children = this.svcList.bindSCV.content.children;
children.forEach( _item =>{
if( _item.svItem && _item.svItem.mdata && _item.svItem.mdata.bid && _item.svItem.mdata.bid != 0 ){
have++;
}
} )
for( let i = 0; i < children.length; ++i ) {
let temp = children[ i ];
if( temp.svItem && temp.svItem.mdata ) {
if( have <= 2 ){
if( unit && temp.svItem.mdata.bid == units[1] && units[1] == 20401 ){
node = temp;
break;
}
}
if( have >= 3 ){
if( unit && temp.svItem.mdata.bid == units[1] && ( units[1] == 20401 || units[1] == 30508 ) ){
node = temp;
break;
}
}
}
}
if( !node ) {
nx.error( "$ParterPage:定位特定英雄失败!" + have );
node = have == 2 ? children[0] : children[2] ;
if( !node ) {
return;
}
}
let cell = nx.gui.find( this, "panel/plotCell" );
let cmp = nx.gui.getComponent( cell, "", "cmp.plot.trigger" );
let pos = node.convertToWorldSpaceAR( cc.Vec2.ZERO );
cell.position = cell.parent.convertToNodeSpaceAR( pos );
cell.width = node.width;
cell.height = node.height;
cell.mdata = node.svItem.mdata;
if( cmp ){
cmp.pID = "partner_" + cell.mdata.bid;
cmp.regist();
}
},
// 点击特定英雄处理
onTouchPartner20401: function() {
let cell = nx.gui.find( this, "panel/plotCell" );
let cmp = nx.gui.getComponent( cell, "", "cmp.plot.trigger" );
let HC = HeroControl.getInstance();
if( HC ) {
HC.openHeroMainInfoWindow( true, cell.mdata );
if( cmp ){
nx.bridge.plot.unregUnit( this.pID )
}
}
},
} );