Files
fc/dev/project/library/imports/9f/9fe83fb1-9ef1-4703-8865-aecea1a8f04d.js
T
2026-05-24 10:21:26 +08:00

352 lines
8.6 KiB
JavaScript

"use strict";
cc._RF.push(module, '9fe83+xnvFHA4hlrs6hqPBN', 'cmp.plot.guide.wnd');
// Scripts/mod/plot/cmps/cmp.plot.guide.wnd.js
"use strict";
/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 剧情/引导
*
*
******************************************************************/
var BridgeWindow = require("bridge.window");
var NxSpine = require("nx.fx.spine");
var PlotDefine = require("plot.define");
var BattleController = require("battle_controller");
var 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 onOpenConfigs(_params) {
// 清理
this.doneStep();
// 是否主动激活
var 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)]]);
var step = nx.bridge.plot.vget("step");
if (step < 0) {
nx.bridge.plot.next();
}
nx.wp = this;
},
// 关闭
onDisable: function onDisable() {
// 视图解绑
nx.bridge.plot.vunbind(this);
},
// 点击热区
onTouchArea: function onTouchArea() {
if (!this.unit) {
return;
}
// 隐藏热区&&手指
this.nodArea.active = false;
this.nodFigure.active = false;
var key = this.wkey;
// 触发
this.unit.cb();
// 下一步
if (nx.dt.strEmpty(key)) {
nx.bridge.plot.next();
}
},
// 执行单步
doStep: function doStep(_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 doneStep() {
// 数据清理
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 doOp(_op) {
switch (_op) {
// 返回主界面
case "main":
{
//处于战斗中发送此消息通知服务端切出战斗,必须执行
var 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":
{
var id = nx.bridge.plot.vget("id");
nx.bridge.plot.reqComplete(id);
}
break;
default:
break;
}
this.doneStep();
nx.bridge.plot.next();
},
// 窗体关闭
doClosePanel: function doClosePanel(_wid) {
nx.bridge.closePanel(_wid);
this.doneStep();
nx.bridge.plot.next();
},
// 讲述
startTell: function startTell(_tpos, _words, _emo) {
var _nx$gui;
if (_emo === void 0) {
_emo = "idle";
}
this.nodTell.active = true;
// 位置
// TPOS: [对齐方式,偏移,偏移,对白角色序号0开始]
var pos = _tpos || ["center"];
(_nx$gui = nx.gui).setAligment.apply(_nx$gui, [this.nodTell, ""].concat(pos));
// 角色
var index = pos[3] || 0;
var info = nx.bridge.plot.vget("info");
var 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]));
// 模型
var path = cc.path.join("prefab/plot/models", role[1]);
this.spRole.play(path, _emo, function () {}, true);
// 文本
this.texts = nx.dt.objClone(nx.text.keymap[_words]);
if (nx.dt.arrEmpty(this.texts)) {
this.texts = [_words];
}
this.continueTell();
},
// 讲述继续
continueTell: function continueTell() {
// 结束
if (nx.dt.arrEmpty(this.texts)) {
this.doneStep();
nx.bridge.plot.next();
return;
}
// 文本
var text = this.texts.shift();
nx.gui.setString(this.nodTell, "content", text);
// 标记
nx.gui.setActive(this.nodTell, "continue", this.texts.length > 0);
},
// 聚焦指定元素
focusUnit: function focusUnit(_name) {
this.unit = nx.bridge.plot.queryUnit(_name);
if (!this.unit) {
this.nodArea.active = false;
nx.error("$Plot:聚焦失败,未找到.", _name);
this.onTouchSkip();
return;
}
var 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 showFigure(_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(function (node) {
node.active = node.name == _pos;
});
},
// 点击跳过
onTouchSkip: function onTouchSkip() {
this.doneStep();
nx.bridge.plot.done();
},
// 点击背景
onTouchBG: function onTouchBG() {
if (this.nodArea.active) {
return;
}
// 讲述
if (this.nodTell.active) {
this.continueTell();
}
},
// 显示背景
freshBG: function freshBG() {
var show = this.nodTell.active && !this.nodArea.active;
nx.gui.setActive(this, "panel/touch", show);
},
// 剧情可否跳过
onSkipChanged: function onSkipChanged(_skip) {
var _this = this;
this.nodSkip.node.active = false;
if (!_skip) {
return;
}
this.nodSkip.interactable = false;
nx.tween.delayFadeIn(this.nodSkip, "", 3, 1, function () {
_this.nodSkip.interactable = true;
});
},
// 步数改变
onStepChanged: function onStepChanged(_step, _, _init) {
var step = nx.bridge.plot.stepData();
if (nx.dt.objEmpty(step)) {
this.doneStep();
return;
}
// 执行
this.doStep(step);
},
// 触发事件改变
onKeyChanged: function onKeyChanged(_key, _, _init) {
if (_init || nx.dt.strEmpty(_key)) {
return;
}
if (this.wkey == _key) {
nx.bridge.plot.next();
}
},
// 异常情况超时跳过机制
openTimeoutSkip: function openTimeoutSkip(_open) {
var _this2 = this;
nx.timers.delTimer("PlotToutSkip");
nx.gui.setActive(this.nodSkip, "", false);
if (!_open) {
return;
}
nx.timers.newTimer("PlotToutSkip", 15, 1, function () {
nx.gui.setActive(_this2.nodSkip, "", true);
nx.tween.delayFadeIn(_this2.nodSkip, "", 3, 1);
});
}
});
cc._RF.pop();