Files
fc/dev/project/assets/Scripts/mod/pray/cmp/cmp.holy.pray.wish.js
T
2026-05-23 22:10:14 +08:00

392 lines
12 KiB
JavaScript

const BridgeWindow = require( "bridge.window" );
const FxSVC = require( "nx.fx.sv.expand" );
const PrayMod = require( "pray.mod" );
const FXTogs = require( "nx.fx.togs" );
cc.Class({
extends: BridgeWindow,
properties: {
svcList: { default: null, type: FxSVC },
nodMenu: { default: null, type: FXTogs },
nodChoice: { default: [], type: cc.Node },
nodDesc : { default: null, type: cc.Node },
},
// 重载:参数打开
onOpenConfigs: function( _params ) {
let pray = PrayMod.getInstance();
this.group_id = _params.group_id;
this.selectedPos = _params.select;
this.preSelect = [];
this.selectedPos.forEach( _nod => {
this.preSelect.push( _nod.lucky_holy_eqm );
} )
this.showLst = pray.getShow();
for (let i = 0; i < this.showLst.length; i++) {
let lst = this.showLst[i];
let lsts = lst.lst;
lsts.forEach( _item => {
_item.inTeam = 0;
this.selectedPos.forEach( _pos =>{
if( _pos.lucky_holy_eqm == _item.group_id ){
_item.inTeam = _pos.pos + 1;
}
} )
} )
}
this.nodMenu.posTog = this.onTogType.bind( this );
this.nodMenu.togTo( 0 );
this.onTogType( 0 );
//刷新已選列表
this.freshSelected();
this.onTouch( _params.focus || 0 );
// 引导辅助
if( nx.bridge.plot && nx.bridge.plot.isDoing() ) {
this.positionWish();
}
// // 重建
// this.rebuild();
},
// 重载:关闭前
onPreClosed: function() {
this.svcList.rebuild( [] );
},
freshSelected: function(){
let cfgs = game.configs.holy_eqm_lottery_data.data_wish_show;
for (let i = 0; i < this.nodChoice.length; i++) {
let nod = this.nodChoice[i];
let luckInfo = this.selectedPos[i];
let cmp = nx.gui.getComponent( nod, "", "cmp.holy.eqm.item" );
if( cmp ){
if( luckInfo ){
if( luckInfo.lucky_holy_eqm == 0 ){
cmp.rebind( i, {} );
}else{
let info = cfgs[luckInfo.lucky_holy_eqm];
cmp.rebind( i, info );
}
}else{
cmp.rebind( i, {} );
}
}
}
// this.freshWish();
},
onTogType : function( _idx ){
let idx = parseInt( _idx ) || 0;
let change = idx + 23;
if( this.curTag == change ) {
return;
}
this.curTag = change;
this.freshEqm();
// this.freshWish();
},
freshEqm: function(){
this.showLst.forEach( item => {
if( item.type == this.curTag ){
this.svcList.rebuild( item.lst );
}
});
this.dealShow(2);
},
onTouch: function( _idx ){
for (let i = 0; i < this.nodChoice.length; i++) {
let nod = this.nodChoice[i];
let cmp = nod.getComponent( "cmp.holy.eqm.item" );
if( cmp ){
if( i != _idx ){
cmp.outFocus();
}else{
cmp.setFocus();
let data = cmp.mdata;
if( cmp.mdata ){
let desc = "";
if( nx.dt.objNEmpty( cmp.mdata ) ){
desc = nx.text.format( "HolyWishDesc", data.name, data.desc );
}
nx.gui.setString( this.nodDesc, "txt", desc );
}
}
}
}
this.select = _idx;
// nx.gui.setActive( this.nodChoice[_idx], "base/focus", true ) ;
},
onTouchChange: function( _idx ){
// 點擊切換選中,并且
let snode = nx.gui.find( this.svcList.bindSCV, "view/content" );
if( snode ){
let nodes = snode.children;
// 如果沒有選擇項
if( nx.dt.arrEmpty( this.selectedPos ) ){
for (let i = 0; i < nodes.length; i++) {
let selectNode = nodes[i];
let cmp = selectNode.svItem;
if( cmp ){
if( i == _idx.index ){
if( cmp.focus ){
cmp.outFocus();
this.onFreshInfo( {} );
}else{
cmp.setFocus();
this.onFreshInfo( cmp.mdata );
}
}else{
cmp.outFocus();
}
}
}
}else{
for (let i = 0; i < nodes.length; i++) {
let selectNode = nodes[i];
let cmp = selectNode.svItem;
if( cmp ){
if( cmp.index == _idx.index ){
if( cmp.focus ){
let pcmp = nx.gui.getComponent( this.nodChoice[cmp.mdata.inTeam - 1], "", "cmp.holy.eqm.item" );
if( pcmp ){
pcmp.rebind( pcmp.index, {} );
cmp.mdata.inTeam = 0;
nx.gui.setString( this.nodDesc, "txt", "" );
}
cmp.rebind( cmp.index, cmp.mdata );
}else{
cmp.mdata.inTeam = ( parseInt( this.select ) + 1 ) ;
cmp.rebind( cmp.index, cmp.mdata );
this.onFreshInfo( cmp.mdata );
}
}else{
// cmp.mdata.inTeam = 0;
cmp.rebind( cmp.index, cmp.mdata );
}
}
}
}
// console.log( JSON.stringify( schemes ) + "当前的默认方案配置" + JSON.stringify( defaultSchemeInfo ) );
}
},
onFreshInfo: function( _info ){
this.dealShow( 1 );
let cmp = nx.gui.getComponent( this.nodChoice[this.select], "", "cmp.holy.eqm.item" );
if( cmp ){
cmp.rebind( this.select, _info );
}
let desc = nx.text.format( "HolyWishDesc", _info.name, _info.desc );
nx.gui.setString( this.nodDesc, "txt", desc );
// nx.bridge.setIconS( nod, "", _info.icon );
// nx.gui.setActive( this.nodChoice[_idx], "base/focus", !nx.gui.find( this.nodChoice[_idx], "base/focus" ).active ) ;
},
dealShow: function( _type ){
let snode = nx.gui.find( this.svcList.bindSCV, "view/content" );
// console.log( JSON.stringify( _item ) + "当前的默认方案配置" + snode );
if( snode ){
let nodes = snode.children;
let cmpd = nx.gui.getComponent( this.nodChoice[this.select], "", "cmp.holy.eqm.item" );
for (let i = 0; i < nodes.length; i++) {
let selectNode = nodes[i];
let cmp = selectNode.svItem;
if( cmp && cmpd ){
if( cmp.mdata.icon == cmpd.mdata.icon && _type == 1 ){
cmp.mdata.inTeam = 0;
cmp.rebind( cmp.index, cmp.mdata );
}
if( cmp.mdata.inTeam == cmpd.mdata.inTeam && _type == 2 && cmp.mdata.icon != cmpd.mdata.icon ){
cmp.mdata.inTeam = 0;
cmp.rebind( cmp.index, cmp.mdata );
}
}
}
// console.log( JSON.stringify( schemes ) + "当前的默认方案配置" + JSON.stringify( defaultSchemeInfo ) );
}
},
// 點擊確認
onTouchConfirm: function(){
/***
* [25230]:{"group_id":1,"lucky_holy_eqm":[{"pos":0,"lucky_holy_eqm":101},{"pos":1,"lucky_holy_eqm":0},{"pos":2,"lucky_holy_eqm":0},{"pos":3,"lucky_holy_eqm":0}]}
*/
let holys = [];
for (let i = 0; i < this.nodChoice.length; i++) {
let nod = this.nodChoice[i];
let cmp = nod.getComponent( "cmp.holy.eqm.item" );
if( cmp ){
if( !nx.dt.objEmpty( cmp.mdata ) ){
holys.push( {
pos : i,
lucky_holy_eqm : cmp.mdata.group_id
} )
}else{
holys.push( {
pos : i,
lucky_holy_eqm : 0
} )
}
}
}
let pray = PrayMod.getInstance();
pray.sender25230( this.group_id, holys );
},
freshWish: function(){
let snode = nx.gui.find( this.svcList.bindSCV, "view/content" );
// console.log( JSON.stringify( _item ) + "当前的默认方案配置" + snode );
if( snode ){
let nodes = snode.children;
for (let i = 0; i < nodes.length; i++) {
let selectNode = nodes[i];
let cmp = selectNode.svItem;
if( cmp ){
this.selectedPos.forEach( _nod => {
if( _nod.lucky_holy_eqm == cmp.mdata.group_id ){
cmp.setFocus();
}
} )
}
}
// console.log( JSON.stringify( schemes ) + "当前的默认方案配置" + JSON.stringify( defaultSchemeInfo ) );
}
},
/****
* 引导 -------
*/
// 定位最弱的一个
positionWish: function() {
let node = null;
let chd = nx.gui.find( this.svcList.bindSCV, "view/content" );
if( chd ){
let nodes = chd.children;
node = nodes[ 0 ];
// let node = null;
// let children = this.svcList.bindSCV.content.children;
// for( let i = 0; i < children.length; ++i ) {
// let temp = children[ i ];
// if( temp.svItem && temp.svItem.mdata && temp.svItem.mdata.bid == 20401 ) {
// node = temp;
// break;
// }
// }
if( !node ) {
nx.error( "$ParterPage:定位特定英雄失败!" );
node = chd[ 0 ];
if( !node ) {
return;
}
}
let cell = nx.gui.find( this, "plot" );
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;
cell.index = node.svItem.index;
nx.gui.setActive( this, "plot", true );
}
},
onTouchSelf : function( _nod ){
let nod = nx.gui.find( this, "plot" );
if( nod ){
this.onTouchChange( nod );
}
},
});