Files
fc/dev/project/assets/Scripts/mod/home/bedroom/cmp.bedroom.story.wnd.js
T
2026-05-23 22:10:14 +08:00

284 lines
7.7 KiB
JavaScript

/******************************************************************
*
* 闺房剧情场景
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const HomeModel = require( "home.mod" );
const FxBGM = require( "nx.fx.BGM" );
const FxSpine = require( "nx.fx.spine" );
const START_ID = "start";
const AUTO_INTERVAL = 3;
cc.Class( {
extends: BridgeWindow,
properties: {
spBG: { default: null, type: FxSpine },
nodHead: { default: null, type: cc.Node },
nodTime: { default: null, type: cc.Node },
nodTitle: { default: null, type: cc.Node },
nodContent: { default: null, type: cc.Node },
nodChoices: { default: null, type: cc.Node },
cmpBGM: { default: null, type: FxBGM },
},
// 关闭
onDisable: function() {
this.unscheduleAllCallbacks();
},
// 重载:参数打开
onOpenConfigs: function( _params ) {
// 设置自动
this.setAutoPlay( false );
this.setEnd( false );
this.partner_id = _params.partner_id;
this.profile_id = _params.profile_id;
// 配置获取
this.partner = game.configs.partner_data.data_partner_base[ this.partner_id ];
this.profile = game.configs.favor_data.data_interface[ this.profile_id ];
this.talks = game.configs.favor_data.data_content[ this.profile_id ];
if( nx.dt.objEmpty( this.partner ) ||
nx.dt.objEmpty( this.talks ) ||
nx.dt.objEmpty( this.profile ) ) {
this.scheduleOnce( () => {
this.close();
}, 0.1 );
nx.error( "无效闺蜜剧情章节:" + this.profile_id );
return;
}
// 标题
let txt = nx.text.getKey( this.profile.name || "Archives" );
nx.gui.setString( this.nodHead, "txt", txt );
// 背景动画
let path = cc.path.join( "prefab/home/bedroom/roles", this.profile.bg_res, "spines/model" );
if( this.spBG.key != path ) {
this.spBG.play( path, "action", null, true );
}
// 角色名
nx.gui.setString( this.nodTitle, "txt", nx.text.getKey( this.partner.name ) );
// 背景音乐
if( nx.dt.strNEmpty( this.profile.bgm ) ) {
path = cc.path.join( "prefab/home/bedroom/bgm", this.profile.bgm );
this.cmpBGM.bgmRK = path;
this.cmpBGM.reActive();
}
// 设置当前对话
let step = _params.step || -1;
if( step <= 0 ) {
step = 1;
}
let talkId = "start";
for( let tid in this.talks ) {
let t = this.talks[tid];
if( t && t.rank == step ) {
talkId = tid;
break;
}
}
this.resetTalk( talkId );
},
// 设置当前对话
resetTalk: function( _talk_id ) {
this.talk_id = _talk_id || START_ID;
let data = this.talks[ this.talk_id ];
if( nx.dt.objEmpty( data ) ) {
this.curtalk = null;
nx.error( "无效的对话:", this.profile_id, _talk_id );
return;
}
this.cur = {
index: -1,
tid: data.number,
content: data.content,
selects: [],
};
for( let i in data.next_content_id ) {
let id = data.next_content_id[ i ];
this.cur.selects.push( this.talks[ id ] );
}
this.setEnd( false );
this.onTouchNext();
},
// 点击下一步
onTouchNext: function() {
// 下一句
this.cur.index += 1;
// 对话已经完成
if( this.cur.index >= this.cur.content.length ) {
// 如果单选项
if( this.cur.selects.length == 1 ) {
let ifo = this.cur.selects[ i ];
if( ifo ) {
this.resetTalk( ifo.next_content_id[ 0 ] );
}
}
// 如果已经完结
if( this.cur.selects.length == 0 ) {
this.setAutoPlay( false );
this.setEnd( true );
}
return;
}
// 文本
let txt = nx.text.getKey( this.cur.content[ this.cur.index ] );
nx.gui.setString( this.nodContent, "txt", txt );
// 选项更新
let end = ( this.cur.index == ( this.cur.content.length - 1 ) );
let ops = ( this.cur.selects.length == 2 );
let root = nx.gui.setActive( this.nodContent.parent, "choices", end && ops );
if( root && end && ops ) {
let choice = function( _btn, _info ) {
let path = cc.path.join( "prefab/home/bedroom/ui", "icon" + _info.icon );
nx.gui.setSpriteFrame( _btn, "icon", path );
nx.gui.setString( _btn, "txt", nx.text.getKey( _info.content[ 0 ] ) );
};
choice( nx.gui.find( root, "c1/btn" ), this.cur.selects[ 0 ] );
choice( nx.gui.find( root, "c2/btn" ), this.cur.selects[ 1 ] );
}
},
// 点击选项
onTouchChoice: function( _key ) {
let index = parseInt( _key ) || 1;
let cfgs = this.cur.selects[ index - 1 ];
if( nx.dt.objEmpty( cfgs ) ) {
return;
}
let HC = HomeModel.getInstance();
let tid = cfgs.next_content_id[ 0 ];
HC.commitStoryOp( this.profile_id, cfgs.number, ( _ret, _data ) => {
if( !_ret ) {
nx.tbox( _data );
return;
}
// 下段
this.resetTalk( tid );
} );
},
// 点击自动
onTouchAuto: function() {
this.setAutoPlay( true );
},
// 点击取消自动
onTouchAutoCancel: function() {
this.setAutoPlay( false );
},
// 设置结束标记
setEnd: function( _end ) {
nx.gui.setActive( this.nodContent, "end", _end );
},
// 设置自动
setAutoPlay: function( _open ) {
this.unscheduleAllCallbacks();
this.autoPlaying = _open;
nx.gui.setActive( this.nodContent, "flag", _open );
nx.gui.setActive( this.nodContent, "ops/auto", !_open );
nx.gui.setActive( this.nodContent, "ops/auto_cancel", _open );
let flag = nx.gui.find( this.nodContent, "flag" );
if( !_open ) {
cc.Tween.stopAllByTarget( flag );
return;
}
// 闪烁
cc.tween( flag )
.repeatForever(
cc.tween()
.to( 0.5, { opacity: 100 } )
.to( 0.5, { opacity: 200 } )
)
.start();
// 心跳
this.schedule( () => {
if( this.cur.selects.length == 2 ) {
this.onTouchChoice( this.profile.default );
} else {
this.onTouchNext();
}
}, AUTO_INTERVAL, cc.macro.repeatForever );
},
// 点击跳过
onTouchSkip: function() {
if( this.cur &&
this.cur.selects.length == 2 ) {
this.onTouchChoice( this.profile.default );
}
},
// 点击剧本集
onTouchGraphic: function() {
let home = HomeModel.getInstance();
home.reqArchiveInfo( this.profile_id, ( _ret, _data ) => {
if( !_ret ) {
nx.tbox( _data );
return;
}
nx.bridge.createPanel( "WndBedroomDocument", {
partner_id: this.partner_id,
profile_id: this.profile_id,
talks: _data.historical_dialogue,
results: _data.personal_profile_result,
story: this,
});
} );
},
} );