MainViewPresenter.ts
4.21 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
import { GameRecord } from "../../../avg/game-data/GameRecord";
import { ReadonlyPlots, SpecialPlotId } from "../../../avg/model/PlotModel";
import { PlotManager } from "../../../avg/PlotManager";
import { createPresenter, Presenter } from "../../../common/classbase/PresenterBase";
import { View } from "../../../common/classbase/ViewBase";
import { GameTextData } from "../../../common/gameplay/gamedata/GameTextData";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { PlotSceneType } from "../../Enums";
import { GameModelManager } from "../../model/GameModelManager";
import { RegPresenter } from "../PresenterCCViewFactory";
import { showToBeContinue } from "../view/impl/AlertToBeContinueImpl";
import { MainView, MainViewProps, MainViewType } from "../view/type/MainView";
import DatingEventViewPresenter from "./DatingEventViewPresenter";
import MessageViewPresenter from "./MessageViewPresenter";
const enum Tabs {
messageTab = 0,
datingEventTab = 1,
}
const TabPresenterFactory: ({ new(): Presenter } & { uuid: string })[] = [MessageViewPresenter, DatingEventViewPresenter];
@RegPresenter(MainViewType)
export default class MainViewPresenter extends Presenter<undefined, MainView> {
static uuid = "MainViewPresenter";
private _subPresenters: Presenter<any, View>[] = [];
private _currentTab = 0;
private _viewProps: MainViewProps;
private _loadingTab = false;
constructor() {
super();
this._viewProps = {
selectedTab: 0,
messageRedDot: false,
datingEventRedDot: false,
onTabClick: this.onTabClick
};
}
checkRedDot = (plots: ReadonlyPlots) => {
if (plots[0].plotSceneType === PlotSceneType.Message || plots[0].plotSceneType === PlotSceneType.PhoneCall) {
this._viewProps.messageRedDot = true;
} else {
this._viewProps.messageRedDot = false;
}
this._viewProps.datingEventRedDot = false;
for (let plot of plots) {
if (plot.plotSceneType === PlotSceneType.DatingEvent) {
this._viewProps.datingEventRedDot = true;
}
}
this.view.setProps(this._viewProps);
}
async start() {
// 开始游戏
this._subPresenters[0] = await createPresenter(TabPresenterFactory[0]);
this._subPresenters[0].open(this._view.getTabContentContainer(), undefined);
this.checkRedDot(PlotManager.getCurrentPlots());
PlotManager.PlotStartEvent.on(this.checkRedDot);
if (PlotManager.getCurrentPlots()[0].id === SpecialPlotId.ToBeContinued) {
showToBeContinue();
}
}
onClose() {
super.onClose();
UIManager.popToPresenter(this);
}
onOpen() {
super.onOpen(undefined);
}
onEnterBackground() {
super.onEnterBackground();
this._subPresenters[this._currentTab].onEnterBackground();
}
onEnterForeground() {
super.onEnterForeground();
this._subPresenters[this._currentTab].onEnterForeground();
if (PlotManager.getCurrentPlots()[0].id === SpecialPlotId.ToBeContinued) {
showToBeContinue();
}
}
onTabClick = (index: number) => {
if (!GameModelManager.checkFuncUnloced(TabPresenterFactory[index].uuid)) {
UIManager.showToast(GameModelManager.getLanguageTxt(GameTextData.GAME_TEXT_MAIN_FUNCTION_NOT_OPEN));
return;
}
if (this._loadingTab) return;
if (this._currentTab !== index) {
this._subPresenters[this._currentTab].view.hide();
this._currentTab = index;
this._viewProps.selectedTab = index;
this._view.setProps(this._viewProps);
if (!this._subPresenters[this._currentTab]) {
this._loadingTab = true;
createPresenter(TabPresenterFactory[this._currentTab]).then((presenter) => {
this._loadingTab = false;
this._subPresenters[this._currentTab] = presenter;
presenter.open(this.view.getTabContentContainer(), undefined);
});
} else {
this._subPresenters[this._currentTab].view.show();
}
}
}
}