/****************************************************************** * * 伙伴换肤界面 * ******************************************************************/ const BridgeComponent = require( "bridge.component" ); const NxSpine = require( "nx.fx.spine" ); const HeroController = require( "hero_controller" ); const TipsController = require( "tips_controller" ); cc.Class( { extends: BridgeComponent, properties: { spMini: { default: null, type: NxSpine }, spRole: { default: null, type: NxSpine }, nodName: { default: null, type: cc.Node }, rootAttrs: { default: null, type: cc.Node }, attrPersons: { default: null, type: cc.Node }, attrTeam: { default: null, type: cc.Node }, lstSkin: { default: null, type: cc.Node }, nodOps: { default: null, type: cc.Node }, }, // 设置伙伴 setPartner: function( _partner, _cbChanged ) { // 置空 if( !_partner ) { this.spRole.stop(); this.spMini.stop(); return; } this.partner = _partner; this.preskin = _partner.use_skin; this.cbskin = _cbChanged; this.scheduleOnce( () => { this.rebuildList(); this.setSkin( 0 ); }, 0.05 ); }, // 重建 rebuildList: function() { let SkinData = game.configs.partner_skin_data.data_skin_info; let SkinPartners = game.configs.partner_skin_data.data_partner_bid_info; let skins = SkinPartners[ this.partner.bid ]; this.skins = []; for( let id in skins ) { let info = SkinData[ id ]; this.skins.push( nx.dt.objClone( info ) ); } // 列表重构 let chds = this.lstSkin.children; nx.gui.gocChildren( this.lstSkin, "", this.skins.length, chds[ 0 ] ); for( let i = 0; i < this.skins.length; ++i ) { let cmp = nx.gui.getComponent( chds[ i ], "", "cmp.partner.skin.item" ); cmp.setSkin( i, this.skins[ i ] ); } }, // 聚焦皮肤 setSkin: function( _index ) { let index = _index; if( this.current == index ) { return; } let chds = this.lstSkin.children; for( let i = 0; i < chds.length; ++i ) { let cmp = nx.gui.getComponent( chds[ i ], "", "cmp.partner.skin.item" ); cmp.setFocus( i == index ); } this.current = index; this.currentShow( this.skins[ index ] ); this.freshShows(); }, // 当前展示 currentShow: function( _skin ) { // 如果为空,则还原 if( nx.dt.objEmpty( _skin ) ) { this.current = -1; let key = this.partner.bid + "_" + this.partner.star; let cfg = gdata( "partner_data", "data_partner_star", key ); _skin = { res_id: cfg.res_id, skin_name: "SkinRaw", skin_attr: [], } } // 立绘 let path = PathTool.getSpinePath( _skin.res_id, "show", false ); this.spRole.load( path, ( _e ) => { if( !_e ) { this.spRole.action( "action1", true ); } else { this.spRole.stop(); } } ); // 战斗迷你 path = PathTool.getSpinePath( _skin.res_id, _skin.res_id, false ); this.spMini.load( path, ( _e ) => { if( !_e ) { this.spMini.action( "stand2", true ); } else { this.spMini.stop(); } } ); // 名字 nx.gui.setString( this.nodName, "txt", nx.text.getKey( _skin.skin_name ) ); // 个人属性加成 let attrs = _skin.skin_attr || []; if( nx.dt.arrEmpty( attrs ) ) { this.attrPersons.active = false; nx.gui.setActive( this.rootAttrs, "empty1", true ); } else { this.attrPersons.active = true; nx.gui.setActive( this.rootAttrs, "empty1", false ); let chds = this.attrPersons.children; nx.gui.gocChildren( this.attrPersons, "", attrs.length, chds[ 0 ] ); for( let i = 0; i < attrs.length; ++i ) { nx.bridge.attrs.setAttribute( chds[ i ], attrs[ i ] ); } } // 团体属性加成 attrs = _skin.skin_attr_all || []; if( nx.dt.arrEmpty( attrs ) ) { this.attrTeam.active = false; nx.gui.setActive( this.rootAttrs, "empty2", true ); } else { this.attrTeam.active = true; nx.gui.setActive( this.rootAttrs, "empty2", false ); let chds = this.attrTeam.children; nx.gui.gocChildren( this.attrTeam, "", attrs.length, chds[ 0 ] ); for( let i = 0; i < attrs.length; ++i ) { nx.bridge.attrs.setAttribute( chds[ i ], attrs[ i ] ); } } this.voice = ""; if( nx.dt.strNEmpty( _skin.voice ) ) { this.voice = cc.path.join( "resDB/models", _skin.res_id, _skin.voice ); } }, // 展示刷新 freshShows: function() { let skin = this.skins[ this.current ]; if( nx.dt.objEmpty( skin ) ) { this.nodOps.active = false; return; } nx.gui.setActive( this.nodName, "icon", true ); nx.gui.setActive( this.nodName, "icon/lock", this.partner.use_skin == 0 ); // nx.gui.setActive( this.nodName, "icon", this.partner.use_skin != 0 ); // 皮肤项刷新 let node = this.lstSkin.children[ this.current ]; let cmp = nx.gui.getComponent( node, "", "cmp.partner.skin.item" ); if( cmp ) { cmp.freshVars(); } // 操作刷新 let HC = HeroController.getInstance(); let HM = HC.getModel(); let used = ( this.partner.use_skin == skin.skin_id ); let lst = HM.hero_skin_list || {}; let have = nx.dt.numGood( lst[ skin.skin_id ] ); this.nodOps.active = true; nx.gui.setActive( this.nodOps, "use", !used && have ); nx.gui.setActive( this.nodOps, "using", used ); nx.gui.setActive( this.nodOps, "lock", false ); // nx.gui.setString( this.nodOps, "lock/txt", nx.text.getKey( skin.unlock_tip ) ); }, // 使用 onTouchChange: function() { let skin = this.skins[ this.current ]; if( nx.dt.objEmpty( skin ) ) { return; } let HC = HeroController.getInstance(); HC.sender11019( this.partner.partner_id, skin.skin_id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } this.freshShows(); nx.dt.fnInvoke( this.cbskin ); if( nx.dt.strNEmpty( this.voice ) ) { nx.audio.playSFX( this.voice ); } } ); }, // 点击还原 onTouchTakeOff: function() { let HC = HeroController.getInstance(); HC.sender11019( this.partner.partner_id, 0, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } this.freshShows(); nx.dt.fnInvoke( this.cbskin ); } ); }, onTouchLook: function(){ let skin_cfg = game.configs.partner_skin_data.data_skin_info[ this.skins[ this.current ].skin_id ]; if( skin_cfg ) { if( nx.dt.strEmpty( skin_cfg.hcg ) ){ let tip = nx.text.getKey( "NoImplementation" ); nx.tbox( tip ); return; } nx.bridge.plot.done(); let hcg = skin_cfg.hcg; nx.bridge.plot.records.ids.splice( nx.bridge.plot.records.ids.indexOf( hcg ), 1 ); nx.bridge.plot.fire( hcg ); } }, onTouchLock: function(){ let skin_cfg = game.configs.partner_skin_data.data_skin_info[ this.skins[ this.current ].skin_id ]; let tip = skin_cfg.unlock_tip; nx.tbox( tip ); }, // 点击规则 onTouchHelp: function() { let TC = TipsController.getInstance(); if( TC ) { let txt = game.configs.partner_skin_data.data_const.show_txt.desc; TC.showTextPanel( "tip", txt ); } }, } );