/****************************************************************** * * 礼包选择界面 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const FxSVC = require( "nx.fx.sv.expand" ); const BackPackConst = require( "backpack_const" ); const BackPackController = require( "backpack_controller" ); const FxTogs = require( "nx.fx.togs" ); const HeroConst = require( "hero_const" ); const HeroEvent = require( "hero_event" ); const HeroControl = require( "hero_controller" ); const HEHY = HeroConst.HolyequipmentPosList; const HolyTitle = HeroConst.HolyTitle; const BBC = BackPackConst.Bag_Code; const BIT = BackPackConst.item_type; const BITT = BackPackConst.item_sub_type; cc.Class( { extends: BridgeWindow, properties: { svcList: { default: null, type: FxSVC, }, nodPartner: { default: null, type: cc.Node, }, nodHoly: { default: null, type: cc.Node, }, nodSortStar: { default: null, type: cc.Node, }, nodSortSet: { default: null, type: cc.Node, }, nodSuitDes: { default: null, type: cc.Node, } }, onLoad : function(){ let tmp = nx.gui.getComponent( this.nodSortStar, "lst/view/content", FxTogs ); let tmp1 = nx.gui.getComponent( this.nodSortSet, "lst/view/content", FxTogs ); this.set = 0; this.star = 0; tmp.posTog = this.onTogMenu.bind( this ); tmp1.posTog = this.onTogMenu1.bind( this ); this.bindGEvent( HeroEvent.Holy_Equipment_Update_Event, this.onHolyUpdate.bind( this ) ); }, // 重载:参数打开 onOpenConfigs: function( _params ) { this.holyLst = _params.holyLst; nx.gui.setActive( this.nodSortStar, "lst", false ); nx.gui.setActive( this.nodSortSet, "lst", false ); this.etype = _params.etype; this.partner = _params.partner; this.cb = _params.cb; this.cboff = _params.cboff; this.planid = _params.planid || 0; // console.log( this.etype + "当前的类型—神装数据" + JSON.stringify( this.holyLst ) ); let cmp = this.nodPartner.getComponent( "cmp.item.base" ); if( cmp ){ cmp.setData( this.partner ); } let count = Object.keys( HolyTitle ).length; let cfgss = nx.dt.objClone( game.configs.partner_holy_eqm_data.data_suit_res_prefix ) ; cfgss[0] = {"id":0,"name":"AllSets","prefix":"AllSets"}; let count_set = game.configs.partner_holy_eqm_data.data_suit_res_prefix_length; nx.gui.gocChildren( this.nodSortStar, "lst/view/content", count ); nx.gui.gocChildren( this.nodSortSet, "lst/view/content", count_set + 1 ); let nods = nx.gui.find( this.nodSortStar, "lst/view/content" ).children; let nodset = nx.gui.find( this.nodSortSet, "lst/view/content" ).children; for (let i in HolyTitle ) { let item = HolyTitle[i]; let node = nods[i]; nx.gui.setString( node, "on/txt", nx.text.getKey( item ) ); nx.gui.setString( node, "off/txt", nx.text.getKey( item ) ); } for (let d in cfgss ) { let item = cfgss[d]; let node = nodset[d]; nx.gui.setString( node, "on/txt", nx.text.getKey( item.prefix ) ); nx.gui.setString( node, "off/txt", nx.text.getKey( item.prefix ) ); } this.onTouchSlot( this.etype ); }, onTouchSortStar: function(){ nx.gui.setActive( this.nodSortStar, "lst", !nx.gui.find( this.nodSortStar, "lst" ).active ); nx.gui.setActive( this.nodSortSet, "lst", false ); let dpath = cc.path.join( "prefab/partner/holy/ui", "partner_94" ); let upath = cc.path.join( "prefab/partner/holy/ui", "partner_95" ); nx.gui.setSpriteFrame( this.nodSortStar, "bg/op/bg", nx.gui.find( this.nodSortStar, "lst" ).active ? upath : dpath ); }, onTouchSortSet: function(){ nx.gui.setActive( this.nodSortStar, "lst", false ); nx.gui.setActive( this.nodSortSet, "lst", !nx.gui.find( this.nodSortSet, "lst" ).active ); let dpath = cc.path.join( "prefab/partner/holy/ui", "partner_94" ); let upath = cc.path.join( "prefab/partner/holy/ui", "partner_95" ); nx.gui.setSpriteFrame( this.nodSortSet, "bg/op/bg", nx.gui.find( this.nodSortSet, "lst" ).active ? upath : dpath ); }, onTouchSlot: function( _index ){ this.nowSelect = _index; let num = parseInt( _index ); // 空处理 let slots = this.nodHoly; this.onHolyUpdate(); for ( let pos in HEHY ) { // 当前装备 let slot = nx.gui.find( slots, "slot" + pos ); let cmp = nx.gui.getComponent( slot, "", "cmp.item.base" ); if( pos == num ){ if( cmp ) { cmp.onFocus(); // console.log( "当前的数据ssss" + JSON.stringify( cmp.mdata ) ); if( cmp.mdata && !nx.dt.objEmpty( cmp.mdata ) ){ nx.gui.setActive( slot, "off", true ); }else{ nx.gui.setActive( slot, "off", false ) } } }else{ if( cmp ) { cmp.outFocus(); } } } this.freshLst( num ); }, freshLst: function( _type ){ const BC = BackPackController.getInstance(); const model = BC.getModel(); // 统计该类型装备列表 let eqms = []; let list = {}; if( _type == BIT.GOD_EARRING || _type == BIT.GOD_RING || _type == BIT.GOD_NECKLACE || _type == BIT.GOD_BANGLE ){ list = model.getAllBackPackArray( BITT.HOLYEQUIPMENT ) || {}; } // 统计匹配项 for( let i in list ) { let eqm = list[ i ]; if( eqm && eqm.config && eqm.config.type == _type ) { eqms.push( eqm ); } } // console.log( "当前的holy数据" + JSON.stringify( eqms ) ); let empty = nx.dt.arrEmpty( eqms ); // 刷新 nx.gui.setActive( this.svcList, "empty", empty ); // this.svcList.rebuild( eqms ); this.svcList.binder = this; let tmp2 = nx.gui.getComponent( this.nodSortSet, "lst/view/content", FxTogs ); tmp2.rebuildTogs(); tmp2._freshTogShow(); tmp2.togTo( this.set || 0 ); this.onTogMenu1( this.set || 0 ); let tmp = nx.gui.getComponent( this.nodSortStar, "lst/view/content", FxTogs ); tmp.rebuildTogs(); tmp._freshTogShow(); tmp.togTo( this.star || 0 ); this.onTogMenu( this.star || 0 ); // if( this.set >= 0 || this.star >= 0 ){ // console.log( this.star + "套裝" + this.set ); // this.dealShow( this.star, this.set ); // } // 引导辅助 if( nx.bridge.plot && nx.bridge.plot.isDoing() ) { this.positionWear(); } }, onHolyUpdate: function(){ const HC = HeroControl.getInstance(); let slots = this.nodHoly; let holy_eqm_list = {}; if( this.planid.id > 0 ){ let allPlan = HC.getModel().getHolyEquipmentPlanData(); let pland = []; for (let i in allPlan ) { let plan = allPlan[i]; if( plan.id == this.planid.id ){ pland = plan.list; } } this.holyLst = pland; // console.log( JSON.stringify( pland ) + "更换后的数据显示为" ); }else{ let holyLst = []; let eqms = HC.getModel().getHeroHolyEquipList( this.partner.partner_id ); for (let i in eqms ) { let eqm = eqms[i]; holyLst.push( { partner_id: this.partner.partner_id, item_id : eqm.id, } ) } this.holyLst = holyLst; } holy_eqm_list = this.getAllHolyLst( this.holyLst ); // console.log( "当前的装备数据----->>>>>" + JSON.stringify( holy_eqm_list ) ); let empty = function( _sc = false ) { // 卡槽置空 slots.children.forEach( _c => { nx.gui.setActive( _c, "empty", true ); nx.gui.setActive( _c, "focus", false ); nx.gui.setActive( _c, "off", false ); } ); }; // 判空 if( nx.dt.objEmpty( this.partner ) && this.partner != 0 ) { empty( true ); return; } for ( let pos in HEHY ) { let eqm = holy_eqm_list[pos]; // 当前装备 let emt = nx.dt.objEmpty( eqm ); let slot = nx.gui.find( slots, "slot" + pos ); nx.gui.setActive( slot, "off", !emt ); nx.gui.setActive( slot, "empty", emt ); let cmp = nx.gui.getComponent( slot, "", "cmp.item.base" ); if( !emt ) { if( cmp ) { cmp.setData( eqm ); } }else{ cmp.setData( null ); } } let lst = HeroControl.getInstance().getModel().getHolyEquipSuitDes( holy_eqm_list ); nx.gui.setActive( this.nodSuitDes, "", !nx.dt.arrEmpty( lst ) ); if( !nx.dt.arrEmpty( lst ) ){ let nod = this.nodSuitDes; for (let i = 0; i < nod.children.length; i++) { let des = lst[i]; if( des ){ nx.gui.setString( nod.children[i], "", des.name ); }else{ nx.gui.setString( nod.children[i], "", "" ); } } } }, getAllHolyLst: function( _list ){ if (!_list) { return }; if ( _list.length == 0 ) { return {} }; let holy_list = {} //神装数据 for ( const k in _list) { const v = _list[k]; if (v.item_id) { let item_vo = {}; if (v.partner_id == 0) { //在装备背包中 item_vo = BackPackController.getInstance().getModel().getBagItemById(BackPackConst.Bag_Code.EQUIPS, v.item_id); } else { //英雄已穿戴 item_vo = HeroControl.getInstance().getModel().getHolyEquipById(v.item_id); } if (item_vo && item_vo.config) { holy_list[item_vo.config.type] = item_vo; } } } return holy_list; }, // 选中装备 onEquip: function( _item ) { const HC = HeroControl.getInstance(); if( _item && nx.dt.numPositive( _item.id, false ) ) { if( this.planid != 0 ){ data = { eqm : _item.id, partner: this.partner, mdata : this.planid, type: this.etype, } nx.dt.fnInvoke( this.cb, data, this ); }else{ nx.dt.fnInvoke( this.cb, _item.id, this ); } this.scheduleOnce( ()=> { this.onTouchSlot( this.nowSelect ); },0.3 ); } }, // 选中装备 onEquipOff: function( _index ) { let slots = this.nodHoly; let eqm = {}; const HC = HeroControl.getInstance(); for ( let pos in HEHY ) { // 当前装备 let slot = nx.gui.find( slots, "slot" + pos ); let cmp = nx.gui.getComponent( slot, "", "cmp.item.base" ); if( pos == _index ){ if( cmp ){ eqm = cmp.mdata; } } } let data ={}; if( this.planid != 0 ){ data = { eqm : eqm.id, partner: this.partner, mdata : this.planid, } }else{ data = { eqm : eqm.id, partner: this.partner, } } nx.dt.fnInvoke( this.cboff, data, this ); this.scheduleOnce( ()=> { this.onTouchSlot( this.nowSelect ); },0.3 ); }, onTogMenu: function( _index ) { this.unscheduleAllCallbacks(); this.star = _index; // console.log( "当前选择相关" + _index ); let nods = nx.gui.find( this.nodSortStar, "lst/view/content" ).children; let nod = nods[_index]; let txt = nx.gui.getComponent( nod, "on/txt", cc.Label ); if( txt ){ nx.gui.setString( this.nodSortStar, "bg/txt", txt.string ); } this.dealShow( this.star, this.set ); }, onTogMenu1: function( _index ) { // console.log( "当前选择相关2" + _index ); this.set = _index; let nods = nx.gui.find( this.nodSortSet, "lst/view/content" ).children; let nod = nods[_index]; let txt = nx.gui.getComponent( nod, "on/txt", cc.Label ); if( txt ){ nx.gui.setString( this.nodSortSet, "bg/txt", txt.string ); } this.dealShow( this.star, this.set ); }, dealShow: function( _star, _set ){ let BC = BackPackController.getInstance(); let model = BC.getModel(); let list = {}; if( this.nowSelect == BIT.GOD_EARRING || this.nowSelect == BIT.GOD_RING || this.nowSelect == BIT.GOD_NECKLACE || this.nowSelect == BIT.GOD_BANGLE ){ list = model.getAllBackPackArray( BITT.HOLYEQUIPMENT ) || {}; } let show = []; let eqms = []; // 统计匹配项 for( let i in list ) { let eqm = list[ i ]; if( eqm && eqm.config && eqm.config.type == this.nowSelect ) { eqms.push( eqm ); } } eqms.forEach( _eqm =>{ if( _star != 0 ){ if( _set != 0 ){ if( _eqm.config.eqm_star == _star && parseInt( _eqm.config.eqm_set / 100 ) == ( this.set ) ){ show.push( _eqm ); } // nx.gui.setActive( item, "", cmp.mdata.config.eqm_star == _star && parseInt( cmp.mdata.config.eqm_set / 100 ) == ( this.set ) ); }else{ if( _eqm.config.eqm_star == _star ){ show.push( _eqm ); } } }else{ if( _set != 0 ){ if( parseInt(Math.floor( _eqm.config.eqm_set / 100 ) ) == ( this.set ) ){ show.push( _eqm ); } }else{ show.push( _eqm ); } } } ); show.sort( Utils.tableUpperSorter(["all_score"]) ); this.svcList.rebuild( show ); }, /**** * 引导 ------- */ // 定位最弱的一个 positionWear: function() { let node = null; let chd = nx.gui.find( this.svcList.bindSCV, "view/content" ); if( chd ){ let nodes = chd.children; node = nodes[ 0 ]; if( !node ) { nx.error( "$ParterPage:定位特定英雄失败!" ); node = chd[ 0 ]; if( !node ) { return; } } let cell = nx.gui.find( this, "plotd" ); let pos = node.convertToWorldSpaceAR( cc.Vec2.ZERO ); cell.position = cell.parent.convertToNodeSpaceAR( pos ); cell.width = node.width; cell.height = node.height; cell.svItem = node.svItem; cell.mdata = node.svItem.mdata; cell.index = node.svItem.index; nx.gui.setActive( this, "plotd", true ); } }, onTouchSelf : function( _nod ){ let nod = nx.gui.find( this, "plotd" ); if( nod ){ nod.svItem.onTouchEquip(); } }, } );