DatingScenePresenter.ts
24.7 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
import { AudioManager } from "simba-cc-audio-manager";
import { ConfigManager } from "simba-config-manager";
import { DeepReadonly, delay } from "simba-utils";
import { Action, ActionManager, ActionType, GameRecord, Plot, PlotManager, richNodesToCocosString, SentenceType, SpecialPlotId } from "../../../avg/AVG";
import { DateType, FaceType } from "../../../avg/EditorEnums";
import { EditorEvents } from "../../../avg/EditorEvents";
import { Presenter } from "../../../common/classbase/PresenterBase";
import { GameConstData } from "../../../common/gameplay/gamedata/GameConstData";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { dateSceneConfig } from "../../../config/DateSceneConfig";
import { PlotSceneType } from "../../Enums";
import CDKeyEventManager from "../../model/CDKeyEventManager";
import { DatingEventSceneModel, DatingEventStatus } from "../../model/DatingEventSceneModel";
import { GameModelManager } from "../../model/GameModelManager";
import GameRoleDataModel from "../../model/GameRoleDataModel";
import { RegPresenter } from "../PresenterCCViewFactory";
import { SpecialToastType } from "../SpecialToast";
import VerbView from "../VerbView";
import { AlertDialogViewProps } from "../view/type/AlertDialogView";
import { DatingSceneView, DatingSceneViewType } from "../view/type/DatingSceneView";
import { SentenceSelectorViewProps } from "../view/type/SentenceSelectorView";
import AlertDialogViewPresenter from "./AlertDialogViewPresenter";
import ReviewPlotViewPresenter, { ReviewPlotViewParam } from "./ReviewPlotViewPresenter";
import SentenceSelectorViewPresenter from "./SentenceSelectorViewPresenter";
type DatingPlot = DeepReadonly<Plot & { face: FaceType, portrait?: number, portraitFace?: FaceType }>
@RegPresenter(DatingSceneViewType)
export class DatingScenePresenter extends Presenter<DatingEventSceneModel, DatingSceneView> {
static uuid = "DatingScenePresenter";
private _currPlot?: DatingPlot;
private _executingPlot = false;
private _completingPlot = false;
private _showScrollView = false;
/**是否时回忆 */
private _isReview = false;
private _model: DatingEventSceneModel;
// private _actionFilter?: (action: DeepReadonly<Action>) => boolean;
private _plotBranch = 0;
/**出现选择时记录当前选择的id*/
private _currSelect?: number = undefined;
/**本次约会剧情是否结束 */
private _finished = false;
//dating scene which id is 1, need to deal by specially;
private _specialDealSceneId: number = 1;
private _isDotTutorial: boolean = false;
private _showBackBtn: boolean = true;
private _reviewPlot: string = "";
onOpen(param: DatingEventSceneModel) {
super.onOpen(param);
this._finished = false;
this._isDotTutorial = false;
this._reviewPlot = "";
this.view.completePlotCallback = this.completePlot;
this.view.onReviewButtonClickCallback = this.onReviewButtonClickCallback;
this._model = param;
if (this._model.status === DatingEventStatus.New) {
this._model.status = DatingEventStatus.InProgress;
}
let isSpecialScene: boolean = this._model.id === this._specialDealSceneId;
// deal special :hide backBtn
this._showBackBtn = !(isSpecialScene && this._model.status === DatingEventStatus.InProgress);
this.view.showBackBtn(this._showBackBtn);
// this.view.setRunCloseAction((isSpecialScene && this._model.status !== DatingEventStatus.Completed));
if (this._model.isExtra) {
GameModelManager.setIsMainPlotSceneType(false);
} else {
GameModelManager.setIsMainPlotSceneType(true);
}
delay(0.1).then(async () => {
if (param.status === DatingEventStatus.Completed) {
this._isReview = true;
// this._actionFilter = (action) => {
// return action.type !== ActionType.ModifyVariable;
// }
this._model.background = "";
this._currPlot = this._model.firstPlot as DatingPlot;
} else {
this._isReview = false;
if (this._model.isExtra) {
GameModelManager.setBranchInProgress(this._model.id);
}
let plots = PlotManager.getCurrentPlots();
this._plotBranch = plots.findIndex(v => v.plotSceneType === PlotSceneType.DatingEvent && v.plotSceneTypeId === param.id);
this._isDotTutorial = GameModelManager.checkIsDotTutorial() && this._plotBranch === 0;
this._currPlot = plots[this._plotBranch] as DatingPlot;
if (this._currPlot.id === this._model.firstPlot.id) {
GameRecord.recordVariables.bgm = ""; // 新约会,不继承之前剧情的背景音乐存档
this._model.background = "";
}
this._currSelect = PlotManager.getPlotSelection(this._currPlot.id);
// if(!this._currSelect) this._currSelect = 0;
if (GameRecord.recordVariables.bgm) {
AudioManager.playMusic(GameRecord.recordVariables.bgm);
}
//dot main plot start
if (0 === this._plotBranch && this._currPlot && this._currPlot.id === this._model.firstPlot.id) {
GameModelManager.dotMainLinePlotStart();
}
}
if (this._model.background) {
await this.view.setBackground("textures/background/dating_event/" + this._model.background);
}
this.execPlot();
});
this._disposable.add(EditorEvents.SET_DATING_BG.on((bgPath) => {
this._model.background = bgPath;
if (bgPath) bgPath = "textures/background/dating_event/" + bgPath;
return this.view.setBackground(bgPath);
}));
this._disposable.add(EditorEvents.SET_DATING_BG_EFFECT.on((bgPath) => {
this._model.background = bgPath;
if (bgPath) bgPath = "textures/background/dating_event/" + bgPath;
return this.view.setBackgroundEffect(bgPath);
}));
this._showScrollView = false;
this._disposable.add(GameModelManager.DeadEvent.on(this.onDeadEvent));
this._disposable.add(GameModelManager.SpecialToast.on(this.onSpecialToast));
}
onClose() {
super.onClose();
this._currPlot = undefined;
AudioManager.stopMusic();
// UIManager.popToPresenter(this);
if (!this._model.isExtra) {
GameModelManager.CloseDatingSceneView.emit(this._model.id);
}
}
async execPlot() {
if (this._currPlot) {
if (this._currPlot.sentences && this._currPlot.plotSceneType === PlotSceneType.DatingEvent && this._currPlot.plotSceneTypeId === this._model.id) {
this._executingPlot = true;
const sentence = this._currPlot.sentences[0];
const content = sentence.content;
const roleData = GameModelManager.getRoleData(sentence.roleId)!;
let otherPortrait: string | undefined = undefined;
let isShowRouge: boolean = this.checkIsShowRouge(this._currPlot.id);
if (this._currPlot.portrait !== undefined) {
let otherRole = GameModelManager.getRoleData(this._currPlot.portrait);
if (otherRole) {
// otherPortrait = otherRole.getPortrait(this._currPlot.portraitFace);
otherPortrait = this.getPortraitByRole(otherRole, this._currPlot.portraitFace);
}
}
if (content) { // TODO 图片设置
if (content.type === SentenceType.TEXT) {
this.view.showBackBtn(this._showBackBtn);
await this.view.setContent(sentence.roleId === GameConstData.GAME_CONST_PLAYER_ROLE_VALUE,
richNodesToCocosString(content.value),
sentence.roleId === 1 ? "" : roleData.getNameIcon(),
sentence.roleId === 1 ? undefined : roleData.getConfig().name,
// sentence.roleId === 1 ? otherPortrait : roleData.getPortrait(this._currPlot.face,),
sentence.roleId === 1 ? otherPortrait : this.getPortraitByRole(roleData, this._currPlot.face),
otherPortrait, isShowRouge);
let plotName = "<color=#EFDA91>" + (sentence.roleId === 1 ? "旁白" : roleData.getConfig().name) + ":</c>\n";
let plotContent = richNodesToCocosString(content.value) + "\n";
if (this._isReview) {
this._reviewPlot = this._reviewPlot + plotName;
this._reviewPlot = this._reviewPlot + plotContent;
}
} else if (content.type === SentenceType.SELECT) {
this.view.showBackBtn(false);
let setSelection = async () => {
let value = content.value[this._currSelect!];
let str = value.summary;
this._reviewPlot = this._reviewPlot + "<color=#D36777>" + "选项" + ":</c>\n";
if (value.content && value.content.type === SentenceType.EMPTY) { // 空类型,不做展示
await this.completePlot();
if (this._isReview) {
this._reviewPlot = this._reviewPlot + str + "\n";
}
return;
} else if (value.content && value.content.type === SentenceType.TEXT) {
str = richNodesToCocosString(value.content.value);
if (this._isReview) {
this._reviewPlot = this._reviewPlot + str + "\n";
this._reviewPlot = this._reviewPlot + "<color=#EFDA91>" + "梵优" + ":</c>\n";
this._reviewPlot = this._reviewPlot + str + "\n";
}
} else {
if (this._isReview) {
this._reviewPlot = this._reviewPlot + str + "\n";
this._reviewPlot = this._reviewPlot + "<color=#EFDA91>" + "梵优" + ":</c>\n";
this._reviewPlot = this._reviewPlot + str + "\n";
}
}
// await this.view.setContent(true, str, roleData.getConfig().name, roleData.getPortrait(this._currPlot!.face), otherPortrait, isShowRouge);
await this.view.setContent(true, str, roleData.getNameIcon(), roleData.getConfig().name, this.getPortraitByRole(roleData, this._currPlot!.face), otherPortrait, isShowRouge);
}
if (this._currSelect === undefined || this._currSelect === null) {
let props: SentenceSelectorViewProps =
{
sentence: content,
backgroundpath: "",
clickcausehide: false,
isFromDate: true,
y: -250,
dateSceneId: this._model.id,
plotId: this._currPlot.id,
onSelectIndexCallback: (index: number) => { this._currSelect = index; setSelection(); }
};
UIManager.pushPresenter(SentenceSelectorViewPresenter, props);
// await this.view.setContent(true, "", roleData.getConfig().name, roleData.getPortrait(this._currPlot!.face), otherPortrait, isShowRouge);
await this.view.setContent(true, "", roleData.getNameIcon(), roleData.getConfig().name, this.getPortraitByRole(roleData, this._currPlot!.face), otherPortrait, isShowRouge);
} else {
await setSelection();
}
} else {
console.error("不支持的约会剧情", content);
}
} else { // 没有句子,只设置其立绘、背景等
// await this.view.setContent(false, "", "", roleData.getPortrait(this._currPlot!.face), otherPortrait, isShowRouge);
await this.view.setContent(false, "", "", "", this.getPortraitByRole(roleData, this._currPlot!.face), otherPortrait, isShowRouge);
}
if (this._currPlot.sentences[0].actions.actions.length) {
await ActionManager.executeActions(this._currPlot.sentences[0].actions, this.filterFunc, !this._isReview);
}
this._executingPlot = false;
} else {
// 本次约会剧情结束
this._model.status = DatingEventStatus.Completed;
this._finished = true;
this.view.setIsRunningAction(false);
this.view.showBackBtn(this._showBackBtn);
let Plot = PlotManager.getCurrentPlots()[0];
let isToBeContinued = Plot.id == SpecialPlotId.ToBeContinued;
let isEnd = Plot.id == SpecialPlotId.End;
if ((this._isReview || isToBeContinued || isEnd) && !this._model.isExtra) {
let nextKey = this.getNextDatingEventKey();
let nextEventModel = GameModelManager.getMainDatingEventSceneModel(nextKey);
if (nextEventModel) {
if (nextEventModel.status == DatingEventStatus.Completed) {
this.view.closeView();
let comp = cc.director.getScene().getChildByName("Canvas").getChildByName("VerbRoot").getChildByName("VerbView").getComponent(VerbView);
// let cfgs = ConfigManager.getAllConfig(dateSceneConfig);
// let ids: string[] = [];
// for (const id in cfgs) {
// if (cfgs[id].DateType == DateType.Date_Normal) {
// ids.push(id);
// }
// }
// let index = ids.indexOf(nextKey.toString());
let plotIds: number[] = [];
let models = GameModelManager.getMainDatingEventScenesModel();
for (let i = 0; i < models.length; i++) {
plotIds.push(models[i].id);
}
let index = plotIds.indexOf(nextEventModel.id);
let title = "第" + (index + 1) + "章:";
let cfg = ConfigManager.getConfig(dateSceneConfig, Number(nextKey));
let desc = cfg && cfg.name ? GameModelManager.getConfigLanguageTxt(cfg.name) : "";
comp.toDating(() => {
AudioManager.playEffect('verb');
GameModelManager.ForceClickDataReady.emit();
GameModelManager.ForceClickDatingItem.emit(Number(nextKey));
}, { title: title, desc: desc })
} else {
this.view.guideBack();
if (this._model.isExtra) {
GameModelManager.setBranchComplete(this._model.id);
}
}
} else {
if (this._model.isExtra) {
GameModelManager.setBranchComplete(this._model.id);
}
this.view.guideBack();
console.log("The nextEventModel is undefined.");
}
} else if (this._model.isExtra) {
this.view.guideBack();
GameModelManager.setBranchComplete(this._model.id);
console.log("Curr Chapter is extra plot.");
} else {
GameModelManager.dotMainLinePlotEnd();
}
}
} else if (this._model.isExtra) {
this.view.guideBack();
GameModelManager.setBranchComplete(this._model.id);
console.log("Curr Chapter is extra plot.");
}
}
/**完成当前剧情回调 */
completePlot = async () => {
if (this._executingPlot || this._completingPlot || !this._currPlot || this._finished) return;
let content = this._currPlot.sentences[0].content;
if (content && content.type === SentenceType.SELECT && this._currSelect === undefined) return;
this._completingPlot = true;
// GameModelManager.pushDateSceneKeyPlot(this._model.id, this._currPlot.id);
if (this._model.isExtra) {
GameModelManager.setIsMainPlotSceneType(false);
} else {
GameModelManager.setIsMainPlotSceneType(true);
}
if (this._isReview) {
let nextPlot = await PlotManager.getNextPlot(this._currPlot, this._currSelect);
if (nextPlot) {
this._currPlot = nextPlot as DatingPlot;
}
} else {
this._model.status = DatingEventStatus.InProgress;
let nextPlots = await PlotManager.completePlot(this._currPlot, this._currSelect);
this._currPlot = nextPlots[this._plotBranch] as DatingPlot;
}
this._currSelect = undefined;
this._completingPlot = false;
this.execPlot();
}
checkIsShowRouge(plotId: number): boolean {
let pStart: number = 1202;
let pEnd: number = 1229;
let ret: boolean = plotId >= pStart && plotId <= pEnd;
// console.log("剧情id = " + plotId + " 是否展示口红: = ", ret);
return ret;
}
getPortraitByRole(role: GameRoleDataModel, face = FaceType.Normal, skin?: number): string {
let portrait: string = "";
let curSkin = role.getCurSkin();
if (skin === undefined && curSkin > 0) {
skin = curSkin;
}
portrait = "textures/portrait/" + role.getConfig().id + "/" + (skin !== undefined ? skin + "/" : "") + face;
if (this._model.id === 1) {
portrait = "textures/portrait/" + role.getConfig().id + "/" + face;
}
return portrait;
}
getRetainVarKeyArr(): string[] {
let keyArr: string[] = [];
let branches = GameModelManager.getAllStartedBranches();
let branchMap = this.getBranchFirstPlotIdMap();
for (let i = 0; i < branches.length; i++) {
let startPlotId = branches[i].startPlot;
let extraId = branchMap[startPlotId + ""];
if (extraId) {
let recordKey = "de" + extraId;
let f = recordKey + ".f";
let s = recordKey + ".s";
let b = recordKey + ".bg";
if (GameRecord.recordVariables[f]) {
keyArr.push(f);
}
if (GameRecord.recordVariables[s]) {
keyArr.push(s);
}
if (GameRecord.recordVariables[b]) {
keyArr.push(b);
}
}
}
return keyArr;
}
getBranchFirstPlotIdMap(): { [key: string]: number } {
let map: { [key: string]: number } = {};
let tbl = ConfigManager.getAllConfig(dateSceneConfig);
if (tbl) {
for (let id in tbl) {
let c = tbl[id];
if (c && c.DateType == DateType.Date_Sp) {
map[c.start_plot_id + ""] = c.id;
}
}
}
return map;
}
onDeadEvent = (pid: number) => {
if (this._model.status == DatingEventStatus.Completed) {
let temp: AlertDialogViewProps = {
dataptr: {},
titlecontent: "提示",
content: "触发了死亡结局,但因为是在回忆模式,所以章节不会被重置",
ishasad: false,
istwobtn: false,
adconfig: "",
hasBanner: false,
callback: async (type, ret) => {
if (ret) {
this.view.closeView();
}
}
};
UIManager.pushPresenter(AlertDialogViewPresenter, temp);
} else {
let temp: AlertDialogViewProps = {
dataptr: {},
titlecontent: "提示",
content: "触发了死亡结局,本章节将<color=red>重置</color>!!",
ishasad: false,
istwobtn: false,
adconfig: "",
hasBanner: false,
callback: async (type, ret) => {
if (ret) {
let retainVar = this.getRetainVarKeyArr();
await PlotManager.rollbackToPlot(pid, false, retainVar);
this.rollBackDateAdArray(pid);
GameRecord.saveRecord();
this._showScrollView = !this._showScrollView;
this.view.closeView();
await GameModelManager.init((value: number) => {
});
GameModelManager.setIsChangePlotSceneType(true);
UIManager.showSceneToast("数据刷新完成");
let isSpecialScene: boolean = this._model.id === this._specialDealSceneId;
this._showBackBtn = !(isSpecialScene && this._model.status === DatingEventStatus.InProgress);
this.view.showBackBtn(this._showBackBtn);
GameModelManager.RefreshAllStatus.emit();
}
}
};
UIManager.pushPresenter(AlertDialogViewPresenter, temp);
}
}
private filterFunc = (action: DeepReadonly<Action>): boolean => {
let isExcute: boolean = true;
if (action.type === ActionType.ModifyVariable) {
isExcute = !GameModelManager.checkPlotTipAddGraceAlready(this._currPlot?.id as number);
if (isExcute) {
GameModelManager.pushTipAddGracePlot(this._currPlot?.id as number);
}
}
return isExcute;
}
rollBackDateAdArray(pid: number) {
let models = GameModelManager.getMainDatingEventScenesModel();
let chapterId = -1;
for (let i = 0; i < models.length; i++) {
if (pid == models[i].config.start_plot_id) {
chapterId = models[i].config.id;
}
}
if (chapterId == -1) {
console.error("Cannot found the chapterId.");
}
let record = GameRecord.globalVariables["date_ad_arr"] as string;
let a: number[] = [];
if (record) {
a = JSON.parse(record);
a.sort((a, b) => {
if (a < b) {
return -1;
} else if (a > b) {
return 1;
}
return 0;
});
for (let i = 0; i < a.length; i++) {
if (a[i] >= chapterId) {
a.splice(i, a.length - (i - 1));
GameRecord.globalVariables["date_ad_arr"] = JSON.stringify(a);
return;
}
}
}
}
getNextDatingEventKey(): number {
let nextKey: number = 0;
let currEventId = this._model.id;
let plotIds: number[] = [];
let models = GameModelManager.getMainDatingEventScenesModel();
for (let i = 0; i < models.length; i++) {
plotIds.push(models[i].id);
}
for (let i = 0; i < plotIds.length; i++) {
if (plotIds[i] == currEventId) {
nextKey = plotIds[i + 1];
}
}
console.log("getNextDatingEventModel", nextKey);
return nextKey;
}
onReviewButtonClickCallback = async () => {
let temp: ReviewPlotViewParam = {
isReview: this._isReview,
plotString: this._reviewPlot,
startPlotId: this._model.config.start_plot_id,
currentPlotId: this._currPlot!.id,
};
UIManager.pushPresenter(ReviewPlotViewPresenter, temp);
}
onSpecialToast = (type: SpecialToastType) => {
UIManager.showSpecialToast(type);
}
}