/****************************************************************** * * 水晶卡牌召喚 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const FxTogs = require( "nx.fx.togs" ); const FxSVC = require( "nx.fx.sv.expand" ); const HeroConst = require( "hero_const" ); const HeroEvent = require( "hero_event" ); const HeroControl = require( "hero_controller" ); const BackpackController = require( "backpack_controller" ) const TipsController = require( "tips_controller" ); const CRYModel = require( "summon.crystal.mod" ); const HCT = HeroConst.CampType; cc.Class( { extends: BridgeWindow, properties: { togCamp: { default: null, type: FxTogs }, svcList: { default: null, type: FxSVC }, nodFrom: { default: null, type: cc.Node }, nodTo: { default: null, type: cc.Node }, nodEmpty: { default: null, type: cc.Node }, nodReady: { default: null, type: cc.Node }, nodResult: { default: null, type: cc.Node }, lockResult: { default: null, type: cc.Node }, }, // 重载:参数打开 onOpenConfigs: function( _params ) { this.curCamp = -1; this.partners = []; this.partner = null; this.targetBid = 0; // 事件监听 this.bindGEvent( HeroEvent.Del_Hero_Event, this.onPartnerChanged.bind( this ) ); this.bindGEvent( HeroEvent.Hero_Data_Add, this.onPartnerChanged.bind( this ) ); // Tog监听 this.togCamp.posTog = this.onTogCamp.bind( this ); this.togCamp.togTo( 0 ); this.onTogCamp( HCT.eNone ); // 置空 this.setEmpty(); // 现场恢复 CRYModel.getInstance().reqSwapRecord( ( _ret, _data ) => { if( !_ret || !_data || !nx.dt.numPositive( _data.partner_id, false ) ) { return; } // 设置当前 for( let i = 0; i < this.partners.length; ++i ) { let pt = this.partners[ i ]; if( pt && pt.id == _data.partner_id ) { this.onFocusChanged( { index: i, mdata: pt, } ); this.setTarget( _data.new_partner_bid ); return; } } } ); }, // 重载:关闭前 onPreClosed: function() { this.svcList.rebuild( [] ); }, // 置空 setEmpty: function() { this.setPartner( null ); }, // 设置当前伙伴 setPartner: function( _partner ) { this.partner = _partner; this.setTarget( 0 ); // 置空 if( !this.partner ) { this.svcList.cleanFocus(); let spine = nx.gui.getComponent( this.nodFrom, "smod", "nx.fx.spine" ); if( spine ) { spine.stop(); } nx.gui.setActive( this.nodFrom, "smod", false ); nx.gui.setActive( this.nodFrom, "infos", false ); return; } // 模型 let key = this.partner.bid + "_" + this.partner.star; let cfg = gdata( "partner_data", "data_partner_star", key ) let spine = nx.gui.getComponent( this.nodFrom, "smod", "nx.fx.spine" ); if( cfg && spine ) { let path = PathTool.getSpinePath( cfg.res_id, cfg.res_id, false ); spine.load( path, ( _e ) => { if( !_e ) { spine.action( "stand2", true ); } else { spine.stop(); } } ); } nx.gui.setActive( this.nodFrom, "smod", true ); // 信息 let infos = nx.gui.setActive( this.nodFrom, "infos", true ); let sf = cc.path.join( "coms/images/camps" + this.partner.camp_type ); nx.gui.setSpriteFrame( infos, "camp", sf ); nx.gui.setString( infos, "lv", "Lv." + this.partner.lev ); nx.gui.setString( infos, "name", nx.text.getKey( this.partner.name ) ); let st = cc.path.join( "coms/images", "star" + this.partner.star ); nx.gui.setSpriteFrame( infos, "star", st ); }, // 更新目标 setTarget: function( _bid ) { this.targetBid = _bid; this.freshOps(); // 置空 if( !nx.dt.numPositive( this.targetBid, false ) ) { // 模型 nx.gui.setActive( this.nodTo, "empty", true ); nx.gui.setActive( this.nodTo, "smod", false ); let spine = nx.gui.getComponent( this.nodTo, "smod", "nx.fx.spine" ); if( spine ) { spine.stop(); } if( !this.partner ) { nx.gui.setActive( this.nodTo, "infos", false ); } else { // 信息 let infos = nx.gui.setActive( this.nodTo, "infos", true ); let sf = cc.path.join( "coms/images/camps" + this.partner.camp_type ); nx.gui.setSpriteFrame( infos, "camp", sf ); nx.gui.setString( infos, "lv", "Lv." + this.partner.lev ); nx.gui.setString( infos, "name", nx.text.getKey( "????" ) ); let st = cc.path.join( "coms/images", "star" + this.partner.star ); nx.gui.setSpriteFrame( infos, "star", st ); } return; } // 模型 nx.gui.setActive( this.nodTo, "empty", false ); nx.gui.setActive( this.nodTo, "smod", true ); let key = this.targetBid + "_" + this.partner.star; let cfg = gdata( "partner_data", "data_partner_star", key ) let spine = nx.gui.getComponent( this.nodTo, "smod", "nx.fx.spine" ); if( cfg && spine ) { let path = PathTool.getSpinePath( cfg.res_id, cfg.res_id, false ); spine.load( path, ( _e ) => { if( !_e ) { spine.action( "stand2", true ); } else { spine.stop(); } } ); } // 名字 let infos = nx.gui.setActive( this.nodTo, "infos", true ); let base = game.configs.partner_data.data_partner_base[this.targetBid]; nx.gui.setString( infos, "name", nx.text.getKey( base ? base.name : "" ) ); // 特效 let spine2 = nx.gui.getComponent( this.nodTo, "show", "nx.fx.spine" ); if( spine2 ) { let spine_path = PathTool.getSpinePath( "E80009", "action", false ); spine2.play( spine_path, "action1_blue", () => { }, false ); } }, // 整体刷新 freshList: function( _reset = false ) { let HC = HeroControl.getInstance(); let mod = HC.getModel(); // 符合条件判断 let camp = this.curCamp; let good = function( _hero ) { // 4,5星过滤 if( !_hero || _hero.is_in_form > 0 || _hero.star < 4 || _hero.star > 5 ) { return false; } // 全阵营(除光暗) if( camp == HCT.eNone ) { if( _hero.camp_type != HCT.eLight && _hero.camp_type != HCT.eDark ) { return true; } return false; } return camp == _hero.camp_type; }; // 阵营伙伴统计 this.partners = []; let heros = mod.getHeroList(); for( let id in heros ) { let hero = heros[ id ]; if( good( hero ) ) { this.partners.push( hero ); } } // 排序 this.partners.sort( ( _a, _b ) => { return _b.star - _a.star; } ); this.svcList.rebuild( this.partners ); this.setPartner( null ); }, // 伙伴增删 onPartnerChanged: function() { // console.log( "刷新伙伴信息" ); this.setEmpty(); this.freshList( true ); }, // 阵营切换 onTogCamp: function( _index ) { let idx = parseInt( _index ) || 0; if( this.curCamp == idx ) { return; } nx.debug( `[Hero]阵营切换:${ this.curCamp } -> ${ idx }` ); this.curCamp = idx; // 整体刷新 this.freshList(); }, // 选中切换 onFocusChanged: function( _item ) { // 空 if( nx.dt.objEmpty( _item ) || nx.dt.objEmpty( _item.mdata ) ) { return; } nx.audio.playSFX( "audios/effects/touchitem" ); // 聚焦 this.svcList.cleanFocus(); this.svcList.addFocus( _item.index ); this.setPartner( _item.mdata ); }, // ------------------------------------------------------- // 操作相关 // ------------------------------------------------------- // 操作更新 freshOps: function() { // 空 if( !this.partner ) { this.nodEmpty.active = true; this.nodReady.active = false; this.nodResult.active = false; this.lockResult.active = false; return; } // 准备 if( this.partner && !nx.dt.numPositive( this.targetBid, false ) ) { this.nodEmpty.active = false; this.nodResult.active = false; this.lockResult.active = false; this.nodReady.active = true; // 花费 const DATA = game.configs.recruit_high_data.data_seerpalace_const; let key = "hero_change" + this.partner.star; let val = DATA[ key ].val[0]; nx.bridge.setIconS( this.nodReady, "cost/icon", val[ 0 ] ); nx.gui.setString( this.nodReady, "cost/txt", val[ 1 ] ); const BC = BackpackController.getInstance(); let have = BC.getModel().getItemNumByBid( val[ 0 ] ); let btn = nx.gui.getComponent( this.nodReady, "convert", "nx.fx.button" ); btn.lock( have < val[ 1 ] ); return; } // 保存确认 this.nodEmpty.active = false; this.nodReady.active = false; this.nodResult.active = true; this.lockResult.active = true; }, // 点击置换 onTouchConvert: function() { if( !this.partner ) { return; } let CRY = CRYModel.getInstance(); CRY.reqSwap( this.partner.id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } this.setTarget( _data.new_partner_bid ); this.freshOps(); } ); }, // 点击取消 onTouchCancel: function() { if( !this.partner ) { return; } let CRY = CRYModel.getInstance(); CRY.reqSwapCancel( this.partner.id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } this.setPartner( this.partner ); } ); }, // 点击保存 onTouchSave: function() { if( !this.partner ) { return; } let CRY = CRYModel.getInstance(); CRY.reqSwapSave( this.partner.id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } this.setPartner( null ); } ); }, // 点击保存锁定区 onTouchLockArea: function() { nx.tbox( "转换保存提醒" ); }, // 点击帮助 onTouchHelp: function() { let TC = TipsController.getInstance(); if( TC ) { const DATA = game.configs.recruit_high_data.data_seerpalace_const; let txt = DATA.game_rule2.desc; TC.showTextPanel( "tip", nx.text.getKey( txt ) ); } }, } );