22676a95-dd5b-47a3-95bc-d81b675c15b3.js
17.3 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
"use strict";
cc._RF.push(module, '22676qV3VtHo5W82BtnXBWz', 'ChatBubbleView');
// script/game/ui/view/impl/message/ChatBubbleView.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 });
const simba_cc_audio_manager_1 = require("simba-cc-audio-manager");
const simba_cc_resutils_1 = require("simba-cc-resutils");
const simba_config_manager_1 = require("simba-config-manager");
const AVG_1 = require("../../../../../avg/AVG");
// import { DailyQuestType } from "../../../../../avg/EditorEnums";
const CCDummyObjects_1 = require("../../../../../common/CCDummyObjects");
const GameTextData_1 = require("../../../../../common/gameplay/gamedata/GameTextData");
const UIManager_1 = require("../../../../../common/gameplay/managers/UIManager");
const CharacterVoiceConfig_1 = require("../../../../../config/CharacterVoiceConfig");
const Enums_1 = require("../../../../Enums");
const GameModelManager_1 = require("../../../../model/GameModelManager");
const AlertDialogViewPresenter_1 = require("../../../presenter/AlertDialogViewPresenter");
const ImagePreviewPresenter_1 = require("../../../presenter/message/ImagePreviewPresenter");
const { ccclass, property } = cc._decorator;
const BASE_DELAY = 1;
const PER_CHAR_DELAY = 0.1;
let ChatBubbleView = /** @class */ (() => {
let ChatBubbleView = class ChatBubbleView extends cc.Component {
constructor() {
super(...arguments);
//#region editor bindings
this.iconSprite = CCDummyObjects_1.DummySprite;
this.nameSpr = CCDummyObjects_1.DummySprite;
this.textContentLabel = CCDummyObjects_1.DummyRichText;
this.inputtingNode = undefined;
this.contentNode = CCDummyObjects_1.DummyNode;
this.bgNode = CCDummyObjects_1.DummyNode;
this.imageSprite = undefined;
this.container = undefined;
this.voiceNode = CCDummyObjects_1.DummyNode;
this.voiceLabel = CCDummyObjects_1.DummyLabel;
this.playVoice = () => {
var _a;
if (this._voicePath) {
(_a = this.contentNode.children[1].getComponent(cc.Animation)) === null || _a === void 0 ? void 0 : _a.play("voice_play");
simba_cc_audio_manager_1.AudioManager.playVoice(this._voicePath).then(() => {
var _a;
(_a = this.contentNode.children[1].getComponent(cc.Animation)) === null || _a === void 0 ? void 0 : _a.play("voice_stop");
});
}
};
}
onVoiceClick() {
if (this._voiceCfg) {
let needAd = GameModelManager_1.GameModelManager.checkVoiceNeedShowAD(this._voiceCfg);
if (needAd) {
this.showVoiceAdAlert();
}
else {
this.playVoice();
}
}
}
autoPopVoiceDialog(isCheckContent = true) {
if (this._voiceCfg) {
if (isCheckContent) {
let needAd = GameModelManager_1.GameModelManager.checkVoiceNeedShowAD(this._voiceCfg);
if (needAd) {
this.showVoiceAdAlert();
}
}
else {
this.showVoiceAdAlert();
}
}
}
showVoiceAdAlert() {
let temp = {
dataptr: {},
titlecontent: GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_VOICE_TITLE_VALUE),
content: GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_VOICE_CONTENT_VALUE),
ishasad: true,
istwobtn: true,
adconfig: "inject_fruit",
// items: [],
location: Enums_1.CommonLocation.Audio,
hasBanner: false,
callback: (type, ret) => {
if (ret) {
GameModelManager_1.GameModelManager.pushVoiceShowAdToRecord(this._voiceCfg.id);
this.playVoice();
if (type === "video") {
// GameModelManager.addDailyTasks(DailyQuestType.Dq_AdsWatch, 1);
}
}
}
};
UIManager_1.UIManager.pushPresenter(AlertDialogViewPresenter_1.default, temp);
}
previewImage() {
UIManager_1.UIManager.pushPresenter(ImagePreviewPresenter_1.ImagePreviewPresenter, this._previewImage);
}
delay(time) {
return new Promise((resolve) => {
this._timer = setTimeout(() => {
this._timer = undefined;
resolve(null);
}, time * 1000);
});
}
init() {
this._nodeHeight = this.node.height;
this._bgWidth = this.bgNode.width;
this._bgHeight = this.bgNode.height;
this._textHeight = this.textContentLabel.node.height;
}
reuse() {
if (this._timer) {
clearTimeout(this._timer);
this._timer = undefined;
}
if (this._nodeHeight === undefined)
return;
if (this._extraNode) {
this._extraNode.removeFromParent(true);
this._extraNode = undefined;
}
this.node.height = this._nodeHeight;
this.bgNode.width = this._bgWidth;
this.bgNode.height = this._bgHeight;
this.textContentLabel.string = "";
this._previewImage = "";
this.bgNode.active = true;
this.voiceLabel.string = "";
this._voiceCfg = undefined;
this._voicePath = "";
if (this.imageSprite)
this.imageSprite.node.parent.active = false;
}
async resizeContent() {
// console.log("resizeContent begin");
if (this._previewImage) { // 图片类型
let sf = this.imageSprite.spriteFrame;
let width = this.imageSprite.node.width = Math.max(sf.getOriginalSize().width, 200);
this.imageSprite.node.height = width / sf.getOriginalSize().width * sf.getOriginalSize().height;
this.node.height = -this.imageSprite.node.y + this.imageSprite.node.height + 40;
}
else {
this.textContentLabel.node.active = true;
this.textContentLabel.maxWidth = 0;
// while (!this.enabledInHierarchy) {
// if (!this.enabled) return;
// await this.delay(0.5);
// }
let mw = 440;
if (mw < this.textContentLabel.node.width) {
this.textContentLabel.maxWidth = mw;
}
this.bgNode.height = this.textContentLabel.node.height + 70;
if (this._voiceCfg) {
this.voiceNode.y = this.bgNode.height / 2 * (-1);
}
this.node.height = this.bgNode.height + this._textHeight;
let gapW = 120;
if (this.bgNode.anchorX == 0) {
if (this._voiceCfg) {
this.bgNode.width = this.voiceLabel.node.x + this.voiceLabel.node.width + gapW + 32;
}
else {
this.bgNode.width = this.textContentLabel.node.x + this.textContentLabel.node.width + gapW;
}
}
else {
if (this._voiceCfg) {
this.bgNode.width = -this.voiceLabel.node.x + this.voiceLabel.node.width + gapW + 32;
}
else {
this.bgNode.width = -this.textContentLabel.node.x + this.textContentLabel.node.width + gapW;
}
}
this.node.height = this.bgNode.height + this.nameSpr.node.height;
}
// console.log("resizeContent end");
}
setName(name) {
// console.log("setName begin");
// this.nameLabel.string = name;
// console.log("setName end");
}
setNameIcon(icon) {
this.nameSpr.spriteFrame = new cc.SpriteFrame();
if (icon && "" !== icon.trim()) {
simba_cc_resutils_1.ResUtils.loadRes(icon, cc.SpriteFrame).then((sf) => {
this.nameSpr.spriteFrame = sf;
});
}
}
setIcon(icon) {
if (icon && this._icon !== icon) {
this._icon = icon;
simba_cc_resutils_1.ResUtils.loadRes(icon, cc.SpriteFrame).then((sf) => {
if (this._icon === icon)
this.iconSprite.spriteFrame = sf;
});
}
}
setText(txt) {
// console.log("setText begin");
this.textContentLabel.string = txt;
// console.log("setText end");
}
setExtraContent(node) {
if (this.container) {
let pre = this.container.getChildByName("LikeTip");
if (pre) {
this.container.removeChild(pre, true);
}
node.name = "LikeTip";
node.active = true;
this.container.addChild(node);
}
}
updateVoiceLastTime() {
this.voiceLabel.string = this._voiceCfg.last + "''";
}
async setContent(plotId, content, select, shouldDelay = false) {
// console.log("setContent begin");
if (this._nodeHeight === undefined)
this.init();
let textCount = 0;
let setContent1 = async (pid, content) => {
if (content.type === AVG_1.SentenceType.TEXT) {
textCount = AVG_1.richNodeTextCount(content.value);
let str = AVG_1.richNodesToCocosString(content.value);
this.textContentLabel.string = str;
this.contentNode.children[0].active = true;
this.contentNode.children[1].active = false;
this.contentNode.children[2].active = false;
}
else if (content.type === AVG_1.SentenceType.AUDIO) {
let cfg = simba_config_manager_1.ConfigManager.getConfig(CharacterVoiceConfig_1.characterVoiceConfig, parseInt(content.value));
if (cfg) {
this._voiceCfg = cfg;
this._voicePath = cfg.name;
this.updateVoiceLastTime();
this.contentNode.children[0].active = false;
this.contentNode.children[1].active = true;
this.contentNode.children[2].active = false;
let hasAd = cfg.ads === 1;
let needAd = GameModelManager_1.GameModelManager.checkVoiceNeedShowAD(this._voiceCfg);
if (hasAd && needAd) {
let curMainLinePlotId = GameModelManager_1.GameModelManager.getCurMainLinePlotId();
if (curMainLinePlotId === pid) {
this.autoPopVoiceDialog(false);
}
}
}
}
else if (content.type === AVG_1.SentenceType.IMAGE && this.imageSprite) {
this.contentNode.children[0].active = false;
this.contentNode.children[1].active = false;
this.contentNode.children[2].active = true;
if (content.value) {
this._previewImage = "textures/stickers/" + content.value;
let thumb = "textures/stickers/thumb/" + content.value;
let info = cc.resources.getInfoWithPath(thumb);
// console.log("getInfoWithPath", info);
if (!info) {
thumb = this._previewImage;
}
try {
await simba_cc_resutils_1.ResUtils.loadRes(thumb, cc.SpriteFrame).then((sf) => {
// if (this.imageSprite!.node.activeInHierarchy) {
this.imageSprite.spriteFrame = sf;
// }
});
}
catch (e) {
}
}
}
else {
console.error("content type not supported yet.");
}
};
let inputtingForever = false;
let promise = undefined;
if (content.type === AVG_1.SentenceType.SELECT) {
if (select === undefined) {
inputtingForever = true;
}
else {
let option = content.value[select];
if (option.content) {
promise = setContent1(plotId, option.content);
}
else {
this.contentNode.children[0].active = true;
this.contentNode.children[1].active = false;
this.textContentLabel.string = option.summary;
}
}
}
else {
promise = setContent1(plotId, content);
}
if (this.inputtingNode) {
if (shouldDelay || inputtingForever) {
this.inputtingNode.active = true;
this.contentNode.active = false;
this.inputtingNode.children[0].runAction(cc.repeatForever(cc.rotateBy(1, 360)));
if (inputtingForever)
return;
if (promise)
await promise;
await this.delay(BASE_DELAY + PER_CHAR_DELAY * textCount);
// return new Promise<void>((resolve) => {
// this.scheduleOnce(() => {
this.inputtingNode.children[0].stopAllActions();
this.inputtingNode.active = false;
this.contentNode.active = true;
if (this._previewImage)
this.bgNode.active = false;
this.resizeContent();
// resolve();
// }, BASE_DELAY + PER_CHAR_DELAY * textCount);
// })
}
else {
if (promise)
await promise;
this.inputtingNode.children[0].stopAllActions();
this.inputtingNode.active = false;
this.contentNode.active = true;
if (this._previewImage)
this.bgNode.active = false;
this.resizeContent();
}
}
// console.log("setContent end");
}
clearInputting() {
if (this._timer) {
clearTimeout(this._timer);
this._timer = undefined;
if (this.inputtingNode) {
this.inputtingNode.children[0].stopAllActions();
this.inputtingNode.active = false;
}
this.contentNode.active = true;
this.resizeContent();
}
}
};
__decorate([
property({ type: cc.Sprite })
], ChatBubbleView.prototype, "iconSprite", void 0);
__decorate([
property({ type: cc.Sprite })
], ChatBubbleView.prototype, "nameSpr", void 0);
__decorate([
property({ type: cc.RichText })
], ChatBubbleView.prototype, "textContentLabel", void 0);
__decorate([
property({ type: cc.Node })
], ChatBubbleView.prototype, "inputtingNode", void 0);
__decorate([
property({ type: cc.Node })
], ChatBubbleView.prototype, "contentNode", void 0);
__decorate([
property({ type: cc.Node })
], ChatBubbleView.prototype, "bgNode", void 0);
__decorate([
property({ type: cc.Sprite })
], ChatBubbleView.prototype, "imageSprite", void 0);
__decorate([
property({ type: cc.Node })
], ChatBubbleView.prototype, "container", void 0);
__decorate([
property({ type: cc.Node })
], ChatBubbleView.prototype, "voiceNode", void 0);
__decorate([
property({ type: cc.Label })
], ChatBubbleView.prototype, "voiceLabel", void 0);
ChatBubbleView = __decorate([
ccclass
], ChatBubbleView);
return ChatBubbleView;
})();
exports.default = ChatBubbleView;
cc._RF.pop();