a82b1762-2ea5-4e85-894e-fd48f5d79339.js
6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"use strict";
cc._RF.push(module, 'a82b1diLqVOhYlO/Uj115M5', 'AnimationUtils');
// script/common/utils/AnimationUtils.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnimationUtils = void 0;
const FrameAnimation_1 = require("../components/FrameAnimation");
const ScheduleUtils_1 = require("./ScheduleUtils");
var AnimationUtils;
(function (AnimationUtils) {
function playFrameAnimation(node, loop, name, callback) {
let anims = node.getComponents(FrameAnimation_1.default);
if (!anims || anims.length == 0) {
return;
}
let findOne = anims[0];
for (let i = 0; i < anims.length; i++) {
const anim = anims[i];
if (anim.tag == name) {
findOne = anim;
}
else {
anim.enabled = false;
}
}
findOne.enabled = true;
findOne.play(callback, loop);
}
AnimationUtils.playFrameAnimation = playFrameAnimation;
function playFrameAnimationOnce(node, name, callback) {
playFrameAnimation(node, false, name, callback);
}
AnimationUtils.playFrameAnimationOnce = playFrameAnimationOnce;
function playFrameAnimationLoop(node, name) {
playFrameAnimation(node, true, name);
}
AnimationUtils.playFrameAnimationLoop = playFrameAnimationLoop;
function animateProgress(progressBar, progress, speed = 1, label) {
return new Promise((resolve) => {
let oldProgress = progressBar.progress;
if (oldProgress == progress) {
resolve();
return;
}
if (progress > 1)
progress = 1;
if (progress < 0)
progress = 0;
let delta = progress - oldProgress;
if (progressBar.updateFunc)
ScheduleUtils_1.ScheduleUtils.unscheduleUpdate(progressBar.updateFunc);
const update = (dt) => {
oldProgress += delta * dt * speed;
if ((delta > 0 && oldProgress > progress) || (delta < 0 && oldProgress < progress)) {
oldProgress = progress;
delete progressBar.updateFunc;
ScheduleUtils_1.ScheduleUtils.unscheduleUpdate(update);
resolve();
}
progressBar.progress = oldProgress;
if (label)
label.string = `${Math.round(oldProgress * 1000) / 10}%`;
};
progressBar.updateFunc = update;
ScheduleUtils_1.ScheduleUtils.scheduleUpdate(update);
});
}
AnimationUtils.animateProgress = animateProgress;
//异步动画执行API. 方便链式调用.
async function runAction(node, action) {
return new Promise(resolve => {
if (!action || !node) {
console.info("runAction param is null:", node, action);
resolve();
return;
}
let nd = node instanceof cc.Component ? node.node : node;
nd.runAction(cc.sequence(action, cc.callFunc(function () {
resolve();
})));
});
}
AnimationUtils.runAction = runAction;
let timerIds = [];
function ActionTypeWriter(comp, str, time) {
return new Promise((resolve) => {
if (timerIds && timerIds.length) {
for (let i = 0; i < timerIds.length; i++) {
clearTimeout(timerIds[i]);
}
timerIds = [];
}
if (!comp || !str || "" === str.trim()) {
return;
}
comp.string = str;
time = time ? time : 1;
let cArr = [];
for (let i = 0; i < str.length; i++) {
cArr.push(" ");
}
let reg = new RegExp(',', 'g');
for (let i = 0; i < str.length; i++) {
cArr[i] = str[i];
let s = cArr.toString();
let id = setTimeout(() => {
s = s.replace(reg, "");
comp.string = s;
if (s.length === str.length) {
resolve();
}
}, time / str.length * 1000 * i);
timerIds.push(id);
}
});
}
AnimationUtils.ActionTypeWriter = ActionTypeWriter;
let animTime = 0.3;
/**
*
* @param maskNode 遮罩node
* @param mainNode 所有内容node
* @param params callback:执行完成后的回调,maskNodeOpacityValue遮罩node的opacity值
*/
function showUIAnim(mainNode, params = { callback: () => { }, maskNodeOpacityValue: 200 }, maskNode) {
mainNode.scale = 0;
mainNode.active = true;
// 播放背景动画
let opacityValue = params.maskNodeOpacityValue;
if (maskNode) {
maskNode.opacity = 0;
maskNode.active = true;
cc.tween(maskNode)
.to(animTime * 0.8, { opacity: opacityValue })
.call(() => {
})
.start();
}
// 播放主体动画
cc.tween(mainNode)
.to(animTime, { scale: 1 }, { easing: 'backOut' })
.call(() => {
// 弹窗已完全展示(动画完毕)
if (params.callback)
params.callback();
})
.start();
}
AnimationUtils.showUIAnim = showUIAnim;
/**
*
* @param parentNode 该组件挂载的node
* @param maskNode 遮罩node
* @param mainNode 所有内容node
* @param params callback:执行完成后的回调,maskNodeOpacityValue遮罩node的opacity值
*/
function hideUIAnim(parentNode, mainNode, params = { callback: () => { } }, maskNode) {
// 拦截点击事件
let blocker = parentNode.getChildByName("blocker");
if (!blocker) {
blocker = new cc.Node('blocker');
blocker.addComponent(cc.BlockInputEvents);
blocker.setParent(parentNode);
blocker.setContentSize(parentNode.getContentSize());
}
blocker.active = true;
if (maskNode) {
// 播放背景动画
cc.tween(maskNode)
.delay(animTime * 0.2)
.to(animTime * 0.8, { opacity: 0 })
.call(() => {
})
.start();
}
// 播放主体动画
cc.tween(mainNode)
.to(animTime, { scale: 0 }, { easing: 'backIn' })
.call(() => {
blocker.active = false;
if (params.callback)
params.callback();
})
.start();
}
AnimationUtils.hideUIAnim = hideUIAnim;
})(AnimationUtils = exports.AnimationUtils || (exports.AnimationUtils = {}));
cc._RF.pop();