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

394 lines
9.4 KiB
JavaScript

/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 剧情/引导
*
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const NxSpine = require( "nx.fx.spine" );
const PlotDefine = require( "plot.define" );
const BattleController = require( "battle_controller" );
const BattleEvent = require( "battle_event" );
cc.Class( {
extends: BridgeWindow,
properties: {
nodPanel: { default: null, type: cc.Node },
nodArea: { default: null, type: cc.Node },
nodFigure: { default: null, type: cc.Node },
nodTell: { default: null, type: cc.Node },
nodSkip: { default: null, type: cc.Button },
spRole: { default: null, type: NxSpine },
},
// 重载:参数打开
onOpenConfigs: function( _params ) {
// 清理
this.doneStep();
// 是否主动激活
let id = nx.bridge.plot.vget( "id" );
if( nx.dt.strEmpty( id ) ) {
nx.error( "$PlotWnd:引导失败,查找当前引导失败!" );
this.delayClose();
return;
}
// 视图监听
nx.bridge.plot.vbind( this, [
[ "skip", this.onSkipChanged.bind( this ) ],
[ "step", this.onStepChanged.bind( this ) ],
[ "key", this.onKeyChanged.bind( this ) ],
] );
let step = nx.bridge.plot.vget( "step" );
if( step < 0 ) {
nx.bridge.plot.next();
}
nx.wp = this;
},
// 关闭
onDisable: function() {
// 视图解绑
nx.bridge.plot.vunbind( this );
},
// 点击热区
onTouchArea: function() {
if( !this.unit ) {
return;
}
// 隐藏热区&&手指
this.nodArea.active = false;
this.nodFigure.active = false;
let key = this.wkey;
// 触发
this.unit.cb();
// 下一步
if( nx.dt.strEmpty( key ) ) {
nx.bridge.plot.next();
}
},
// 执行单步
doStep: function( _data ) {
if( nx.dt.objEmpty( _data ) ) {
return;
}
// 界面显示
this.step = _data;
this.nodPanel.active = true;
// 特殊操作
if( nx.dt.strNEmpty( this.step.op ) ) {
this.doOp( this.step.op );
}
if( this.step ){
// 窗口关闭
if( this.step.close && nx.dt.strNEmpty( this.step.close ) ) {
this.doClosePanel( this.step.close );
}
// 讲述
if( this.step.words && nx.dt.strNEmpty( this.step.words ) ) {
this.startTell( this.step.tpos, this.step.words, this.step.emo );
}
// 引导元素
if( nx.dt.strNEmpty( this.step.unit ) ) {
this.focusUnit( this.step.unit );
// 聚焦失败,提前结束
if( !this.step ) {
return;
}
this.showFigure( this.step.figure || "" );
}
// 弹窗
if( nx.dt.strNEmpty( this.step.window ) ) {
nx.bridge.createPanel( this.step.window );
}
// 等待
this.wkey = this.step.event || "";
// 背景刷新
this.freshBG();
}
// 超时跳过
// this.openTimeoutSkip( !nx.bridge.plot.vget( "skip" ) );
},
// 单步完毕
doneStep: function() {
// 数据清理
this.step = null;
this.unit = null;
this.wkey = "";
// 隐藏热区&&手指
this.nodArea.active = false;
this.nodFigure.active = false;
this.nodTell.active = false;
// 界面隐藏
this.nodPanel.active = false;
// 超时跳过
this.openTimeoutSkip( false );
},
// 特殊操作
doOp: function( _op ) {
switch( _op ) {
// 返回主界面
case "main": {
//处于战斗中发送此消息通知服务端切出战斗,必须执行
let BC = BattleController.getInstance();
if( BC ) {
BC.SendProtocal( 20060, { combat_type: 0 } );
BC.setUIFightType( 0 );
}
nx.bridge.ui.cleanWindows();
nx.bridge.vset( "CloseSpecial", 1 );
} break;
// 提前完成记录
case "commit": {
let id = nx.bridge.plot.vget( "id" );
nx.bridge.plot.reqComplete( id );
} break;
default: break;
}
this.doneStep();
nx.bridge.plot.next();
},
// 窗体关闭
doClosePanel: function( _wid ) {
nx.bridge.closePanel( _wid );
this.doneStep();
nx.bridge.plot.next();
},
// 讲述
startTell: function( _tpos, _words, _emo = "idle" ) {
this.nodTell.active = true;
// 位置
// TPOS: [对齐方式,偏移,偏移,对白角色序号0开始]
let pos = _tpos || [ "center" ];
nx.gui.setAligment( this.nodTell, "", ...pos );
// 角色
let index = pos[ 3 ] || 0;
let info = nx.bridge.plot.vget( "info" );
let role = info.roles[ index ] || info.roles[ 0 ];
// 名字
nx.gui.setString( this.nodTell, "name", nx.text.getKey( role[ 0 ] ) );
nx.gui.setColor( this.nodTell, "name", cc.color().fromHEX( role[ 2 ] ) );
// 模型
let path = cc.path.join( "prefab/plot/models", role[ 1 ] );
this.spRole.play( path, _emo, () => { }, true );
// 文本
this.texts = nx.dt.objClone( nx.text.keymap[ _words ] );
if( nx.dt.arrEmpty( this.texts ) ) {
this.texts = [ _words ];
}
this.continueTell();
},
// 讲述继续
continueTell: function() {
// 结束
if( nx.dt.arrEmpty( this.texts ) ) {
this.doneStep();
nx.bridge.plot.next();
return;
}
// 文本
let text = this.texts.shift();
nx.gui.setString( this.nodTell, "content", text );
// 标记
nx.gui.setActive( this.nodTell, "continue", this.texts.length > 0 );
},
// 聚焦指定元素
focusUnit: function( _name ) {
this.unit = nx.bridge.plot.queryUnit( _name )
if( !this.unit ) {
this.nodArea.active = false;
nx.error( "$Plot:聚焦失败,未找到.", _name );
this.onTouchSkip();
return;
}
let pos = this.unit.node.convertToWorldSpaceAR( cc.Vec2.ZERO );
pos = this.nodPanel.convertToNodeSpaceAR( pos );
this.nodArea.active = true;
this.nodArea.anchorX = this.unit.node.anchorX;
this.nodArea.anchorY = this.unit.node.anchorY;
this.nodArea.position = pos;
this.nodArea.width = this.unit.node.width + 20;
this.nodArea.height = this.unit.node.height + 20;
this.nodArea.scale = 1;
nx.tween.breatheForever( this.nodArea, "", 2, 0.05 );
},
// 显示手指
showFigure: function( _pos ) {
// 不显示
if( nx.dt.strEmpty( _pos ) ) {
this.nodFigure.active = false;
return;
}
this.nodFigure.active = true;
this.nodFigure.position = this.nodArea.position;
this.nodFigure.width = this.nodArea.width;
this.nodFigure.height = this.nodArea.height;
this.nodFigure.children.forEach( node => {
node.active = ( node.name == _pos );
} );
},
// 点击跳过
onTouchSkip: function() {
this.doneStep();
nx.bridge.plot.done();
},
// 点击背景
onTouchBG: function() {
if( this.nodArea.active ) {
return;
}
// 讲述
if( this.nodTell.active ) {
this.continueTell();
}
},
// 显示背景
freshBG: function() {
let show = this.nodTell.active && !this.nodArea.active;
nx.gui.setActive( this, "panel/touch", show );
},
// 剧情可否跳过
onSkipChanged: function( _skip ) {
this.nodSkip.node.active = false;
if( !_skip ) {
return;
}
this.nodSkip.interactable = false;
nx.tween.delayFadeIn( this.nodSkip, "", 3, 1, () => {
this.nodSkip.interactable = true;
} );
},
// 步数改变
onStepChanged: function( _step, _, _init ) {
let step = nx.bridge.plot.stepData();
if( nx.dt.objEmpty( step ) ) {
this.doneStep();
return;
}
// 执行
this.doStep( step );
},
// 触发事件改变
onKeyChanged: function( _key, _, _init ) {
if( _init || nx.dt.strEmpty( _key ) ) {
return;
}
if( this.wkey == _key ) {
nx.bridge.plot.next();
}
},
// 异常情况超时跳过机制
openTimeoutSkip: function( _open ) {
nx.timers.delTimer( "PlotToutSkip" );
nx.gui.setActive( this.nodSkip, "", false );
if( !_open ) {
return;
}
nx.timers.newTimer( "PlotToutSkip", 15, 1, () => {
nx.gui.setActive( this.nodSkip, "", true );
nx.tween.delayFadeIn( this.nodSkip, "", 3, 1 );
} );
},
} );