PhoneCallViewPresenter.ts
3.62 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
import { Presenter, createPresenter } from "../../../common/classbase/PresenterBase";
import { PhoneCallView, PhoneCallViewType, PhoneCallItemProps, PhoneCallViewProps } from "../view/type/PhoneCallView";
import { RegPresenter } from "../PresenterCCViewFactory";
import { GameModelManager } from "../../model/GameModelManager";
import { PlotSceneType } from "../../Enums";
import { ConfigManager } from "../../../common/gameplay/managers/ConfigManager";
import { role } from "../../../config/Role";
import { PlotManager } from "../../../avg/PlotManager";
import SentenceSelectorViewPresenter from "./SentenceSelectorViewPresenter";
import { SentenceContent, SentenceSelectContent } from "../../../avg/model/PlotModel";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { SentenceSelectorViewProps } from "../view/type/SentenceSelectorView";
import { DeepReadonly } from "simba-utils";
import { runAction } from "../../../../../build-templates/wechatgame/launcher/launcher-scene";
@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;
}
async onOpen() {
super.onOpen(undefined);
this._items = [];
GameModelManager.rollbackPhoneCallIfNeeded().then((plots) => {
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.add(PlotManager.PlotStartEvent.on((plots) => {
plot = plots[0];
if (plot.plotSceneType !== PlotSceneType.PhoneCall) {
this._view.close();
} else {
this._items = [...this._items, { key: plot.id + "", isSelf: plot.sentences[0].roleId === 2, sentence: plot.sentences[0] }];
this._view.updateProps({ items: this._items });
}
}));
}
});
}
}