321 lines
9.5 KiB
JavaScript
321 lines
9.5 KiB
JavaScript
|
|
// const ActPage = require( "act.page.base" );
|
||
|
|
const ActPopup = require( "act.popup.base" );
|
||
|
|
const TipsController = require( "tips_controller" );
|
||
|
|
const mod = require( "act.optionalgift.mod" );
|
||
|
|
const FID = require( "bridge.function.ids" );
|
||
|
|
const themeMod = require( "acts.mod" );
|
||
|
|
const Payment = require( "payment.mod" );
|
||
|
|
const NxExpand = require( "nx.fx.sv.expand" );
|
||
|
|
|
||
|
|
cc.Class({
|
||
|
|
|
||
|
|
extends: ActPopup,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
|
||
|
|
nodCnt: { type: cc.Node, default : null },
|
||
|
|
nodShow : { type: cc.Node, default : null },
|
||
|
|
},
|
||
|
|
|
||
|
|
// build: function( _params ){
|
||
|
|
// },
|
||
|
|
|
||
|
|
onLoad:function(){
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onOpenConfigs(_params){
|
||
|
|
this._super( _params );
|
||
|
|
|
||
|
|
this.mod = mod.getInstance();
|
||
|
|
if( !this.mod || !this.mod.data ){
|
||
|
|
this.delayClose();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
let chargefg = gdata( this.mod.data.config, "data_const" ).charge_id;
|
||
|
|
|
||
|
|
let charge_id = 0;
|
||
|
|
if( chargefg ){
|
||
|
|
charge_id = chargefg.val;
|
||
|
|
}
|
||
|
|
this.charge_id = charge_id;
|
||
|
|
let price = game.configs.charge_data.data_charge_data[charge_id].val;
|
||
|
|
nx.gui.setString( this.nodCnt, "op/price", Payment.getInstance().fmtPrice( price ) + " " + nx.text.getKey( "Buy" ) );
|
||
|
|
|
||
|
|
// 活动监听
|
||
|
|
this.mod.vbind( this, [
|
||
|
|
[ "optionalGift", this.freshInfo.bind( this ) ],
|
||
|
|
[ "optionalGiftSaveBack", this.dealShow.bind( this ) ]
|
||
|
|
|
||
|
|
] );
|
||
|
|
this.mod.reqOptionalGift();
|
||
|
|
},
|
||
|
|
|
||
|
|
onEnable: function(){
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 销毁
|
||
|
|
onDestroy: function() {
|
||
|
|
|
||
|
|
// 活动监听解除
|
||
|
|
if( this.mod ) {
|
||
|
|
this.mod.vunbind( this );
|
||
|
|
}
|
||
|
|
delete this.mod;
|
||
|
|
this._super();
|
||
|
|
},
|
||
|
|
|
||
|
|
freshInfo: function( _data ){
|
||
|
|
|
||
|
|
this.selects = [];
|
||
|
|
if( _data ){
|
||
|
|
let chd = nx.gui.find( this.nodCnt, "choice" ).children;
|
||
|
|
let rewards = _data.reward;
|
||
|
|
for (let r = 0; r < rewards.length; r++ ) {
|
||
|
|
|
||
|
|
let reward = rewards[r];
|
||
|
|
let shows = [];
|
||
|
|
let show = {
|
||
|
|
bid : reward.item_list[0].item_id,
|
||
|
|
num : reward.item_list[0].num,
|
||
|
|
}
|
||
|
|
let nod = chd[reward.id - 1];
|
||
|
|
if( reward.id == 1 || reward.id == 2 ){
|
||
|
|
this.selects.push( {
|
||
|
|
id : reward.id,
|
||
|
|
bid : reward.item_list[0].item_id
|
||
|
|
} );
|
||
|
|
}
|
||
|
|
shows.push( show );
|
||
|
|
|
||
|
|
let cmp = nx.gui.getComponent( nod, "item", "cmp.common.itemlayout" );
|
||
|
|
if( cmp ){
|
||
|
|
cmp.rebuild( shows );
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/*****
|
||
|
|
*{"reward":[
|
||
|
|
{"id":0,"item_list":[{"item_id":0,"num":2000},{"item_id":10001,"num":0}]},
|
||
|
|
{"id":3,"item_list":[{"item_id":14001,"num":5}]}
|
||
|
|
**]}
|
||
|
|
****/
|
||
|
|
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onTouchAdd: function( _idx ){
|
||
|
|
|
||
|
|
let show_list = gdata( this.mod.data.config, "data_optional_reward" )[_idx];
|
||
|
|
let rewards = [];
|
||
|
|
for (let i in show_list ) {
|
||
|
|
let item = show_list[i].reward;
|
||
|
|
let showid = parseInt( i );
|
||
|
|
|
||
|
|
rewards.push( item );
|
||
|
|
}
|
||
|
|
this.id = _idx;
|
||
|
|
let nowSelect = [];
|
||
|
|
let num = parseInt( _idx );
|
||
|
|
let rrnod = nx.gui.find( this.nodCnt, "choice" ).children[ num - 1 ];
|
||
|
|
let rnod = nx.gui.find( rrnod, "item" );
|
||
|
|
if( rnod.children.length > 0 ){
|
||
|
|
for (let i = 0; i < rnod.children.length; i++) {
|
||
|
|
let nodd = rnod.children[i];
|
||
|
|
let ncmp = nodd.getComponent( "cmp.act.optionalgift.item" );
|
||
|
|
if( ncmp ){
|
||
|
|
nowSelect.push( ncmp.mdata.bid );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.setShow( rewards, nowSelect );
|
||
|
|
},
|
||
|
|
|
||
|
|
setShow: function( _rewards, _nowselect ){
|
||
|
|
|
||
|
|
let cmp = nx.gui.getComponent( this.nodShow, "rewards", NxExpand );
|
||
|
|
if( cmp ){
|
||
|
|
cmp.rebuild( _rewards );
|
||
|
|
}
|
||
|
|
let selectss = [];
|
||
|
|
this.selects.forEach( _sel =>{
|
||
|
|
if( _sel.id != this.id ){
|
||
|
|
selectss.push( _sel.bid );
|
||
|
|
}
|
||
|
|
} )
|
||
|
|
this.dealShowItem( _nowselect, selectss );
|
||
|
|
},
|
||
|
|
|
||
|
|
dealShowItem: function( _select, _selectssss ){
|
||
|
|
|
||
|
|
let chd = nx.gui.find( this.nodShow, "rewards/list/view/content" ).children;
|
||
|
|
this.choice = {};
|
||
|
|
this.already = [];
|
||
|
|
// 已选择的 组为非空
|
||
|
|
if( nx.dt.arrNEmpty( _selectssss ) ){
|
||
|
|
|
||
|
|
for ( let i = 0; i < chd.length; i++ ) {
|
||
|
|
let nod = chd[i].svItem;
|
||
|
|
|
||
|
|
if( nod ){
|
||
|
|
nod.setCannotSelect( false );
|
||
|
|
let now = _select[0];
|
||
|
|
if( now ){
|
||
|
|
if( nod.info.item_id == now ){
|
||
|
|
nod.onFocus();
|
||
|
|
nod.setCannotSelect( false );
|
||
|
|
// _selectssss.splice( ( _selectssss.indexOf( now ) ), 1 ) ;
|
||
|
|
// this.already.push[now];
|
||
|
|
}else{
|
||
|
|
|
||
|
|
nod.setCannotSelect( false );
|
||
|
|
for (let s = 0; s < _selectssss.length; s++) {
|
||
|
|
let selectItem = _selectssss[s];
|
||
|
|
if( nod.info.item_id == selectItem ){
|
||
|
|
nod.setCannotSelect( true );
|
||
|
|
nod.outFocus();
|
||
|
|
}else{
|
||
|
|
nod.setCannotSelect( false );
|
||
|
|
nod.outFocus();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
for (let s = 0; s < _selectssss.length; s++) {
|
||
|
|
let selectItem = _selectssss[s];
|
||
|
|
if( nod.info.item_id == selectItem ){
|
||
|
|
nod.setCannotSelect( true );
|
||
|
|
|
||
|
|
}else{
|
||
|
|
nod.setCannotSelect( false );
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}else{
|
||
|
|
nod.setCannotSelect( false );
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}else{
|
||
|
|
// 当第二个槽位 没有选择道具
|
||
|
|
for ( let i = 0; i < chd.length; i++ ) {
|
||
|
|
let nod = chd[i].svItem;
|
||
|
|
|
||
|
|
if( nod ){
|
||
|
|
nod.setCannotSelect( false );
|
||
|
|
let now = _select[0];
|
||
|
|
if( now ){
|
||
|
|
if( nod.info.item_id == now ){
|
||
|
|
nod.onFocus();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
nx.gui.setActive( this.nodShow, "", true );
|
||
|
|
},
|
||
|
|
|
||
|
|
onTouchSelect: function( _item ){
|
||
|
|
let chd = nx.gui.find( this.nodShow, "rewards/list/view/content" ).children;
|
||
|
|
if( _item.mdata.canshow == 1 ){
|
||
|
|
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.choice = [];
|
||
|
|
this.selectsNow = [];
|
||
|
|
for ( let i = 0; i < chd.length; i++ ) {
|
||
|
|
let nod = chd[i].svItem;
|
||
|
|
this.selectsNow.push( nod );
|
||
|
|
if( nod ){
|
||
|
|
nod.outFocus();
|
||
|
|
|
||
|
|
if( nod.index == _item.index ){
|
||
|
|
nod.onFocus();
|
||
|
|
this.selectsNow.push( nod );
|
||
|
|
this.choice = nod.mdata;
|
||
|
|
}else{
|
||
|
|
nod.outFocus();
|
||
|
|
if( nx.dt.arrMember( this.selectsNow, nod ) ){
|
||
|
|
this.selectsNow.splice( this.selectsNow.indexOf( nod ), 1 );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
dealShow: function( _code ){
|
||
|
|
if( !_code ){
|
||
|
|
nx.gui.setActive( this.nodShow, "", false );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
nx.gui.setActive( this.nodShow, "", _code == 0 );
|
||
|
|
},
|
||
|
|
|
||
|
|
closeShow: function(){
|
||
|
|
|
||
|
|
nx.gui.setActive( this.nodShow, "", false );
|
||
|
|
},
|
||
|
|
|
||
|
|
onTouchSave: function( ){
|
||
|
|
|
||
|
|
if( nx.dt.arrEmpty( this.choice ) ){
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
// for (let i = 0; i < this.choice.length; i++) {
|
||
|
|
// let item = this.choice[i];
|
||
|
|
// if( item == 0 ){
|
||
|
|
// return;
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
let pusInfo = [];
|
||
|
|
let item = [];
|
||
|
|
let id = {
|
||
|
|
id : parseInt( this.id )
|
||
|
|
};
|
||
|
|
pusInfo.push( id );
|
||
|
|
let idd = {
|
||
|
|
item_id : this.choice[0],
|
||
|
|
num : this.choice[1],
|
||
|
|
}
|
||
|
|
item.push( idd );
|
||
|
|
this.mod.reqOptionalSelect( parseInt( this.id ), item );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onTouchBuy: function( _idx ){
|
||
|
|
|
||
|
|
let chd = nx.gui.find( this.nodCnt, "choice" ).children;
|
||
|
|
let num = 0;
|
||
|
|
for (let i = 0; i < chd.length; i++) {
|
||
|
|
let nod = nx.gui.find( chd[i], "item");
|
||
|
|
if( nod.children.length == 0 ){
|
||
|
|
num++;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
if( num > 0 ){
|
||
|
|
nx.tbox( "ActGiftSelectTips" );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
Payment.getInstance().reqPayment( this.charge_id );
|
||
|
|
nx.bridge.closePanel( "WndActCustomGift" );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
});
|