Files
2026-05-23 22:10:14 +08:00

170 lines
4.2 KiB
JavaScript

/******************************************************************
*
* 伙伴全身立绘动画展示
*
******************************************************************/
const NxSpine = require( "nx.fx.spine" );
const BridgeComponent = require( "bridge.component" );
cc.Class( {
extends: BridgeComponent,
properties: {
spRole: { default: null, type: NxSpine },
nodLoading: { default: null, type: cc.Node },
nodTouch: { default: null, type: cc.Node },
nodDialog: { default: null, type: cc.Node },
},
// 设置伙伴
setPartner: function( _partner ) {
// 置空
let sinfo = _partner ? nx.bridge.partner.getShowInfo( _partner ) : null;
if( !sinfo ) {
this.setEmpty();
return;
}
this.partner = _partner;
this.setModel( sinfo.sp_show, sinfo.voice, sinfo.phonetic_text );
},
// 设置模型动画, 区别显示了 主场景伙伴与 伙伴背包伙伴详情 点击动画与 展示动画
setModel: function( _spath, _voice, _desc, _from ) {
this.fromOther = _from;
// 重复
if( this.modelPath == _spath ) {
return;
}
this.setEmpty();
// 更新
this.modelPath = _spath;
this.voicePath = _voice;
this.desc = nx.dt.objEmpty( this.desc ) ? _desc : this.desc;
if( nx.dt.strEmpty( this.modelPath ) ) {
return;
}
// 模型展示
this.spRole.load( this.modelPath, ( _e ) => {
if( !_e ) {
this.nodLoading.active = false;
this.nodTouch.active = true;
this.spRole.action( _from ? "drama1" : "action1", true );
this.spRole.node.active = true;
}else{
this.spRole.node.active = false;
}
} );
if( this.nodDialog ){
nx.gui.setString( this.nodDialog, "txt", this.desc );
}
},
// 置空
setEmpty: function() {
this.modelPath = "";
this.spRole.stop();
this.spRole.node.active = false;
this.nodLoading.active = false;
this.nodTouch.active = false;
if( this.nodDialog && this.tween ){
this.nodDialog.scale = 0;
this.tween.stop();
nx.gui.setActive( this.nodDialog, "", false );
}
},
// 点击动画
onTouchSpine: function() {
// 加载中
if( this.nodLoading.active ) {
return;
}
if( this.fromOther ){
if( this.spRole.spAction != "drama1" ) {
return;
}
}else{
// 屏蔽频繁点击打断
if( this.spRole.spAction != "action1" ) {
return;
}
}
// 播放 -> 常态
this.spRole.action( this.fromOther ? "drama3" : "action2", false, ( _event ) => {
// 播放语音
if( _event == "start" ) {
this.playVoice();
}
if( _event == "complete" ) {
this.spRole.action( this.fromOther ? "drama1" : "action1", true );
}
} );
// this.unscheduleAllCallbacks();
if( this.nodDialog ){
nx.gui.setActive( this.nodDialog, "", nx.dt.strNEmpty( this.desc ) );
this.tween = cc.tween( this.nodDialog )
.to(0.2, { scale: 1 })
.to(3, { scale: 1 })
.to(0.2, { scale: 0 })
.to( 0, ()=>{
nx.gui.setActive( this.nodDialog, "", false );
} )
.start()
// this.scheduleOnce( ()=>{
// nx.gui.setActive( this.nodDialog, "", false );
// },3 );
}
},
// 播放语音
playVoice: function() {
if( nx.dt.strEmpty( this.voicePath ) ) {
return;
}
if( this.voiceHandle ) {
nx.audio.stopSFX( this.voiceHandle );
this.voiceHandle = null;
}
nx.audio.playVoice( this.voicePath, ( _err, _id ) => {
if( !_err ) {
this.voiceHandle = _id;
}
});
},
} );