Files
fc/dev/project/library/imports/85/85b33068-ea78-4138-9940-73c8e777569a.js
2026-05-24 10:21:26 +08:00

460 lines
11 KiB
JavaScript

"use strict";
cc._RF.push(module, '85b33Bo6nhBOJlAc8jnd1aa', 'cmp.summon.animation.wnd');
// Scripts/mod/summon/animation/cmp.summon.animation.wnd.js
"use strict";
/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 抽卡召唤动画
*
******************************************************************/
var BridgeWindow = require("bridge.window");
var FxSpine = require("nx.fx.spine");
var SummonMod = require("summon.mod");
// 超时循环上限
var LoopOut = 3;
// 音效
var SFXFolder = "prefab/summon/animation/sfx";
var SFXKeys = [
// "tv", "light", "cv", "change", "hand",
"bgm1", "tv", "light", "cv", "change", "hand"];
// 翻卡节点
var FlipNodes = {
"k1": 0,
"k2": 1,
"k3": 2,
"k4": 3,
"k5": 4,
"k6": 5,
"k7": 6,
"k8": 7,
"k9": 8,
"k10": 9
};
// 阶段定义
var Stage = {
None: 0,
Wait: 1,
// 等待循环
Anim1: 2,
// 动画1
Anim2: 3,
// 动画2
SSR: 4,
// SR展示
Flip: 5,
// 翻卡片
Done: 6 // 结束
};
cc.Class({
"extends": BridgeWindow,
properties: {
nodTouch: {
"default": null,
type: cc.Node
},
cmpSpine: {
"default": null,
type: FxSpine
},
cardS: {
"default": null,
type: cc.Node
},
card10: {
"default": [],
type: cc.Node
},
nodOps: {
"default": null,
type: cc.Node
}
},
// 显示
onLoad: function onLoad() {
// 全局支持
nx.bridge.summonAnimation = this;
// 隐藏(因为常驻,不销毁)
this.setStage(Stage.Done);
this.doStop();
},
// 关闭
onDestroy: function onDestroy() {
if (window.nx && nx.bridge) {
// 全局支持
nx.bridge.summonAnimation = null;
}
},
// 开始
doStart: function doStart() {
// 节点隐藏
nx.gui.hideAllChildren(this.cardS, "");
this.card10.forEach(function (card) {
nx.gui.hideAllChildren(card, "");
});
// UI初始化
nx.gui.setActive(this, "panel", true);
nx.gui.setActive(this.nodOps, "", false);
nx.gui.setActive(this, "panel/closeTip", false);
this.stepWaiting();
},
// 设置结果
setResult: function setResult(_data, _args, _cb) {
this.sumRet = _data || {};
this.sumArgs = _args || {};
this.sumCB = _cb;
},
// 结束
doStop: function doStop() {
// 通知
if (nx.dt.fnGood(this.sumCB)) {
nx.dt.fnInvoke(this.sumCB, true);
this.sumCB = null;
}
// 清理
this.sumRet = null;
this.sumArgs = null;
this.sumCB = null;
this.cmpSpine.stop(false);
nx.gui.setActive(this, "panel", false);
},
// 音效事件
trySFX: function trySFX(_key) {
nx.debug("$StepEvent:", _key);
if (!nx.dt.arrMember(SFXKeys, _key)) {
return false;
}
var path = cc.path.join(SFXFolder, _key);
nx.audio.playSFX(path, false);
return true;
},
// 阶段1: 等待
stepWaiting: function stepWaiting() {
var _this = this;
// 阶段更新
this.setStage(Stage.Wait);
// 背景
var path = cc.path.join("prefab/summon/animation/bg1");
nx.gui.setSpriteFrame(this, "panel/bg", path);
// 动画
this.loops = 0;
this.cmpSpine.action("action1", true, function (_key) {
_this.trySFX(_key);
if (_key == "complete") {
if (_this.sumRet) {
_this.stepAnim1();
} else {
++_this.loops;
if (_this.loops >= LoopOut) {
_this.doStop();
}
}
}
});
},
// 阶段2: 动画1
stepAnim1: function stepAnim1() {
var _this2 = this;
// 阶段更新
this.setStage(Stage.Anim1);
this.cmpSpine.action("action2", false, function (_key) {
_this2.trySFX(_key);
if (_key == "complete") {
_this2.stepAnim2();
}
});
},
// 阶段3: 动画2
stepAnim2: function stepAnim2() {
var _this3 = this;
// 阶段更新
this.setStage(Stage.Anim2);
// 背景
var path = cc.path.join("prefab/summon/animation/bg2");
nx.gui.setSpriteFrame(this, "panel/bg", path);
// 统计SR&&SSR
this.sr = [];
this.srs = [];
for (var i = 0; i < this.sumRet.partner_bids.length; ++i) {
var pt = this.sumRet.partner_bids[i];
var base = game.configs.partner_data.data_partner_base[pt.partner_bid];
if (base && base.quality >= 4) {
this.srs.push(pt);
}
if (base && base.quality == 3) {
this.sr.push(pt);
}
}
// 单抽动作: action3_z2, action3_j2, action3_l2
// 十连抽动作: action3_z, action3_j
var key = "action3_l2";
var golden = nx.dt.arrNEmpty(this.srs);
if (this.sumRet.partner_bids.length == 1) {
if (golden) {
key = "action3_j2";
} else if (nx.dt.arrNEmpty(this.sr)) {
key = "action3_z2";
}
} else {
key = golden ? "action3_j" : "action3_z";
}
this.cmpSpine.action(key, false, function (_key) {
_this3.trySFX(_key);
if (_key == "complete") {
_this3.stepSRShow();
}
});
},
// 阶段4: SR&&SSR展示
stepSRShow: function stepSRShow() {
var _this4 = this;
// 阶段更新
this.setStage(Stage.SSR);
// 五星展示
var SC = SummonMod.getInstance();
if (SC && nx.dt.arrNEmpty(this.srs)) {
SC.openSummonGainShowWindow(true, this.srs, function () {
_this4.stepFlip();
});
} else {
this.stepFlip();
}
},
// 直达翻卡阶段
jumpToFlipCards: function jumpToFlipCards(_data, _args, _cb) {
// 节点隐藏
nx.gui.hideAllChildren(this.cardS, "");
this.card10.forEach(function (card) {
nx.gui.hideAllChildren(card, "");
});
// UI初始化
nx.gui.setActive(this, "panel", true);
nx.gui.setActive(this.nodOps, "", false);
nx.gui.setActive(this, "panel/closeTip", false);
this.sumRet = _data || {};
this.sumArgs = _args || {};
this.sumCB = _cb;
this.stepFlip();
},
// 阶段5: 翻卡
stepFlip: function stepFlip() {
var _this5 = this;
// 阶段更新
this.setStage(Stage.Flip);
// 背景
var path = cc.path.join("prefab/summon/animation/bg3");
nx.gui.setSpriteFrame(this, "panel/bg", path);
// 翻牌处理
var self = this;
var partners = this.sumRet.partner_bids;
var flip = function flip(_root, _info) {
var node = _root.children[0];
if (!node) {
var tmp = nx.gui.find(self, "panel/tmp/cardT");
node = cc.instantiate(tmp);
node.parent = _root;
}
node.active = true;
node.position = cc.Vec2.ZERO;
var card = node.getComponent("cmp.summon.animation.card");
card.flip(_info);
var sfx = cc.path.join(SFXFolder, "card");
nx.audio.playSFX(sfx, false);
};
// 单抽
var flipS = function flipS() {
flip(self.cardS, partners[0]);
};
// 十连抽
var flip10 = function flip10(_key) {
var index = FlipNodes[_key];
if (!nx.dt.numGood(index)) {
return;
}
var root = self.card10[index];
if (!root) {
return;
}
flip(root, partners[index]);
};
// 动画
var key = partners.length == 1 ? "action5" : "action4";
this.cmpSpine.action(key, false, function (_key) {
_this5.trySFX(_key);
// 单抽
if (_key == "k0") {
flipS();
} else {
flip10(_key);
}
if (_key == "complete") {
// 阶段更新
_this5.stepOps();
}
});
},
// 阶段6: 操作菜单显示
stepOps: function stepOps() {
// 阶段更新
this.setStage(Stage.Done);
// 没有特殊操作
if (nx.dt.objEmpty(this.sumArgs)) {
nx.gui.setActive(this, "panel/closeTip", true);
nx.tween.fadeIn(this, "panel/closeTip", 0.5);
return;
}
var op = this.sumArgs.op || "summon";
this.nodOps.children.forEach(function (_node) {
_node.active = _node.name == op;
});
switch (op) {
// 召唤面板
case "summon":
{
this.freshSummonOps(this.sumArgs);
}
break;
// 无限十连抽
case "infinite":
{
this.freshInfiniteOps(this.sumArgs);
}
break;
// 无法识别
default:
{
nx.error("$SumAnimation:无效OP:", op);
nx.gui.setActive(this, "panel/closeTip", true);
nx.tween.fadeIn(this, "panel/closeTip", 0.5);
return;
}
break;
}
// 显示
nx.gui.setActive(this.nodOps, "", true);
nx.tween.fadeIn(this.nodOps, "", 0.5);
},
// 点击背景
onTouchBG: function onTouchBG() {
// 不同阶段处理
switch (this.stage) {
// 动画阶段
case Stage.Anim1:
case Stage.Anim2:
{
this.cmpSpine.stop(false);
this.stepFlip();
}
break;
// 结束阶段
case Stage.Done:
{
// 直接关闭
if (!this.nodOps.active) {
this.doStop();
}
}
break;
}
},
// 阶段更新
setStage: function setStage(_stage) {
nx.debug("$SumAnimation:阶段改变:", this.stage, _stage);
this.stage = _stage;
},
// ======================================================
// 二次操作相关
// ======================================================
// 刷新召唤面板
/**
* 参数结构
* op: "summon",
* bid: 所需道具编号
* need: 所需道具数量
* txt: 按钮文本
* cb: 点击回调
*/
freshSummonOps: function freshSummonOps(_args) {
var node = nx.gui.find(this.nodOps, "summon/draw");
if (node) {
var cfg = gitemdata(_args.bid);
nx.bridge.setIcon(node, "need/list/icon", cfg ? cfg.icon : 0);
nx.gui.setString(node, "need/list/num", _args.need);
nx.gui.setString(node, "btn/txt", nx.text.getKey(_args.txt));
}
},
// 点击召唤取消
onTouchSummonCancel: function onTouchSummonCancel() {
if (this.sumArgs) {
nx.dt.fnInvoke(this.sumArgs.cb, false);
}
},
// 点击召唤
onTouchSummonConfirm: function onTouchSummonConfirm() {
if (this.sumArgs) {
nx.dt.fnInvoke(this.sumArgs.cb, true);
}
},
// 刷新无限十连抽
/**
* 参数结构
* op: "infinite",
* cb: 点击回调(0:再抽 1:满意)
*/
freshInfiniteOps: function freshInfiniteOps(_args) {
// 剩餘次數
var times = nx.bridge.vget("INFTimes") || 0;
nx.gui.setString(this.nodOps, "infinite/times/txt", nx.text.format("剩余次数", times));
},
// 点击不满意
onTouchInfiniteAgain: function onTouchInfiniteAgain() {
nx.dt.fnInvoke(this.sumArgs.cb, false);
},
// 点击满意
onTouchInfiniteOK: function onTouchInfiniteOK() {
nx.dt.fnInvoke(this.sumArgs.cb, true);
},
// 点击方案
onTouchInfiniteRecord: function onTouchInfiniteRecord() {
nx.bridge.createPanel("WndSummonInfiniteRecord", {
replace: true
});
},
// 点击关闭
onTouchInfiniteClose: function onTouchInfiniteClose() {
this.sumCB = null;
this.doStop();
}
});
cc._RF.pop();