262 lines
7.0 KiB
JavaScript
262 lines
7.0 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, '2be24VsBWZNMaRGxhmUEcH1', 'cmp.bedroom.story.wnd');
|
||
|
|
// Scripts/mod/home/bedroom/cmp.bedroom.story.wnd.js
|
||
|
|
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
/******************************************************************
|
||
|
|
*
|
||
|
|
* 闺房剧情场景
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
var BridgeWindow = require("bridge.window");
|
||
|
|
var HomeModel = require("home.mod");
|
||
|
|
var FxBGM = require("nx.fx.BGM");
|
||
|
|
var FxSpine = require("nx.fx.spine");
|
||
|
|
var START_ID = "start";
|
||
|
|
var 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 onDisable() {
|
||
|
|
this.unscheduleAllCallbacks();
|
||
|
|
},
|
||
|
|
// 重载:参数打开
|
||
|
|
onOpenConfigs: function onOpenConfigs(_params) {
|
||
|
|
var _this = this;
|
||
|
|
// 设置自动
|
||
|
|
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(function () {
|
||
|
|
_this.close();
|
||
|
|
}, 0.1);
|
||
|
|
nx.error("无效闺蜜剧情章节:" + this.profile_id);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 标题
|
||
|
|
var txt = nx.text.getKey(this.profile.name || "Archives");
|
||
|
|
nx.gui.setString(this.nodHead, "txt", txt);
|
||
|
|
|
||
|
|
// 背景动画
|
||
|
|
var 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();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 设置当前对话
|
||
|
|
var step = _params.step || -1;
|
||
|
|
if (step <= 0) {
|
||
|
|
step = 1;
|
||
|
|
}
|
||
|
|
var talkId = "start";
|
||
|
|
for (var tid in this.talks) {
|
||
|
|
var t = this.talks[tid];
|
||
|
|
if (t && t.rank == step) {
|
||
|
|
talkId = tid;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.resetTalk(talkId);
|
||
|
|
},
|
||
|
|
// 设置当前对话
|
||
|
|
resetTalk: function resetTalk(_talk_id) {
|
||
|
|
this.talk_id = _talk_id || START_ID;
|
||
|
|
var 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 (var _i in data.next_content_id) {
|
||
|
|
var id = data.next_content_id[_i];
|
||
|
|
this.cur.selects.push(this.talks[id]);
|
||
|
|
}
|
||
|
|
this.setEnd(false);
|
||
|
|
this.onTouchNext();
|
||
|
|
},
|
||
|
|
// 点击下一步
|
||
|
|
onTouchNext: function onTouchNext() {
|
||
|
|
// 下一句
|
||
|
|
this.cur.index += 1;
|
||
|
|
|
||
|
|
// 对话已经完成
|
||
|
|
if (this.cur.index >= this.cur.content.length) {
|
||
|
|
// 如果单选项
|
||
|
|
if (this.cur.selects.length == 1) {
|
||
|
|
var 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;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 文本
|
||
|
|
var txt = nx.text.getKey(this.cur.content[this.cur.index]);
|
||
|
|
nx.gui.setString(this.nodContent, "txt", txt);
|
||
|
|
|
||
|
|
// 选项更新
|
||
|
|
var end = this.cur.index == this.cur.content.length - 1;
|
||
|
|
var ops = this.cur.selects.length == 2;
|
||
|
|
var root = nx.gui.setActive(this.nodContent.parent, "choices", end && ops);
|
||
|
|
if (root && end && ops) {
|
||
|
|
var choice = function choice(_btn, _info) {
|
||
|
|
var 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 onTouchChoice(_key) {
|
||
|
|
var _this2 = this;
|
||
|
|
var index = parseInt(_key) || 1;
|
||
|
|
var cfgs = this.cur.selects[index - 1];
|
||
|
|
if (nx.dt.objEmpty(cfgs)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var HC = HomeModel.getInstance();
|
||
|
|
var tid = cfgs.next_content_id[0];
|
||
|
|
HC.commitStoryOp(this.profile_id, cfgs.number, function (_ret, _data) {
|
||
|
|
if (!_ret) {
|
||
|
|
nx.tbox(_data);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 下段
|
||
|
|
_this2.resetTalk(tid);
|
||
|
|
});
|
||
|
|
},
|
||
|
|
// 点击自动
|
||
|
|
onTouchAuto: function onTouchAuto() {
|
||
|
|
this.setAutoPlay(true);
|
||
|
|
},
|
||
|
|
// 点击取消自动
|
||
|
|
onTouchAutoCancel: function onTouchAutoCancel() {
|
||
|
|
this.setAutoPlay(false);
|
||
|
|
},
|
||
|
|
// 设置结束标记
|
||
|
|
setEnd: function setEnd(_end) {
|
||
|
|
nx.gui.setActive(this.nodContent, "end", _end);
|
||
|
|
},
|
||
|
|
// 设置自动
|
||
|
|
setAutoPlay: function setAutoPlay(_open) {
|
||
|
|
var _this3 = this;
|
||
|
|
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);
|
||
|
|
var 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(function () {
|
||
|
|
if (_this3.cur.selects.length == 2) {
|
||
|
|
_this3.onTouchChoice(_this3.profile["default"]);
|
||
|
|
} else {
|
||
|
|
_this3.onTouchNext();
|
||
|
|
}
|
||
|
|
}, AUTO_INTERVAL, cc.macro.repeatForever);
|
||
|
|
},
|
||
|
|
// 点击跳过
|
||
|
|
onTouchSkip: function onTouchSkip() {
|
||
|
|
if (this.cur && this.cur.selects.length == 2) {
|
||
|
|
this.onTouchChoice(this.profile["default"]);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 点击剧本集
|
||
|
|
onTouchGraphic: function onTouchGraphic() {
|
||
|
|
var _this4 = this;
|
||
|
|
var home = HomeModel.getInstance();
|
||
|
|
home.reqArchiveInfo(this.profile_id, function (_ret, _data) {
|
||
|
|
if (!_ret) {
|
||
|
|
nx.tbox(_data);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
nx.bridge.createPanel("WndBedroomDocument", {
|
||
|
|
partner_id: _this4.partner_id,
|
||
|
|
profile_id: _this4.profile_id,
|
||
|
|
talks: _data.historical_dialogue,
|
||
|
|
results: _data.personal_profile_result,
|
||
|
|
story: _this4
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
cc._RF.pop();
|