NewNoticeViewPresenter.ts
10.8 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
import { ConfigManager } from "simba-config-manager";
import { SDK } from "simba-sdk";
import { ActicityType, PageIndex } from "../../../../avg/EditorEnums";
import { Presenter } from "../../../../common/classbase/PresenterBase";
import { UIManager } from "../../../../common/gameplay/managers/UIManager";
import { taoBaoShopUrlConfig } from "../../../../config/TaoBaoShopUrlConfig";
import { channel, GameConfig } from "../../../../GameConfig";
import { ActivitiesConfig, ActivitiesItemModelManager } from "../../../model/ActivitiesItemModelManager";
import { GameModelManager } from "../../../model/GameModelManager";
import { HttpRequests } from "../../../network/HttpRequests";
import ActivitiesNoticeItem from "../../ActivitiesNoticeItem";
import { RegPresenter } from "../../PresenterCCViewFactory";
import { NewNoticeViewType, NewNoticeView, NewNoticeViewProps, NoticeType, SourceView } from "../../view/type/notice/NewNoticeView";
@RegPresenter(NewNoticeViewType)
export default class NewNoticeViewPresenter extends Presenter<SourceView, NewNoticeView>{
static uuid = "NewNoticeViewPresenter"
private _viewProps: NewNoticeViewProps;
private _noticeType: NoticeType = NoticeType.SystemNotice;
private _delayTime: number = 0;
private _closeTimeTicker: number = -1;
private _canClose: boolean = false;
constructor() {
super();
this._viewProps = {
sourceView: SourceView.MessageView,
onNoticeButtonClickCallback: this.onNoticeButtonClickCallback,
onCloseButtonClickCalback: this.onCloseButtonClickCalback,
};
}
onOpen(source: SourceView) {
super.onOpen(source);
this._viewProps.sourceView = source;
this.view.setProps(this._viewProps);
this.onShow();
}
onShow() {
super.onShow();
this.initView();
}
onEnterBackground() {
super.onEnterBackground();
}
onEnterForeground() {
super.onEnterForeground();
}
onClose() {
super.onClose();
}
initView() {
//重置可关闭状态为false
this._canClose = false;
this._delayTime = 0;
//重置提示文本状态
this.view.getCloseTipsLabel().string = "";
//初始化公告类型
if (channel == "android") {
this._noticeType = NoticeType.ActvitiesNotice;
} else {
this._noticeType = NoticeType.SystemNotice;
}
//根据存档初始化“今日不再提示”的选择框
let autoShow = GameModelManager.getAutoShowNotice();
this.view.getTipsToggle().isChecked = !autoShow;
//初始化公告按钮状态和公告内容
this.setNoticeState();
this.setNoticeContent();
//刷新活动公告按钮的红点状态
this.refreshActivitiesButtonRedDot();
//开启关闭倒计时
this.startTimeTicker();
}
/**
* 设置公告按钮状态和公告内容显隐
*/
setNoticeState() {
let nodes = this.view.getNoticeNodes();
let buttons = this.view.getNoticeButtons();
switch (this._noticeType) {
case NoticeType.SystemNotice://系统公告
nodes[NoticeType.SystemNotice].active = true;
nodes[NoticeType.ActvitiesNotice].active = false;
buttons[NoticeType.SystemNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[1];
buttons[NoticeType.ActvitiesNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[2];
break;
case NoticeType.ActvitiesNotice://活动公告
nodes[NoticeType.SystemNotice].active = false;
nodes[NoticeType.ActvitiesNotice].active = true;
buttons[NoticeType.SystemNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[0];
buttons[NoticeType.ActvitiesNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[3];
break;
default:
break;
}
}
/**
* 设置公告内容
*/
async setNoticeContent() {
switch (this._noticeType) {
case NoticeType.SystemNotice://系统公告
HttpRequests.getNewNotice().then((res) => {
if (res != null && res.length > 0) {
this.view.getContentRichText().string = res[0].msg;
} else {
this.view.getContentRichText().string = "<color=#FF0000>公告获取失败,请检查网络或稍后重试<color/>";
}
});
break;
case NoticeType.ActvitiesNotice://活动公告
this.view.getActivitiesContentNode().removeAllChildren();
let configs = ActivitiesItemModelManager.getValidActivitiesConfigs();
for (let i = 0; i < configs.length; i++) {
if (!configs[i].canClick) {
ActivitiesItemModelManager.setActivitiesReaded(configs[i].activityId);
this.refreshActivitiesButtonRedDot();
}
let item = cc.instantiate(this.view.getActivitiesItemPrefab());
item.getComponent(ActivitiesNoticeItem).setData(configs[i].activityId, configs[i].canClick, configs[i].describe, () => {
//刷新活动列表和“活动公告”按钮的红点
ActivitiesItemModelManager.setActivitiesReaded(configs[i].activityId);
item.getComponent(ActivitiesNoticeItem).refreshRedDot();
this.refreshActivitiesButtonRedDot();
//执行活动逻辑
this.executeActivitiesEvent(configs[i], this._viewProps.sourceView);
});
item.parent = this.view.getActivitiesContentNode();
}
break;
default:
break;
}
}
/**
* 检查“今日不再提示”单选框的选择状态
*/
checkTipsToggleState() {
let isChecked = this.view.getTipsToggle().isChecked;
let autoShow = GameModelManager.getAutoShowNotice();
if (autoShow !== !isChecked) {
GameModelManager.setAutoShowNotice(!isChecked);
}
}
/**
* 刷新“活动公告”按钮的红点状态
*/
refreshActivitiesButtonRedDot() {
let buttons = this.view.getNoticeButtons();
let configs = ActivitiesItemModelManager.getValidActivitiesConfigs();
for (let i = 0; i < configs.length; i++) {
let isReaded = ActivitiesItemModelManager.getActivitiesReaded(configs[i].activityId);
if (!isReaded) {
buttons[NoticeType.ActvitiesNotice].node.getChildByName("RedDot").active = true;
return;
} else {
buttons[NoticeType.ActvitiesNotice].node.getChildByName("RedDot").active = false;
}
}
}
/**
* 根据活动配置处理活动事件
* @param config 活动配置
*/
executeActivitiesEvent(config: ActivitiesConfig, source: SourceView) {
switch (config.activityTypeConfig.activityType) {
case ActicityType.JumpToTaoBao:
if (channel == "wechat") {
// GameCenter.getInstance().openSubProgram(GameConfig.youZanShopAppId);
if (config.activityTypeConfig.taobaoTempId) {
let taobaoConfig = ConfigManager.getConfig(taoBaoShopUrlConfig, config.activityTypeConfig.taobaoTempId);
SDK.openProgramV2(GameConfig.youZanShopAppId, taobaoConfig.youZanUrl);
} else {
console.error("The taobaoTempId is undefined.");
}
} else if (channel == "android") {
if (config.activityTypeConfig.taobaoTempId) {
let taobaoConfig = ConfigManager.getConfig(taoBaoShopUrlConfig, config.activityTypeConfig.taobaoTempId);
GameModelManager.jumpToTaobaoShop(taobaoConfig.websiteUrl);
} else {
console.error("The taobaoTempId is undefined.");
}
} else {
UIManager.showToast("该功能在当前平台不可使用");
}
break;
case ActicityType.PageInGame:
let pageIndex: PageIndex = config.activityTypeConfig.pageIndex;
if (pageIndex) {
this.executePageInGameEvent(pageIndex, source);
} else {
console.error("The pageIndex is undefined.");
}
break;
default:
break;
}
}
/**
* 处理游戏内的活动事件
* @param activityId 活动ID
*/
executePageInGameEvent(pageIndex: PageIndex, source: SourceView) {
switch (source) {
case SourceView.MessageView:
this.onCloseButtonClickCalback();
GameModelManager.JumpToViewInGame.emit(pageIndex);
break;
case SourceView.SettingView:
this.onCloseButtonClickCalback();
GameModelManager.CloseSettingView.emit(pageIndex);
default:
break;
}
}
/**
* 开启可关闭定时器
*/
startTimeTicker() {
if (this._delayTime == 0) {
this._canClose = true;
this.view.getCloseTipsLabel().string = "点击空白区域可关闭";
} else {
this.view.getCloseTipsLabel().string = this._delayTime + "秒后可关闭";
this._closeTimeTicker = window.setTimeout(() => {
this._delayTime -= 1;
this.startTimeTicker();
}, 1000);
}
}
/**
* 公告按钮的点击事件
* @param index 系统公告和活动公告的Index
*/
onNoticeButtonClickCallback = (index: number) => {
if (this._noticeType !== index) {
this._noticeType = index;
this.setNoticeState();
this.setNoticeContent();
}
}
/**
* 关闭按钮的点击事件
*/
onCloseButtonClickCalback = () => {
if (this._canClose) {
this.checkTipsToggleState();
clearTimeout(this._closeTimeTicker);
this.view.close();
}
}
}