cc2ae273-cdb2-44c9-bdb2-c7cc3d991f47.js
28 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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
"use strict";
cc._RF.push(module, 'cc2aeJzzbJEyb2yx8w9mR9H', 'ChatListViewPresenter');
// script/game/ui/presenter/ChatListViewPresenter.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.ChatListViewPresenter = void 0;
const simba_cc_audio_manager_1 = require("simba-cc-audio-manager");
const simba_config_manager_1 = require("simba-config-manager");
const simba_eventkit_1 = require("simba-eventkit");
const simba_utils_1 = require("simba-utils");
const AVG_1 = require("../../../avg/AVG");
const EditorEnums_1 = require("../../../avg/EditorEnums");
const PresenterBase_1 = require("../../../common/classbase/PresenterBase");
const GameTextData_1 = require("../../../common/gameplay/gamedata/GameTextData");
const UIManager_1 = require("../../../common/gameplay/managers/UIManager");
const StringUtils_1 = require("../../../common/utils/StringUtils");
const RelationLevelConfig_1 = require("../../../config/RelationLevelConfig");
const Role_1 = require("../../../config/Role");
const Enums_1 = require("../../Enums");
const GameDotMgr_1 = require("../../GameDotMgr");
const GameModelManager_1 = require("../../model/GameModelManager");
const PresenterCCViewFactory_1 = require("../PresenterCCViewFactory");
const ChatListView_1 = require("../view/type/ChatListView");
const GuideViewPresenter_1 = require("./GuideViewPresenter");
const SentenceSelectorViewPresenter_1 = require("./SentenceSelectorViewPresenter");
const MAX_HISTORY = 50;
let ChatListViewPresenter = /** @class */ (() => {
let ChatListViewPresenter = class ChatListViewPresenter extends PresenterBase_1.Presenter {
constructor() {
super();
this._historyMessages = {};
this._currPlotShowed = false;
this._itemKey = 0;
this._plotExecuting = false;
this._excutedPlots = {};
this._gLevelMax = -1;
this._cachePId = NaN;
this.onSelectIndexCallback = (index) => {
this.selectSentence(index);
};
this.onSetContent = (content) => {
if (content != undefined) {
let props = {
sentence: content,
backgroundpath: "textures/message/selector_bg",
clickcausehide: false,
onSelectIndexCallback: this.onSelectIndexCallback
};
UIManager_1.UIManager.pushPresenter(SentenceSelectorViewPresenter_1.default, props);
let t = GameModelManager_1.GameModelManager.checkIsDotTutorial();
if (t) {
let plotScenTypeSession = AVG_1.GameRecord.globalVariables["p_s_t_s" + Enums_1.PlotSceneType.Message];
GameDotMgr_1.default.getInstance().dotTutorial(Enums_1.TutorialType.Message, Enums_1.TutorialState.SelectSentence, { session: plotScenTypeSession, plotId: this._currPlot.id });
}
}
};
this.isSentenceSelectVisible = () => {
let preset = UIManager_1.UIManager.getTopPresenter();
if (preset instanceof SentenceSelectorViewPresenter_1.default) {
let selectorPresenter = preset;
return !selectorPresenter.view.isHidden;
}
return false;
};
this.closeAction = () => {
if (this._plotExecuting)
return;
UIManager_1.UIManager.popToPresenter(this);
this._view.closeAnimation().then(() => {
this._view.close();
GameModelManager_1.GameModelManager.CheckMainTabGuide.emit();
});
};
this.selectChapter = () => {
};
this.selectSentence = (index) => {
if (!this._currPlot)
throw new Error("ChatList: ePlot error! No currnt plot!");
// let t = GameModelManager.checkIsDotTutorial();
// if (t) {
// let plotScenTypeSession = GameRecord.globalVariables["p_s_t_s" + PlotSceneType.Message] as number;
// GameDotMgr.getInstance().dotTutorial(TutorialType.Message, TutorialState.SelectSentenceRet, { session: plotScenTypeSession, plotId: this._currPlot!.id, select: index });
// }
this.completePlot(index, ChatListView_1.ChatListAutoNextPlot);
};
this.showCurrPlot = async () => {
if (this._currPlot && !this._excutedPlots[this._currPlot.id] && !this._plotExecuting && !this._currPlotShowed) {
let item = this.convertPlotToViewModel(this._currPlot);
if (item && this._currPlot.sentences[0].roleId !== 1 && item.type !== "customplot") { // 除了旁白,扣体力
if (!await GameModelManager_1.GameModelManager.plotUseEnergy(this._currPlot.id)) {
return;
}
if (!this._currPlot)
return;
}
this._excutedPlots[this._currPlot.id] = true;
this._plotExecuting = true;
let disposable = new simba_eventkit_1.CompositeDisposable;
this._plotChangeLike = undefined;
AVG_1.GameRecord.onRecordVariableChange("like" + this._currPlot.sentences[0].roleId, (scope, varName, preValue, value) => {
this._plotChangeLike = value - preValue;
});
await AVG_1.ActionManager.executeActions(this._currPlot.sentences[0].actions); // TODO 处理加好感
disposable.dispose();
this._plotExecuting = false;
if (item) {
if (this._chatList.length > MAX_HISTORY) {
this._chatList.shift();
}
let exist = false;
for (let i = 0; i < this._chatList.length; i++) {
if (this._chatList[i]["id"] === item["id"]) {
exist = true;
break;
}
}
if (!exist) {
this._chatList.push(item);
}
if ((item.type === "plot" || item.type === "customplot") && this._plotChangeLike && this._plotChangeLike !== NaN) {
item.addLike = this._plotChangeLike;
}
this._view.updateProps({ items: this._chatList });
}
this._currPlotShowed = true;
let effectName = "se_npc_send";
if (this._currPlot && this._currPlot.sentences[0].roleId === GameModelManager_1.GameModelManager.getPlayerData().getConfig().id) {
effectName = "se_player_send";
}
simba_cc_audio_manager_1.AudioManager.playEffect(effectName);
}
else if (this._currPlot && this._excutedPlots[this._currPlot.id]) {
this._currPlotShowed = true;
}
};
this.completePlot = async (index, proceedNext = true) => {
if (!this._currPlot)
return;
if (!this._currPlotShowed) {
this.showCurrPlot();
return;
}
GameModelManager_1.GameModelManager.setIsMainPlotSceneType(true);
if (index !== undefined) { // 刷新界面剧情选择
let lastItem = this._chatList.pop();
if (lastItem.type === "plot") {
this._chatList.push(Object.assign(Object.assign({}, lastItem), { select: index }));
}
else {
throw new Error("ChatList: Plot error!");
}
this._view.updateProps({ items: this._chatList });
}
// await this.execCurrPlot(); // 改为开始的时候执行
if (proceedNext) {
this.sceneModel.lastPlot = this._currPlot;
if (this._selectIndex !== undefined) {
index = this._selectIndex;
this._selectIndex = undefined;
}
if (ChatListView_1.ChatListAutoNextPlot)
await simba_utils_1.delay(0.5);
await this.nextPlot(index);
}
else {
this._selectIndex = index;
}
};
this.nextPlot = async (index) => {
if (this.isClosed())
return;
if (this._currPlot) {
GameModelManager_1.GameModelManager.dotPlotProgress();
await AVG_1.PlotManager.completePlot(this._currPlot, index, this._plotChangeLike ? { addlike: this._plotChangeLike } : undefined);
}
else {
console.error("ChatList: Plot error! No current plot!");
}
};
this.convertPlotToViewModel = (plot, select, customData) => {
var _a, _b;
let role = GameModelManager_1.GameModelManager.getRoleData(plot.sentences[0].roleId);
let content = plot.sentences[0].content;
if (plot.id >= 0) {
if (!content)
return undefined;
let nameSpr = role.getNameIcon();
if (role.getConfig().id === 3) {
nameSpr = "/textures/name_icon/laoda";
}
return { id: plot.id, key: (this._itemKey++).toString(), type: "plot", nameSpr: nameSpr, name: role.getConfig().RoleType === EditorEnums_1.RoleType.Role_Blank ? "" : role.getConfig().name, icon: role.getHeadIcon(), isSelf: role.getConfig().RoleType === EditorEnums_1.RoleType.Role_Player, content, select, addLike: customData ? customData["addlike"] : undefined };
}
else { // custom plot
let giftId = (_a = plot.customData) === null || _a === void 0 ? void 0 : _a.giftId;
if (giftId) { // 送礼
}
else {
if (content && content.type !== AVG_1.SentenceType.SELECT && content.type !== AVG_1.SentenceType.EMPTY) {
let addLike = (_b = plot.customData) === null || _b === void 0 ? void 0 : _b.addLike;
return { id: plot.id, key: (this._itemKey++).toString(), type: "customplot", name: role.getConfig().name, icon: role.getHeadIcon(), isSelf: false, content, addLike };
}
else {
throw new Error("This cannot happen!");
}
}
}
};
this.handlePlotsStart = async (plots) => {
let plot = plots.find(v => v.plotSceneType === Enums_1.PlotSceneType.Message && v.plotSceneTypeId === this._sceneModel.id);
if (plot) {
if (this._currPlot && plot === this._currPlot)
return; // 有分支剧情的情况
this._currPlot = plot;
this._currPlotShowed = false;
await this.showCurrPlot();
}
else if (this._currPlot && this._currPlot.id >= 0) { //剧情结束
this._currPlot = undefined;
this._chatList.push({ key: (this._itemKey++).toString(), type: "end" });
if (this._chatList.length > MAX_HISTORY) {
this._chatList.shift();
}
this._view.updateProps({ items: this._chatList, backRedDot: true });
// this.checkGuideBack();
GameModelManager_1.GameModelManager.dotMainLinePlotEnd();
}
};
this.checkGuideBack = () => {
let r = AVG_1.GameRecord.globalVariables["guide_chat_back"];
r = r ? r : Enums_1.GuideState.Open;
if (r !== Enums_1.GuideState.Open) {
return;
}
let m = this._view.getGuideBackParam();
if (m) {
let location = Enums_1.GuideLocation.ChatBack;
m.call = () => {
AVG_1.GameRecord.globalVariables["guide_chat_back"] = Enums_1.GuideState.Complete;
AVG_1.GameRecord.saveRecord();
this.closeAction();
GameDotMgr_1.default.getInstance().dotGuide(Enums_1.GuideOperationType.Click, location);
};
UIManager_1.UIManager.pushPresenter(GuideViewPresenter_1.default, m);
GameDotMgr_1.default.getInstance().dotGuide(Enums_1.GuideOperationType.Show, location);
}
};
this.onNameTitleClick = () => {
if (!this._sceneModel) {
return;
}
let rids = this._sceneModel.config.roles;
if (!rids.length || rids.length !== 1) {
return;
}
let r = GameModelManager_1.GameModelManager.getRoleData(rids[0]);
if (!r || r.getConfig().RoleType !== EditorEnums_1.RoleType.Role_Major) {
return;
}
let l = r.getRoleLikeLevel();
if (this._gLevelMax < 0) {
this._gLevelMax = this.getGraceLevelMax();
}
if (this._gLevelMax === l.level) {
UIManager_1.UIManager.showToast(GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_GRACE_LEVEL_MAX_VALUE));
}
else {
let v = l.nextLevelLike - l.currLike;
UIManager_1.UIManager.showToast(StringUtils_1.StringUtils.format(GameModelManager_1.GameModelManager.getLanguageTxt(GameTextData_1.GameTextData.GAME_TEXT_GRACE_LEVEL_UP_TIP_VALUE), v));
}
};
// async updateHistoryMessages() {
// this._historyMessages[this._sceneModel.id] = [];
// let historyPlots: ChatListItemProps[] = [];
// let records = GameRecord.getCurrentRecordItems();
// let pushHistory = false;
// let hasHistory = false;
// let lastPlotId: number = Number.MAX_SAFE_INTEGER;
// for (let i = records.length - 1; i >= 0; i--) {
// let item = records[i];
// for (let j = 0; j < item.p.length; j++) {
// let plotId = item.p[j];
// if (plotId === lastPlotId) break;
// let plot = (await getPlot(plotId))! as ReadonlyPlot;
// if (!plot) continue;
// if (plot.plotSceneType === PlotSceneType.Message && plot.plotSceneTypeId === this._sceneModel.id) {
// lastPlotId = plotId;
// if (i === records.length - 1) continue;
// if (pushHistory && !hasHistory) {
// historyPlots.unshift({ key: (this._itemKey++).toString(), type: "history" });
// hasHistory = true;
// }
// let select: number | undefined = undefined;
// if (item.s) select = item.s[j];
// let customData: object | undefined = undefined;
// if (item.c) customData = item.c[j];
// let vm = this.convertPlotToViewModel(plot, select, customData);
// if (vm) historyPlots.unshift(vm);
// } else { // TODO process branch plots if needed.
// if (!pushHistory && !hasHistory) {
// pushHistory = true;
// }
// }
// if (plot.id === this._sceneModel.firstPlot.id) {
// break;
// }
// }
// if (historyPlots.length > MAX_HISTORY) {
// break;
// }
// }
// this._chatList = historyPlots;
// // this._view.updateProps({ items: historyPlots, historyMsgCount: this._chatList.length });
// this._historyMessages[this._sceneModel.id] = this._chatList;
// }
this.onResumeChatListView = () => {
this._chatList = [];
// this._sceneModel = undefined;
this._historyMessages = {};
this._currPlot = undefined;
this._currPlotShowed = false;
this._itemKey = 0;
this._plotExecuting = false;
this._excutedPlots = {};
this._selectIndex = undefined;
this._plotChangeLike = 0;
this._viewProps = {
msgSceneId: -1, title: "",
items: [], historyMsgCount: 0,
onCloseBtnClick: this.closeAction,
onSelectChapter: this.selectChapter,
onCompletePlot: this.completePlot,
onSelectSentence: this.selectSentence,
onSetContent: this.onSetContent,
isSentenceSelectVisible: this.isSentenceSelectVisible,
onNameTitleClick: this.onNameTitleClick,
backRedDot: !this._currPlot
};
this._view.setProps(this._viewProps);
// this._viewProps = [];
this._gLevelMax = -1;
this._cachePId = NaN;
this.view.resumeAll();
};
AVG_1.PlotManager.PlotsRollbackEvent.on(() => {
this._excutedPlots = {};
this.onResumeChatListView();
});
}
get sceneModel() { return this._sceneModel; }
getRoleId() {
if (this.sceneModel.config.roles.length == 1)
return this.sceneModel.config.roles[0];
return 1;
}
async onOpen(scene) {
super.onOpen(scene);
this._sceneModel = scene;
this._disposable.add(AVG_1.PlotManager.PlotStartEvent.on(this.handlePlotsStart));
this._currPlot = AVG_1.PlotManager.getCurrentPlots().find(v => v.plotSceneType === Enums_1.PlotSceneType.Message && v.plotSceneTypeId === scene.id);
if (this._historyMessages[scene.id]) {
this._chatList = this._historyMessages[scene.id];
}
else {
this._chatList = [];
}
let canSendGift = false;
let isMajor = false;
if (scene.config.roles.length === 1) {
let roleConfig = simba_config_manager_1.ConfigManager.getConfig(Role_1.role, scene.config.roles[0]);
if (roleConfig.RoleType === EditorEnums_1.RoleType.Role_Major) {
isMajor = true;
}
}
canSendGift = isMajor;
if (this._chatList && this._chatList.length) {
this.organizeViewProps(scene, isMajor);
this._view.setProps(this._viewProps);
}
else {
this._viewProps = {
msgSceneId: scene.id, title: GameModelManager_1.GameModelManager.getConfigLanguageTxt(scene.config.title),
items: [], historyMsgCount: 0,
onCloseBtnClick: this.closeAction,
onSelectChapter: this.selectChapter,
onCompletePlot: this.completePlot,
onSelectSentence: this.selectSentence,
onSetContent: this.onSetContent,
isSentenceSelectVisible: this.isSentenceSelectVisible,
onNameTitleClick: this.onNameTitleClick,
backRedDot: !this._currPlot
};
this._view.setProps(this._viewProps);
await this.loadChatList();
this.organizeViewProps(scene, isMajor);
this._view.setProps(this._viewProps);
}
if (this._currPlot) {
if (GameModelManager_1.GameModelManager.isChangePlotSceneType()) {
GameModelManager_1.GameModelManager.dotMainLinePlotStart();
}
this._currPlotShowed = false;
let player = GameModelManager_1.GameModelManager.getPlayerData();
// if (player.getEnergy() >= GameConstData.GAME_CONST_PLOT_ENERGY_COST_VALUE)//little brother bojie has written wrong judgement condition ,let me modify try try
// await this.showCurrPlot();
let item = this.convertPlotToViewModel(this._currPlot);
let e = player.getEnergy();
let through = e !== 0;
let costEnergy = false;
through = costEnergy ? through : true;
if (through) {
await this.showCurrPlot();
if (this._plotChangeLike) {
item = Object.assign({}, this._chatList.pop());
if (item.type === "plot") {
item.addLike = this._plotChangeLike;
}
this._chatList.push(item);
this.view.updateProps({ items: this._chatList });
}
if (item) {
if (this._cachePId !== this._currPlot.id && !this._excutedPlots[this._currPlot.id] && !this._plotExecuting && !this._currPlotShowed) {
this._chatList.push(item);
this._cachePId = this._currPlot.id;
this.view.updateProps({ items: this._chatList });
}
}
}
}
}
organizeViewProps(scene, isMajor) {
let canSendGift = false;
if (scene.config.roles.length === 1) {
let roleConfig = simba_config_manager_1.ConfigManager.getConfig(Role_1.role, scene.config.roles[0]);
if (roleConfig.RoleType === EditorEnums_1.RoleType.Role_Major) {
isMajor = true;
}
}
canSendGift = isMajor;
if (this._chatList.length !== 0) {
if (this._chatList[this._chatList.length - 1].type === "end") { // 上一次的结束改为历史
let item = this._chatList.pop();
this._chatList.push({ key: item.key, type: "history" });
for (let i = this._chatList.length - 2; i >= 0; i--) { // 删除之前的历史分割,只保留最后一个
let item = this._chatList[i];
if (item.type === "history") {
this._chatList.splice(i, 1);
break;
}
}
}
}
this._viewProps = {
msgSceneId: scene.id, title: GameModelManager_1.GameModelManager.getConfigLanguageTxt(scene.config.title),
items: this._chatList, historyMsgCount: this._chatList.length,
onCloseBtnClick: this.closeAction,
onSelectChapter: this.selectChapter,
onCompletePlot: this.completePlot,
onSelectSentence: this.selectSentence,
onSetContent: this.onSetContent,
isSentenceSelectVisible: this.isSentenceSelectVisible,
onNameTitleClick: this.onNameTitleClick,
backRedDot: !this._currPlot
};
}
async loadChatList() {
if (this._historyMessages[this._sceneModel.id] && this._historyMessages[this._sceneModel.id]) {
this._view.updateProps({ items: this._chatList });
return;
}
this._historyMessages[this._sceneModel.id] = [];
let historyPlots = [];
let records = AVG_1.GameRecord.getCurrentRecordItems();
let pushHistory = false;
let hasHistory = false;
let lastPlotId = Number.MAX_SAFE_INTEGER;
for (let i = records.length - 1; i >= 0; i--) {
let item = records[i];
for (let j = 0; j < item.p.length; j++) {
let plotId = item.p[j];
if (plotId === lastPlotId)
break;
let plot = (await AVG_1.getPlot(plotId));
if (!plot)
continue;
if (plot.plotSceneType === Enums_1.PlotSceneType.Message && plot.plotSceneTypeId === this._sceneModel.id) {
lastPlotId = plotId;
if (i === records.length - 1)
continue;
if (pushHistory && !hasHistory) {
historyPlots.unshift({ key: (this._itemKey++).toString(), type: "history" });
hasHistory = true;
}
let select = undefined;
if (item.s)
select = item.s[j];
let customData = undefined;
if (item.c)
customData = item.c[j];
let vm = this.convertPlotToViewModel(plot, select, customData);
if (vm)
historyPlots.unshift(vm);
}
else { // TODO process branch plots if needed.
if (!pushHistory && !hasHistory) {
pushHistory = true;
}
}
if (plot.id === this._sceneModel.firstPlot.id) {
break;
}
}
if (historyPlots.length > MAX_HISTORY) {
break;
}
}
this._chatList = historyPlots;
// this._view.updateProps({ items: historyPlots, historyMsgCount: this._chatList.length });
this._historyMessages[this._sceneModel.id] = this._chatList;
}
isClosed() {
return !this._disposable;
}
getGraceLevelMax() {
let m = -1;
let t = simba_config_manager_1.ConfigManager.getAllConfig(RelationLevelConfig_1.relationLevelConfig);
for (let id in t) {
let c = t[id];
m = m < c.id ? c.id : m;
}
return m;
}
};
ChatListViewPresenter.uuid = "ChatListViewPresenter";
ChatListViewPresenter = __decorate([
PresenterCCViewFactory_1.RegPresenter(ChatListView_1.ChatListViewType)
], ChatListViewPresenter);
return ChatListViewPresenter;
})();
exports.ChatListViewPresenter = ChatListViewPresenter;
cc._RF.pop();