b3b4451d-4077-4e86-8252-7ae8b694d4e1.js
13.6 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
"use strict";
cc._RF.push(module, 'b3b44UdQHdOhoJSeui2lNTh', 'NewNoticeViewPresenter');
// script/game/ui/presenter/notice/NewNoticeViewPresenter.ts
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const simba_config_manager_1 = require("simba-config-manager");
const simba_sdk_1 = require("simba-sdk");
const EditorEnums_1 = require("../../../../avg/EditorEnums");
const PresenterBase_1 = require("../../../../common/classbase/PresenterBase");
const UIManager_1 = require("../../../../common/gameplay/managers/UIManager");
const TaoBaoShopUrlConfig_1 = require("../../../../config/TaoBaoShopUrlConfig");
const GameConfig_1 = require("../../../../GameConfig");
const ActivitiesItemModelManager_1 = require("../../../model/ActivitiesItemModelManager");
const GameModelManager_1 = require("../../../model/GameModelManager");
const HttpRequests_1 = require("../../../network/HttpRequests");
const ActivitiesNoticeItem_1 = require("../../ActivitiesNoticeItem");
const PresenterCCViewFactory_1 = require("../../PresenterCCViewFactory");
const NewNoticeView_1 = require("../../view/type/notice/NewNoticeView");
let NewNoticeViewPresenter = /** @class */ (() => {
let NewNoticeViewPresenter = class NewNoticeViewPresenter extends PresenterBase_1.Presenter {
constructor() {
super();
this._noticeType = NewNoticeView_1.NoticeType.SystemNotice;
this._delayTime = 0;
this._closeTimeTicker = -1;
this._canClose = false;
/**
* 公告按钮的点击事件
* @param index 系统公告和活动公告的Index
*/
this.onNoticeButtonClickCallback = (index) => {
if (this._noticeType !== index) {
this._noticeType = index;
this.setNoticeState();
this.setNoticeContent();
}
};
/**
* 关闭按钮的点击事件
*/
this.onCloseButtonClickCalback = () => {
if (this._canClose) {
this.checkTipsToggleState();
GameModelManager_1.GameModelManager.setNoticeReaded(true);
clearTimeout(this._closeTimeTicker);
this.view.close();
}
};
this._viewProps = {
sourceView: NewNoticeView_1.SourceView.MessageView,
onNoticeButtonClickCallback: this.onNoticeButtonClickCallback,
onCloseButtonClickCalback: this.onCloseButtonClickCalback,
};
}
onOpen(source) {
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 = GameModelManager.getNoticeReaded() ? 0 : 3;
this._delayTime = 0;
//重置提示文本状态
this.view.getCloseTipsLabel().string = "";
//初始化公告类型
if (GameConfig_1.channel == "android") {
this._noticeType = NewNoticeView_1.NoticeType.ActvitiesNotice;
}
else {
this._noticeType = NewNoticeView_1.NoticeType.SystemNotice;
}
//根据存档初始化“今日不再提示”的选择框
let autoShow = GameModelManager_1.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 NewNoticeView_1.NoticeType.SystemNotice: //系统公告
nodes[NewNoticeView_1.NoticeType.SystemNotice].active = true;
nodes[NewNoticeView_1.NoticeType.ActvitiesNotice].active = false;
buttons[NewNoticeView_1.NoticeType.SystemNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[1];
buttons[NewNoticeView_1.NoticeType.ActvitiesNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[2];
break;
case NewNoticeView_1.NoticeType.ActvitiesNotice: //活动公告
nodes[NewNoticeView_1.NoticeType.SystemNotice].active = false;
nodes[NewNoticeView_1.NoticeType.ActvitiesNotice].active = true;
buttons[NewNoticeView_1.NoticeType.SystemNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[0];
buttons[NewNoticeView_1.NoticeType.ActvitiesNotice].node.getChildByName("Background").getComponent(cc.Sprite).spriteFrame = this.view.getButtonSpriteFrames()[3];
break;
default:
break;
}
}
/**
* 设置公告内容
*/
async setNoticeContent() {
switch (this._noticeType) {
case NewNoticeView_1.NoticeType.SystemNotice: //系统公告
HttpRequests_1.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 NewNoticeView_1.NoticeType.ActvitiesNotice: //活动公告
this.view.getActivitiesContentNode().removeAllChildren();
let configs = ActivitiesItemModelManager_1.ActivitiesItemModelManager.getValidActivitiesConfigs();
for (let i = 0; i < configs.length; i++) {
if (!configs[i].canClick) {
ActivitiesItemModelManager_1.ActivitiesItemModelManager.setActivitiesReaded(configs[i].activityId);
this.refreshActivitiesButtonRedDot();
}
let item = cc.instantiate(this.view.getActivitiesItemPrefab());
item.getComponent(ActivitiesNoticeItem_1.default).setData(configs[i].activityId, configs[i].canClick, configs[i].describe, () => {
//刷新活动列表和“活动公告”按钮的红点
ActivitiesItemModelManager_1.ActivitiesItemModelManager.setActivitiesReaded(configs[i].activityId);
item.getComponent(ActivitiesNoticeItem_1.default).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_1.GameModelManager.getAutoShowNotice();
if (autoShow !== !isChecked) {
GameModelManager_1.GameModelManager.setAutoShowNotice(!isChecked);
}
}
/**
* 刷新“活动公告”按钮的红点状态
*/
refreshActivitiesButtonRedDot() {
let buttons = this.view.getNoticeButtons();
let configs = ActivitiesItemModelManager_1.ActivitiesItemModelManager.getValidActivitiesConfigs();
for (let i = 0; i < configs.length; i++) {
let isReaded = ActivitiesItemModelManager_1.ActivitiesItemModelManager.getActivitiesReaded(configs[i].activityId);
if (!isReaded) {
buttons[NewNoticeView_1.NoticeType.ActvitiesNotice].node.getChildByName("RedDot").active = true;
return;
}
else {
buttons[NewNoticeView_1.NoticeType.ActvitiesNotice].node.getChildByName("RedDot").active = false;
}
}
}
/**
* 根据活动配置处理活动事件
* @param config 活动配置
*/
executeActivitiesEvent(config, source) {
switch (config.activityTypeConfig.activityType) {
case EditorEnums_1.ActicityType.JumpToTaoBao:
if (GameConfig_1.channel == "wechat") {
// GameCenter.getInstance().openSubProgram(GameConfig.youZanShopAppId);
if (config.activityTypeConfig.taobaoTempId) {
let taobaoConfig = simba_config_manager_1.ConfigManager.getConfig(TaoBaoShopUrlConfig_1.taoBaoShopUrlConfig, config.activityTypeConfig.taobaoTempId);
simba_sdk_1.SDK.openProgramV2(GameConfig_1.GameConfig.youZanShopAppId, taobaoConfig.youZanUrl);
}
else {
console.error("The taobaoTempId is undefined.");
}
}
else if (GameConfig_1.channel == "android") {
if (config.activityTypeConfig.taobaoTempId) {
let taobaoConfig = simba_config_manager_1.ConfigManager.getConfig(TaoBaoShopUrlConfig_1.taoBaoShopUrlConfig, config.activityTypeConfig.taobaoTempId);
GameModelManager_1.GameModelManager.jumpToTaobaoShop(taobaoConfig.websiteUrl);
}
else {
console.error("The taobaoTempId is undefined.");
}
}
else {
UIManager_1.UIManager.showToast("该功能在当前平台不可使用");
}
break;
case EditorEnums_1.ActicityType.PageInGame:
let 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, source) {
switch (source) {
case NewNoticeView_1.SourceView.MessageView:
this.onCloseButtonClickCalback();
GameModelManager_1.GameModelManager.JumpToViewInGame.emit(pageIndex);
break;
case NewNoticeView_1.SourceView.SettingView:
this.onCloseButtonClickCalback();
GameModelManager_1.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);
}
}
};
NewNoticeViewPresenter.uuid = "NewNoticeViewPresenter";
NewNoticeViewPresenter = __decorate([
PresenterCCViewFactory_1.RegPresenter(NewNoticeView_1.NewNoticeViewType)
], NewNoticeViewPresenter);
return NewNoticeViewPresenter;
})();
exports.default = NewNoticeViewPresenter;
cc._RF.pop();