/****************************************************************** * * 心愿伙伴选择 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const HeroConst = require( "hero_const" ); const HCT = HeroConst.CampType; cc.Class( { extends: BridgeWindow, properties: { pageGroup: { default: null, type: cc.Node }, }, // 重载:参数打开 onOpenConfigs: function( _params ) { this.raw_bid = _params.cur || 0; this.cur_bid = _params.cur || 0; this.camp_id = _params.camp_id; this.cbDone = _params.cb; const DATA = game.configs.recruit_holiday_lucky_data.data_wish[this.camp_id]; if( nx.dt.objEmpty( DATA ) ) { nx.error( "精英召唤心愿配置无效:", this.camp_id ); this.scheduleOnce( () => { this.close(); }, 0.01 ); } this.partners = []; for( let id in DATA ) { let cfgs = game.configs.partner_data.data_partner_base[id]; if( nx.dt.objEmpty( DATA[id] ) || nx.dt.objEmpty( cfgs ) ) { nx.error( "精英召唤心愿伙伴无效:", id ); continue; } this.partners.push( { bid: id, cfgs: cfgs, sort: DATA[id].sort, } ); this.partners.sort( ( _a, _b ) => { return _a.sort - _b.sort; } ); } // 伙伴重置 this.rebuildPartners(); }, // 伙伴重置 rebuildPartners: function() { // 单设 let reset = function( _node, _data ) { // 空缺 if( nx.dt.objEmpty( _data ) ) { nx.gui.setActive( _node, "", false ); return; } _node.partner = _data; nx.gui.setActive( _node, "", true ); nx.gui.setActive( _node, "focus", false ); let node = nx.gui.find( _node, "normal" ); // 阵营标记 let cfgs = _data.cfgs; let camp = cfgs ? cfgs.camp_type : HCT.eWater; let path = cc.path.join( "coms/images", "camps" + camp ); nx.gui.setSpriteFrame( node, "head/camp", path ); // 阵营背景 path = cc.path.join( "coms/camps", "bg" + camp ); nx.gui.setSpriteFrame( node, "bg", path ); // 阵营边框 path = cc.path.join( "coms/camps", "frame" + camp ); nx.gui.setSpriteFrame( node, "frame", path ); // 名字 nx.gui.setString( node, "dn/txt", nx.text.getKey( cfgs.name) ); // 星级 path = cc.path.join( "coms/images", "star" + cfgs.init_star ); nx.gui.setSpriteFrame( node, "dn/star", path ); // 角色 path = cc.path.join( "resDB/models", cfgs.draw_res, "half_show2" ); nx.gui.setSpriteFrame( node, "mask/img", path, ( _ret ) => { if( !_ret ) { nx.gui.setSpriteFrame( node, "mask/img", "resDB/empty/half_show2" ); } } ); }; // 遍历填充 let chds = this.pageGroup.children; for( let i = 0; i < chds.length; ++i ) { reset( chds[ i ], this.partners[ i ] ); } // 设置当前选中 this.setFocus( this.cur_bid || this.partners[0].bid ); }, // 设置当前选中 setFocus: function( _bid ) { this.cur_bid = _bid; let chds = this.pageGroup.children; for( let i = 0; i < chds.length; ++i ) { let node = chds[i]; nx.gui.setActive( node, "focus", this.cur_bid == node.partner.bid ); } }, // 点击更换 onTouchChange: function( _order ) { let order = parseInt( _order ); if( !nx.dt.numPositive( order, false ) ) { return; } let partner = this.partners[order-1]; if( partner ) { this.setFocus( partner.bid ); } }, // 点击确认 onTouchConfirm: function() { let bid = parseInt( this.cur_bid ); if( !nx.dt.numPositive( bid, false ) || this.raw_bid == bid ) { this.close(); return; } nx.dt.fnInvoke( this.cbDone, bid ); this.close(); }, } );