PhoneCallViewPresenter.ts
3.88 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
import { ConfigManager } from "simba-config-manager";
import { DeepReadonly } from "simba-utils";
import { PlotManager, ReadonlyPlots, SentenceSelectContent } from "../../../avg/AVG";
import { Presenter } from "../../../common/classbase/PresenterBase";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { role } from "../../../config/Role";
import { PlotSceneType } from "../../Enums";
import { GameModelManager } from "../../model/GameModelManager";
import { RegPresenter } from "../PresenterCCViewFactory";
import { PhoneCallItemProps, PhoneCallView, PhoneCallViewProps, PhoneCallViewType } from "../view/type/PhoneCallView";
import { SentenceSelectorViewProps } from "../view/type/SentenceSelectorView";
import SentenceSelectorViewPresenter from "./SentenceSelectorViewPresenter";
@RegPresenter(PhoneCallViewType)
export class PhoneCallViewPresenter extends Presenter<undefined, PhoneCallView> {
static uuid = "PhoneCallViewPresenter";
private _items: PhoneCallItemProps[] = [];
private _viewProps: PhoneCallViewProps;
onSetContent = (content: DeepReadonly<SentenceSelectContent> | undefined) => {
let props: SentenceSelectorViewProps =
{
sentence: content,
backgroundpath: "",
clickcausehide: false,
onSelectIndexCallback: this.onSelectIndexCallback
};
UIManager.pushPresenter(SentenceSelectorViewPresenter, props);
}
onSelectIndexCallback = (index: number) => {
this.view.select(index);
}
isSentenceSelectVisible = (): boolean => {
let preset = UIManager.getTopPresenter();
if (preset instanceof SentenceSelectorViewPresenter) {
let selectorPresenter = preset as SentenceSelectorViewPresenter;
return !selectorPresenter.view.isHidden;
}
return false;
}
onGameChangedClickCallback = (ret: boolean) => {
this.view.applicationChange(ret);
}
async onOpen() {
super.onOpen(undefined);
this._disposable.add(GameModelManager.ApplicaitonGameChanged.on(this.onGameChangedClickCallback));
let plots = await GameModelManager.rollbackPhoneCallIfNeeded();
this.analysisPlots(plots);
}
analysisPlots(plots: ReadonlyPlots) {
this._items = [];
let plot = plots[0];
if (plot.plotSceneType !== PlotSceneType.PhoneCall) {
console.error("Phone call plot data error.");
} else {
let roleData = ConfigManager.getConfig(role, plot.plotSceneTypeId);
this._items = [{ key: plot.id + "", isSelf: plot.sentences[0].roleId === 2, sentence: plot.sentences[0] }];
this._viewProps =
{
name: roleData.name, // TODO i18n
icon: GameModelManager.getRoleData(plot.plotSceneTypeId)!.getHeadIcon(),
items: this._items,
onCompletePlot: (index?: number) => PlotManager.completePlot(plot, index),
onSetContent: this.onSetContent,
isSentenceSelectVisible: this.isSentenceSelectVisible
};
this._view.setProps(this._viewProps);
this._disposable.clear();
this._disposable.add(PlotManager.PlotStartEvent.on((plots) => {
plot = plots[0];
if (plot.plotSceneType !== PlotSceneType.PhoneCall) {
GameModelManager.dotMainLinePlotEnd();
this._view.close();
} else {
let item = { key: plot.id + "", isSelf: plot.sentences[0].roleId === 2, sentence: plot.sentences[0] };
let index = this._items.findIndex((v) => v.key === item.key);
if (index === -1) {
this._items = [...this._items, item];
}
this._view.updateProps({ items: this._items });
}
}));
}
}
}