/****************************************************************** * * 选择 僚机Egg 操作 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const ElfinController = require( "elfin_controller" ); const BackpackController = require( "backpack_controller" ); const ItemBase = require( "cmp.item.base" ); const ElfinEvent = require( "elfin_event" ); const TipsController = require( "tips_controller" ); cc.Class( { extends: BridgeWindow, properties: { nodWingEgg : { default : null, type : cc.Node, }, nodTimeDesc : { default : null, type : cc.Node, }, nodResultDesc : { default : null, type : cc.Node, }, nodBuy : { default : null, type : cc.Node, }, }, onLoad:function(){ this.bindGEvent( ElfinEvent.Buy_Elfin_Item_Success_Event, this.freshScientficInfo.bind( this) ); this.freshScientficInfo(); }, // 重载:参数打开 onOpenConfigs: function( _params ) { // console.log( "孵化数据" + JSON.stringify( _params ) ); this.pos = _params.hatch_id; }, freshScientficInfo : function(){ // 默认的显示 读取的是sprite_data表里的数据 let cfg = game.configs.sprite_data.data_hatch_egg; let chd = this.nodWingEgg.children; this.cfgs = []; nx.gui.setActive( this.nodResultDesc, "", false ); nx.gui.setActive( this.nodTimeDesc, "", false ); for (let i in cfg ) { let item = cfg[i]; // this.nodWingEgg[i].outFocus(); this.cfgs.push( item ); // this.nodWingEgg[i].setData( item.item_bid ); } this.cfgs.sort( Utils.tableLowerSorter( [ "item_bid" ] ) ) // let item for (let i = 0; i < this.cfgs.length; i++) { let item = this.cfgs[i]; let cmp = chd[i].getComponent( ItemBase ); if( cmp ){ cmp.outFocus(); cmp.setData( item.item_bid ); } } }, onTouchItem : function( _index ){ let chd = this.nodWingEgg.children; for (let i = 0; i < chd.length; i++) { let item = chd[i]; let cmp = item.getComponent( ItemBase ); if( cmp ){ if( _index == i ){ cmp.onFocus(); this.freshDesc( cmp.mdata ); }else{ cmp.outFocus(); } } } }, freshDesc : function( _item_bid ){ let cfg = game.configs.sprite_data.data_hatch_egg[_item_bid]; let rate = game.configs.sprite_data.data_const.hatch_rate.val; if( nx.dt.objNEmpty( cfg ) ){ let time = cfg.need_piont * rate; let h = Math.floor( time / 3600 ); let m = time % 60 ; nx.gui.setString( this.nodTimeDesc, "txt" , nx.text.format( "NeedTime", h , m ) ); nx.gui.setString( this.nodResultDesc, "txt" , cfg.desc ); nx.gui.setActive( this.nodResultDesc, "", true ); nx.gui.setActive( this.nodTimeDesc, "", true ); } nx.gui.setActive( this.nodBuy, "", cfg.can_buy > 0 ); this.item_id = _item_bid; }, onTouchSure: function(){ let EC = ElfinController.getInstance(); if( !this.item_id ){ nx.tbox( nx.text.getKey( "SelectOneWing" ) ); return; } if( EC ){ EC.sender26503( this.pos, this.item_id ); this.close(); } }, // 合成 onTouchMerge: function(){ let BC = BackpackController.getInstance(); if( BC ){ // 10601 let cfg = gdata( "item_data","data_unit1" , this.item_id ); let mat = game.configs.sprite_data.data_const.liaoji_materials.val[0]; let needCount = game.configs.sprite_data.data_const.liaoji_materials.val[1]; let all = BC.getModel().getBagItemList( 1 );// 获取对应背包类型的物品列表 this.data = {}; for (let i in all ) { let item = all[i]; if( item.base_id == mat ){ this.data = item; } } // console.log(mat + "物品数据当前显示" + JSON.stringify( this.data ) ); let count = BackpackController.getInstance().getModel().getItemNumByBid( mat ); if( count < needCount ){ let TC = TipsController.getInstance(); if( TC ) { nx.tbox( "tip_noEnoughMaterial" ); // TC.showItemTips( mat ); } return; } // console.log(this.item_id + "物品数据" + JSON.stringify( all ) ); ElfinController.getInstance().openElfinEggSyntheticPanel( true, mat ); // this.scheduleOnce( ()=> { // ElfinController.getInstance().openElfSelectItemWindow( false ); // }, 0.1 ); // BC.openItemMergePanel( true, this.data, BBC.BACKPACK ); } }, // 购买 onTouchBuy: function(){ if( !this.item_id ){ nx.tbox( nx.text.getKey( "SelectOneWing" ) ); return; } let EC = ElfinController.getInstance(); if( EC ){ let type = 1; EC.openBuyPanel( true, this.item_id, type, _data => { let EC = ElfinController.getInstance(); EC.sender26507( _data.type, _data.item_id, _data.num ); EC.openBuyPanel( false ); } ); // this.scheduleOnce( ()=> { // ElfinController.getInstance().openElfSelectItemWindow( false ); // }, 0.1 ); } } } );