ExtraPlotViewPresenter.ts
6.24 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
import { ConfigManager } from "simba-config-manager";
import { SDK } from "simba-sdk";
import { DateType } from "../../../avg/EditorEnums";
import { Presenter } from "../../../common/classbase/PresenterBase";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { dateSceneConfig } from "../../../config/DateSceneConfig";
import { channel, GameConfig } from "../../../GameConfig";
import { DatingEventStatus } from "../../model/DatingEventSceneModel";
import { ExtraStoryModelManager } from "../../model/ExtraStoryModelManager";
import { GameModelManager } from "../../model/GameModelManager";
import { RegPresenter } from "../PresenterCCViewFactory";
import { ExtraPlotViewType, ExtraPlotViewProps, ExtraPlotView, ExtraPlotViewState } from "../view/type/ExtraPlotView";
@RegPresenter(ExtraPlotViewType)
export default class ExtraPlotViewPresenter extends Presenter<undefined, ExtraPlotView>{
static uuid = "ExtraPlotViewPresenter";
private _viewProps: ExtraPlotViewProps;
private _tabbarId: number = 0;
private _markButtonsY: number[] = [];
private _viewState: ExtraPlotViewState;
constructor() {
super();
this._viewProps = {
onMarkButtonClickCallback: this.onMarkButtonClickCallback,
onCloseButtonClickCallback: this.onCloseButtonClickCallback,
onGotoShopButtonClickCallback: this.onGotoShopButtonClickCallback,
}
}
onOpen() {
super.onOpen(undefined);
this.view.setProps(this._viewProps);
this.onShow();
}
onShow() {
super.onShow();
if (this._viewState == ExtraPlotViewState.List) {
GameModelManager.RefreshExtraPlotByType.emit(this._tabbarId);
} else {
this.initViewDate();
}
}
onEnterBackground() {
super.onEnterBackground();
}
onEnterForeground() {
super.onEnterForeground();
}
onClose() {
super.onClose();
}
initViewDate() {
this._viewState = ExtraPlotViewState.Choose;
this.setMarkButtonsPosition();
this.dropAction();
this.updateRedDot();
}
setMarkButtonsPosition() {
for (let i = 0; i < this.view.getMarkButtonNodes().length; i++) {
let y = this.view.getMarkButtonNodes()[i].y;
if (!this._markButtonsY[i]) {
this._markButtonsY.push(y);
}
this.view.getMarkButtonNodes()[i].y = this._markButtonsY[i] + cc.winSize.height;
}
}
dropAction() {
this.view.getMaskNode().active = true;
GameModelManager.RefreshExtraPlotByType.emit(0);
for (let i = 0; i < this.view.getMarkButtonNodes().length; i++) {
let node = this.view.getMarkButtonNodes()[i];
cc.tween(node)
.to(0.8 + i * 0.1, { y: this._markButtonsY[i] }, { easing: 'backOut' })
.call(() => {
if (i == (this.view.getMarkButtonNodes().length - 1)) {
this.view.getMaskNode().active = false;
}
})
.start();
}
}
risingAction() {
this.view.getMaskNode().active = true;
for (let i = 0; i < this.view.getMarkButtonNodes().length; i++) {
let node = this.view.getMarkButtonNodes()[i];
cc.tween(node)
.to(0.8 + i * 0.1, { y: this._markButtonsY[i] + cc.winSize.height }, { easing: 'backIn' })
.call(() => {
if (i == (this.view.getMarkButtonNodes().length - 1)) {
GameModelManager.RefreshExtraPlotByType.emit(this._tabbarId);
this.view.getMaskNode().active = false;
}
})
.start();
}
}
async updateRedDot() {
for (let i = 0; i < this.view.getMarkButtonNodes().length; i++) {
let node = this.view.getMarkButtonNodes()[i].getChildByName("RedDotSprite");
node.active = false;
}
let cfg = ConfigManager.getAllConfig(dateSceneConfig);
for (const id in cfg) {
for (let i = 0; i < this.view.getMarkButtonNodes().length; i++) {
if (cfg[id].DateType == DateType.Date_Sp && cfg[id].chapter_index == (i + 1)) {
await ExtraStoryModelManager.startBranches([cfg[id].start_plot_id]);
let branchStatus = ExtraStoryModelManager.getBranchStatus(Number(id), cfg[id].start_plot_id);
if (branchStatus == DatingEventStatus.New || branchStatus == DatingEventStatus.InProgress) {
let node = this.view.getMarkButtonNodes()[i].getChildByName("RedDotSprite");
node.active = true;
}
}
}
}
}
onMarkButtonClickCallback = (tabbarId: number) => {
let cfg = ConfigManager.getAllConfig(dateSceneConfig);
let index: number[] = [];
for (const id in cfg) {
if (cfg[id].DateType == DateType.Date_Sp) {
index.push(cfg[id].chapter_index);
}
}
if (index.indexOf(tabbarId) == -1) {
UIManager.showToast("敬请期待");
return;
}
this._viewState = ExtraPlotViewState.List;
this._tabbarId = tabbarId;
this.risingAction();
}
onGotoShopButtonClickCallback = () => {
if (channel == "wechat") {
// GameCenter.getInstance().openSubProgram(GameConfig.youZanShopAppId);
let link = GameModelManager.getYouZanShopUrlByType(8);
if (link) {
SDK.openProgramV2(GameConfig.youZanShopAppId, link);
}
} else if (channel == "android") {
let link = GameModelManager.getTaoBaoShopUrlByType(8);
if (link) {
GameModelManager.jumpToTaobaoShop(link);
}
} else {
UIManager.showToast("该功能在当前平台不可使用");
}
}
onCloseButtonClickCallback = async () => {
if (this._viewState == ExtraPlotViewState.List) {
this.initViewDate();
} else {
GameModelManager.CloseExtraSceneView.emit();
GameModelManager.setIsMainPlotSceneType(false);
this.view.close();
}
}
}