cde0e608-3a09-4f9a-bc95-9aee3115c34f.js
23 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
"use strict";
cc._RF.push(module, 'cde0eYIOglPmryVmu4xFcNP', 'DatingSceneViewImpl');
// script/game/ui/view/impl/dating/DatingSceneViewImpl.ts
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DatingSceneViewImpl = exports.AutoPlayType = exports.AutoPlayState = void 0;
const CCViewBase_1 = require("../../../../../common/classbase/CCViewBase");
const DatingSceneView_1 = require("../../type/DatingSceneView");
const PresenterCCViewFactory_1 = require("../../../PresenterCCViewFactory");
const CCDummyObjects_1 = require("../../../../../common/CCDummyObjects");
const simba_cc_resutils_1 = require("simba-cc-resutils");
const Typewriter_1 = require("../../../../../common/components/Typewriter");
const PortraitFixComponent_1 = require("../../../../../common/components/PortraitFixComponent");
const GameConfig_1 = require("../../../../../GameConfig");
const GameModelManager_1 = require("../../../../model/GameModelManager");
const { ccclass, property } = cc._decorator;
var AutoPlayState;
(function (AutoPlayState) {
AutoPlayState[AutoPlayState["Close"] = 0] = "Close";
AutoPlayState[AutoPlayState["AutoPlay"] = 1] = "AutoPlay";
})(AutoPlayState = exports.AutoPlayState || (exports.AutoPlayState = {}));
var AutoPlayType;
(function (AutoPlayType) {
AutoPlayType[AutoPlayType["Skip"] = 0] = "Skip";
AutoPlayType[AutoPlayType["Speedx1"] = 1] = "Speedx1";
})(AutoPlayType = exports.AutoPlayType || (exports.AutoPlayType = {}));
let DatingSceneViewImpl = /** @class */ (() => {
let DatingSceneViewImpl = class DatingSceneViewImpl extends CCViewBase_1.CCView {
constructor() {
super(...arguments);
//#region editor bindings
this.backgroundSprite = CCDummyObjects_1.DummySprite;
this.effectBackgroundSprite = CCDummyObjects_1.DummySprite;
this.portraitSprite = CCDummyObjects_1.DummySprite;
this.selfSmallPortrait = CCDummyObjects_1.DummySprite;
this.otherDialogNode = CCDummyObjects_1.DummyNode;
this.selfDialogNode = CCDummyObjects_1.DummyNode;
this.narratorDialogNode = CCDummyObjects_1.DummyNode;
this.backRedDot = CCDummyObjects_1.DummyNode;
this.backBtnNode = CCDummyObjects_1.DummyNode;
this.endTipNode = CCDummyObjects_1.DummyNode;
this.arrowguideNode = CCDummyObjects_1.DummyNode;
this.otherNameSpr = CCDummyObjects_1.DummySprite;
this.typewriter = undefined;
this.chapterBtn = CCDummyObjects_1.DummyPrefab;
this.skipButtonNode = CCDummyObjects_1.DummyNode;
this.autoPlayButtonNode = CCDummyObjects_1.DummyNode;
this.autoPlaySpriteFrame = [];
this._originPos = cc.v3(-265, 68, 0);
this._isRunCloseAction = false;
this._isRunningAction = false;
this._contentText = "";
this._autoPlayTimer = -1;
this._skipButtonState = 0;
this._autoPlayButtonState = 0;
this._autoPlayState = -1;
this._autoPlaySpeed = 1;
this._textTyperIsOver = true;
this._isSpecialEffect = false;
this.setIsRunningAction = (isRunning) => {
this._isRunningAction = isRunning;
};
/**
* 背景监听回调
*/
this.touchEndHandler = async () => {
if (this._autoPlayState == AutoPlayState.Close) {
if (this.typewriter.getShowingString() == "") {
if (this.completePlotCallback)
await this.completePlotCallback();
}
else {
this.typewriter.stopTyperShowString();
}
}
};
this.getChapterBtn = () => {
return this.chapterBtn;
};
}
/**
* 是否显示返回按钮
* @param show bool
*/
showBackBtn(show) {
this.backBtnNode.active = show;
if (show) {
this.backBtnNode.getComponent(cc.Widget).updateAlignment();
}
}
closeAction() {
GameModelManager_1.GameModelManager.setIsMainPlotSceneType(false);
GameConfig_1.GameConfig.isVerb = false;
//清除自动播放计时器
clearTimeout(this._autoPlayTimer);
if (this._isRunCloseAction) {
this.runCloseAction();
}
else if (!this._isRunningAction) {
this.closeView();
}
}
closeView() {
this.backgroundSprite.spriteFrame = undefined;
this.portraitSprite.spriteFrame = undefined;
this.selfSmallPortrait.spriteFrame = undefined;
this.otherDialogNode.active = false;
this.selfDialogNode.active = false;
this.narratorDialogNode.active = false;
this.backRedDot.active = false;
this.backBtnNode.active = true;
this.endTipNode.stopAllActions();
this.endTipNode.active = false;
this.endTipNode.position = this._originPos;
this.endTipNode.opacity = 255;
this._isRunCloseAction = false;
// this.closeActNode.active = false;
this._isRunningAction = false;
this.arrowguideNode.active = false;
this.close();
}
onEnable() {
this.resetAutoPlayButtonState();
this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
}
onDisable() {
this.node.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
}
/**引导返回 */
guideBack() {
this.runEndTipAction();
}
/**
* 设置约会场景内容
* @param isSelf 是否是自身
* @param text 文本内容
* @param nameSpr
* @param name 别人名字
* @param portraitImg 立绘图名字
* @param otherPortraitImg 其他立绘图名字
* @param showRouge 是否显示口红
*/
async setContent(isSelf, text, nameSpr, name, portraitImg, otherPortraitImg, showRouge) {
let promises = [];
if (!((isSelf && otherPortraitImg) || portraitImg)) { // 防止切换过程中闪
this.portraitSprite.spriteFrame = undefined;
}
if (portraitImg) {
if (isSelf) {
let portraitPath = portraitImg.substring(0, portraitImg.lastIndexOf("/") + 1);
let faceId = portraitImg.substring(portraitImg.lastIndexOf("/") + 1, portraitImg.length);
portraitImg = portraitPath + "1/" + faceId;
}
promises.push(simba_cc_resutils_1.ResUtils.loadRes(portraitImg, cc.SpriteFrame).then((sf) => {
if (this.node.active) {
if (isSelf) {
this.selfSmallPortrait.spriteFrame = sf;
}
else {
this.portraitSprite.spriteFrame = sf;
this.fixScreenSize();
}
}
}));
}
if (isSelf && otherPortraitImg) {
promises.push(simba_cc_resutils_1.ResUtils.loadRes(otherPortraitImg, cc.SpriteFrame).then((sf) => {
this.portraitSprite.spriteFrame = sf;
this.fixScreenSize();
}));
}
if (nameSpr && !isSelf && "" !== nameSpr.trim()) {
promises.push(simba_cc_resutils_1.ResUtils.loadRes(nameSpr, cc.SpriteFrame).then((sf) => {
this.otherNameSpr.spriteFrame = sf;
}));
}
this.otherDialogNode.active = false;
this.selfDialogNode.active = false;
this.narratorDialogNode.active = false;
// let rougeNode = this.selfDialogNode.getChildByName("rouge");
// let perTime = 0.05;
if (text) {
// let time = perTime * text.length;
this._contentText = text;
this._textTyperIsOver = false;
if (isSelf) { // 自己
this.selfDialogNode.active = true;
// this.selfDialogNode.children[0].getComponent(cc.Label).string = name!;
// this.selfDialogNode.children[1].getComponent(cc.RichText).string = text;
this.typewriter.showRichTextTyper(this.selfDialogNode.children[0].getComponent(cc.RichText), text, () => {
this._textTyperIsOver = true;
}, () => { }, this._autoPlaySpeed);
// promises.push(AnimationUtils.ActionTypeWriter(this.selfDialogNode.children[1].getComponent(cc.RichText), text, time));
// if (rougeNode) {
// rougeNode.active = showRouge ? true : false;
// }
}
else if (name) { // 别人
this.otherDialogNode.active = true;
// this.otherDialogNode.children[0].getComponent(cc.Label).string = name!;
// this.otherDialogNode.children[1].getComponent(cc.RichText).string = text;
this.typewriter.showRichTextTyper(this.otherDialogNode.children[0].getComponent(cc.RichText), text, () => {
this._textTyperIsOver = true;
}, () => { }, this._autoPlaySpeed);
// promises.push(AnimationUtils.ActionTypeWriter(this.otherDialogNode.children[1].getComponent(cc.RichText), text, time));
}
else { // 旁白
this.narratorDialogNode.active = true;
// this.narratorDialogNode.children[0].getComponent(cc.RichText).string = text;
this.typewriter.showRichTextTyper(this.narratorDialogNode.children[0].getComponent(cc.RichText), text, () => {
this._textTyperIsOver = true;
}, () => { }, this._autoPlaySpeed);
// promises.push(AnimationUtils.ActionTypeWriter(this.narratorDialogNode.children[0].getComponent(cc.RichText), text, time));
}
}
try {
await Promise.all(promises);
}
catch (e) {
console.error(e);
}
}
resetAutoPlayButtonState() {
this._autoPlaySpeed = 1;
this._autoPlayState = AutoPlayState.Close;
this._skipButtonState = AutoPlayState.Close;
this._autoPlayButtonState = AutoPlayState.Close;
this.changeSkipButtonState(this._autoPlayState);
this.changeAutoPlayButtonState(this._autoPlayState);
}
changeSkipButtonState(state) {
let skipLabel = this.skipButtonNode.getComponentInChildren(cc.Sprite);
if (state == AutoPlayState.Close) {
skipLabel.spriteFrame = this.autoPlaySpriteFrame[2];
}
else {
skipLabel.spriteFrame = this.autoPlaySpriteFrame[3];
}
}
changeAutoPlayButtonState(state) {
let autoPlaySprite = this.autoPlayButtonNode.getComponentInChildren(cc.Sprite);
if (state == AutoPlayState.Close) {
autoPlaySprite.spriteFrame = this.autoPlaySpriteFrame[0];
}
else {
autoPlaySprite.spriteFrame = this.autoPlaySpriteFrame[1];
}
}
/**
* 开始自动播放计时器
* @param startNow 是否不进行延时,立即执行下一步,适用于玩家点击自动播放按钮之后,无需等待
*/
startAutoPlayTimer(startNow = false) {
let interval = 0;
if (!startNow) {
//时间间隔的计算方法,如果startNow为true的话,不进行延时,时间为0,否则:
//(文本长度 * 50ms / this._autoPlaySpeed)表示文本走完打字机效果所需要的时间
//(文本长度 * 60ms / this._autoPlaySpeed)表示文本完全展示之后展示停留的时间
interval = ((this._contentText.length * 50) / this._autoPlaySpeed) + ((this._contentText.length * 60) / this._autoPlaySpeed);
}
this._autoPlayTimer = window.setTimeout(async () => {
if (this._autoPlayState == AutoPlayState.AutoPlay) {
if (this._textTyperIsOver && !this._isSpecialEffect) {
if (this.completePlotCallback)
await this.completePlotCallback();
}
this.startAutoPlayTimer();
}
else {
clearTimeout(this._autoPlayTimer);
}
}, interval);
}
fixScreenSize() {
let comp = this.portraitSprite.node.getComponent(PortraitFixComponent_1.default);
if (comp) {
comp.fixScreenSize(true);
}
}
/**
* 设置背景
* @param bgImage 背景路径
*/
async setBackground(bgImage) {
if (!bgImage) {
this.backgroundSprite.spriteFrame = undefined;
}
else {
try {
this.backgroundSprite.node.opacity = 255;
let sf = await simba_cc_resutils_1.ResUtils.loadRes(bgImage, cc.SpriteFrame);
this.backgroundSprite.spriteFrame = sf;
this.backgroundSprite.node.height = this.node.height;
this.backgroundSprite.node.width = sf.getOriginalSize().width / sf.getOriginalSize().height * this.node.height;
}
catch (e) {
console.error(e);
}
}
}
/**
* 设置背景(特殊效果)
* @param bgImage 背景路径
*/
async setBackgroundEffect(bgImage) {
this._isSpecialEffect = true;
let dialogNodesActive = [this.otherDialogNode.active, this.selfDialogNode.active, this.narratorDialogNode.active];
this.otherDialogNode.active = false;
this.selfDialogNode.active = false;
this.narratorDialogNode.active = false;
if (!bgImage) {
this.backgroundSprite.node.opacity = 255;
cc.tween(this.backgroundSprite.node)
.to(1, { opacity: 0 })
.call(() => {
this.backgroundSprite.spriteFrame = undefined;
this.otherDialogNode.active = dialogNodesActive[0];
this.selfDialogNode.active = dialogNodesActive[1];
this.narratorDialogNode.active = dialogNodesActive[2];
}).start();
if (this.backgroundSprite.spriteFrame) {
this.effectBackgroundSprite.node.active = true;
this.effectBackgroundSprite.node.opacity = 255;
cc.tween(this.effectBackgroundSprite.node)
.to(1, { opacity: 0 })
.call(() => {
this.effectBackgroundSprite.node.active = false;
this._isSpecialEffect = false;
}).start();
}
}
else {
try {
this.effectBackgroundSprite.node.active = true;
this.effectBackgroundSprite.node.opacity = 0;
cc.tween(this.effectBackgroundSprite.node)
.to(1, { opacity: 255 })
.call(() => {
cc.tween(this.effectBackgroundSprite.node)
.to(1, { opacity: 0 })
.call(() => {
this.effectBackgroundSprite.node.active = false;
}).start();
}).start();
cc.tween(this.backgroundSprite.node)
.to(1, { opacity: 0 })
.call(async () => {
let sf = await simba_cc_resutils_1.ResUtils.loadRes(bgImage, cc.SpriteFrame);
this.backgroundSprite.spriteFrame = sf;
this.backgroundSprite.node.height = this.node.height;
this.backgroundSprite.node.width = sf.getOriginalSize().width / sf.getOriginalSize().height * this.node.height;
cc.tween(this.backgroundSprite.node)
.to(1, { opacity: 255 })
.call(() => {
this.otherDialogNode.active = dialogNodesActive[0];
this.selfDialogNode.active = dialogNodesActive[1];
this.narratorDialogNode.active = dialogNodesActive[2];
this._isSpecialEffect = false;
}).start();
}).start();
}
catch (e) {
console.error(e);
}
}
}
runEndTipAction() {
this.setIsRunningAction(true);
let offsetY = 300;
let actTime = 1.5;
this.endTipNode.stopAllActions();
this.endTipNode.active = true;
this.endTipNode.scale = 1;
this.endTipNode.opacity = 255;
this.endTipNode.position = cc.v3(-265, this._originPos.y - offsetY, 0);
this.endTipNode.opacity = 0;
let ease = cc.easeSineInOut();
let moveAct = cc.moveTo(actTime, cc.v2(-265, this._originPos.y)).easing(ease);
let fadeInAct = cc.fadeIn(actTime).easing(ease);
let spawn = cc.spawn(moveAct, fadeInAct);
let call = cc.callFunc(() => {
this.backRedDot.active = true;
// if (!this._isRunCloseAction) {
// SDK.showInterstitialAd();
// }
this.setIsRunningAction(false);
});
let showArrowGuideCall = cc.callFunc(() => {
this.arrowguideNode.active = true;
});
let actTime2 = 2;
let seq = cc.sequence(spawn, call, cc.spawn(cc.moveTo(1, cc.v2(this.backBtnNode.position.x, this.backBtnNode.position.y)), cc.scaleTo(actTime2, 0)), showArrowGuideCall);
this.endTipNode.runAction(seq);
}
setRunCloseAction(run) {
this._isRunCloseAction = run;
}
runCloseAction() {
this.closeView();
}
onRefreshAllStatus() {
this.closeAction();
}
onReviewButtonClick() {
this.resetAutoPlayButtonState();
clearTimeout(this._autoPlayTimer);
this.onReviewButtonClickCallback();
}
onSkipButtonClick() {
this._skipButtonState = this._skipButtonState == AutoPlayState.Close ? AutoPlayState.AutoPlay : AutoPlayState.Close;
this._autoPlayState = this._skipButtonState;
if (this._autoPlayState == AutoPlayState.AutoPlay) {
this._autoPlaySpeed = 20;
this.startAutoPlayTimer(true);
this.changeSkipButtonState(this._autoPlayState);
this.changeAutoPlayButtonState(AutoPlayState.Close);
this._autoPlayButtonState = AutoPlayState.Close;
}
else {
this.resetAutoPlayButtonState();
clearTimeout(this._autoPlayTimer);
}
}
onAutoPlayButtonClick() {
this._autoPlayButtonState = this._autoPlayButtonState == AutoPlayState.Close ? AutoPlayState.AutoPlay : AutoPlayState.Close;
this._autoPlayState = this._autoPlayButtonState;
if (this._autoPlayState == AutoPlayState.AutoPlay) {
this._autoPlaySpeed = 1;
this.startAutoPlayTimer(true);
this.changeSkipButtonState(AutoPlayState.Close);
this.changeAutoPlayButtonState(this._autoPlayState);
this._skipButtonState = AutoPlayState.Close;
}
else {
this.resetAutoPlayButtonState();
clearTimeout(this._autoPlayTimer);
}
}
};
__decorate([
property(cc.Sprite)
], DatingSceneViewImpl.prototype, "backgroundSprite", void 0);
__decorate([
property(cc.Sprite)
], DatingSceneViewImpl.prototype, "effectBackgroundSprite", void 0);
__decorate([
property(cc.Sprite)
], DatingSceneViewImpl.prototype, "portraitSprite", void 0);
__decorate([
property(cc.Sprite)
], DatingSceneViewImpl.prototype, "selfSmallPortrait", void 0);
__decorate([
property(cc.Node)
], DatingSceneViewImpl.prototype, "otherDialogNode", void 0);
__decorate([
property(cc.Node)
], DatingSceneViewImpl.prototype, "selfDialogNode", void 0);
__decorate([
property(cc.Node)
], DatingSceneViewImpl.prototype, "narratorDialogNode", void 0);
__decorate([
property(cc.Node)
], DatingSceneViewImpl.prototype, "backRedDot", void 0);
__decorate([
property(cc.Node)
], DatingSceneViewImpl.prototype, "backBtnNode", void 0);
__decorate([
property(cc.Node)
], DatingSceneViewImpl.prototype, "endTipNode", void 0);
__decorate([
property(cc.Node)
], DatingSceneViewImpl.prototype, "arrowguideNode", void 0);
__decorate([
property(cc.Sprite)
], DatingSceneViewImpl.prototype, "otherNameSpr", void 0);
__decorate([
property(Typewriter_1.default)
], DatingSceneViewImpl.prototype, "typewriter", void 0);
__decorate([
property(cc.Prefab)
], DatingSceneViewImpl.prototype, "chapterBtn", void 0);
__decorate([
property(cc.Node)
], DatingSceneViewImpl.prototype, "skipButtonNode", void 0);
__decorate([
property(cc.Node)
], DatingSceneViewImpl.prototype, "autoPlayButtonNode", void 0);
__decorate([
property([cc.SpriteFrame])
], DatingSceneViewImpl.prototype, "autoPlaySpriteFrame", void 0);
DatingSceneViewImpl = __decorate([
ccclass,
PresenterCCViewFactory_1.RegView(DatingSceneView_1.DatingSceneViewType, "prefab/ui/DatingSceneView")
], DatingSceneViewImpl);
return DatingSceneViewImpl;
})();
exports.DatingSceneViewImpl = DatingSceneViewImpl;
cc._RF.pop();