233 lines
6.6 KiB
JavaScript
233 lines
6.6 KiB
JavaScript
const BridgeWindow = require( "bridge.window" );
|
|
const FxSVC = require( "nx.fx.sv.expand" );
|
|
const Mod = require( "act.sevencustom.mod" );
|
|
const BackpackController = require( "backpack_controller" );
|
|
|
|
cc.Class({
|
|
extends: BridgeWindow,
|
|
|
|
properties: {
|
|
|
|
svcRewardsList : {
|
|
default: null,
|
|
type : FxSVC,
|
|
displayName: "奖励列表",
|
|
},
|
|
|
|
nodRewards : {
|
|
default: null,
|
|
type : cc.Node,
|
|
displayName: "上方奖励列表",
|
|
},
|
|
|
|
nodLeft : {
|
|
default: null,
|
|
type : cc.Node,
|
|
displayName: "左邊顯示相關",
|
|
}
|
|
},
|
|
|
|
// 重载:参数打开
|
|
onOpenConfigs: function( _params ) {
|
|
|
|
this.day = _params.day;
|
|
this.cate = _params.cate;
|
|
this.cfg = _params.config;
|
|
this.pos = _params.pos;
|
|
this.cfgs = gdata( this.cfg, "data_optional_reward", this.cate + 1 );
|
|
this.select = _params.pos;
|
|
this.inPos = _params.select;
|
|
this.dealRewards( this.select );
|
|
|
|
if( _params.select ){
|
|
this.inPos.sort( ( a, b ) =>{
|
|
return a.bid - b.bid;
|
|
} )
|
|
for (let i = 0; i < this.inPos.length; i++) {
|
|
|
|
let item = this.nodRewards.children[i];
|
|
let cmp = nx.gui.getComponent( item, "item", "cmp.item.base" );
|
|
if( cmp ){
|
|
cmp.rebind( i ,this.inPos[i] );
|
|
}
|
|
nx.gui.setActive( item, "item", true );
|
|
nx.gui.setActive( item, "change", true );
|
|
if( i == this.select - 1 ){
|
|
let pos = {
|
|
mdata : this.inPos[i],
|
|
}
|
|
this.onTouchAdd( pos );
|
|
}
|
|
|
|
}
|
|
}else{
|
|
this.freshLeftCnt( [] );
|
|
}
|
|
},
|
|
|
|
|
|
onTouchChange: function( _item ){
|
|
|
|
|
|
},
|
|
|
|
onTouchFocus : function( _idx ){
|
|
|
|
this.dealRewards( _idx );
|
|
this.select = _idx;
|
|
if( this.inPos ){
|
|
let pos = {
|
|
mdata : this.inPos[ this.select - 1 ],
|
|
}
|
|
|
|
this.onTouchAdd( pos );
|
|
}else{
|
|
this.freshLeftCnt( [] );
|
|
}
|
|
|
|
},
|
|
|
|
dealRewards : function( _idx ){
|
|
|
|
for (let n = 0; n < this.nodRewards.children.length; n++) {
|
|
let nod = this.nodRewards.children[n];
|
|
let cfgg = this.cfgs[n+1];
|
|
nx.gui.setActive( nod, "focus", false );
|
|
if( !cfgg ){
|
|
nx.gui.setActive( nod, "", false );
|
|
continue;
|
|
}
|
|
if( n == ( _idx - 1 ) ){
|
|
nx.gui.setActive( nod, "focus", true );
|
|
}
|
|
nx.gui.setActive( nod, "", true );
|
|
}
|
|
|
|
let show = this.cfgs[ _idx ];
|
|
this.svcRewardsList.rebuild( show );
|
|
|
|
},
|
|
|
|
onTouchAdd : function( _item ){
|
|
|
|
let nodes = nx.gui.find( this.svcRewardsList.bindSCV, "view/content" ).children;
|
|
// console.log( "当前的方案处理www" );
|
|
|
|
let select = parseInt( this.select );
|
|
let mdata = _item.mdata;
|
|
let item = this.nodRewards.children[select - 1];
|
|
let cmp = nx.gui.getComponent( item, "item", "cmp.item.base" );
|
|
if( cmp ){
|
|
cmp.rebind( select - 1 ,mdata );
|
|
}
|
|
nx.gui.setActive( item, "item", true );
|
|
nx.gui.setActive( item, "change", true );
|
|
let show = {};
|
|
if( nx.dt.arrNEmpty( mdata ) ){
|
|
|
|
show = {
|
|
bid : mdata[0],
|
|
num : mdata[1],
|
|
}
|
|
}
|
|
if( nx.dt.objNEmpty( mdata ) ){
|
|
|
|
show = mdata;
|
|
}
|
|
|
|
for (let i = 0; i < nodes.length; i++) {
|
|
if( nodes[i].svItem ){
|
|
let chd = nodes[i].svItem;
|
|
if( chd.mdata[0] == show.bid ){
|
|
chd.onFocus();
|
|
}else{
|
|
chd.outFocus();
|
|
}
|
|
}
|
|
|
|
}
|
|
this.freshLeftCnt( show );
|
|
},
|
|
|
|
onTouchSave: function(){
|
|
|
|
let rewards = [];
|
|
let chd = this.nodRewards.children;
|
|
chd.forEach( _nod => {
|
|
if( _nod.active ){
|
|
let cmp = nx.gui.getComponent( _nod, "item", "cmp.item.base" );
|
|
if( cmp.mdata ){
|
|
|
|
rewards.push( {
|
|
item_id : cmp.mdata[0] || cmp.mdata.bid ,
|
|
num : cmp.mdata[1] || cmp.mdata.num,
|
|
} )
|
|
}
|
|
|
|
}
|
|
});
|
|
let len = Object.keys( this.cfgs ).length;
|
|
if( rewards.length == 0 || rewards.length < len ){
|
|
nx.tbox( "CustomEmptyTip" );
|
|
return;
|
|
}
|
|
Mod.getInstance().reqSetGift( ( this.cate + 1 ), rewards, ( this.day + 1 ), 0 );
|
|
|
|
|
|
},
|
|
|
|
onTouchSure: function(){
|
|
|
|
let rewards = [];
|
|
let chd = this.nodRewards.children;
|
|
chd.forEach( _nod => {
|
|
if( _nod.active ){
|
|
let cmp = nx.gui.getComponent( _nod, "item", "cmp.item.base" );
|
|
if( cmp.mdata ){
|
|
rewards.push( {
|
|
item_id : cmp.mdata[0] || cmp.mdata.bid,
|
|
num : cmp.mdata[1] || cmp.mdata.num,
|
|
} )
|
|
}
|
|
|
|
}
|
|
});
|
|
let len = Object.keys( this.cfgs ).length;
|
|
if( rewards.length == 0 || rewards.length < len ){
|
|
nx.tbox( "CustomEmptyTip" );
|
|
return;
|
|
}
|
|
nx.mbox( nx.text.getKey( "CustomSaveTip" ), ["cancel","confirm"],(_key,_box)=>{
|
|
_box.close();
|
|
if(_key == "confirm"){
|
|
Mod.getInstance().reqSetGift( ( this.cate + 1 ), rewards, ( this.day + 1 ), 1 );
|
|
}
|
|
});
|
|
|
|
|
|
},
|
|
|
|
freshLeftCnt : function( _show ){
|
|
|
|
let nod = nx.gui.find( this.nodLeft, "info" );
|
|
if( nx.dt.objNEmpty( _show ) ){
|
|
nx.gui.setActive( this.nodLeft, "empty", false );
|
|
nx.gui.setActive( nod, "", true );
|
|
let cmp = nx.gui.getComponent( nod, "item", "cmp.item.base" );
|
|
if( cmp ){
|
|
cmp.setData( _show );
|
|
}
|
|
let count = BackpackController.getInstance().getModel().getItemNumByBid( _show.bid );
|
|
nx.gui.setString( nod, "have/txt", count );
|
|
let config = gitemdata( _show.bid );
|
|
nx.gui.setString( nod, "type/txt", config.type_desc );
|
|
return;
|
|
}
|
|
nx.gui.setActive( nod, "", false );
|
|
nx.gui.setActive( this.nodLeft, "empty", true );
|
|
|
|
|
|
},
|
|
|
|
});
|