UrgentNoticeViewPresenter.ts
2.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
import { Presenter } from "../../../../common/classbase/PresenterBase";
import { GameModelManager } from "../../../model/GameModelManager";
import { RegPresenter } from "../../PresenterCCViewFactory";
import { UrgentNoticeViewType, UrgentNoticeView, UrgentNoticeViewProps } from "../../view/type/notice/UrgentNoticeView";
@RegPresenter(UrgentNoticeViewType)
export default class UrgentNoticeViewPresenter extends Presenter<undefined, UrgentNoticeView>{
static uuid = "UrgentNoticeViewPresenter"
private _viewProps: UrgentNoticeViewProps;
private _delayTime: number = 0;
private _closeTimeTicker: number = -1;
private _canClose: boolean = false;
constructor() {
super();
this._viewProps = {
onCloseButtonClickCalback: this.onCloseButtonClickCalback,
};
}
onOpen() {
super.onOpen(undefined);
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.getUrgentNoticeInfo().readed ? 0 : 3;
//重置提示文本状态
this.view.getCloseTipsLabel().string = "";
//根据存档初始化“今日不再提示”的选择框
let autoShow = GameModelManager.getUrgentNoticeInfo().autoShow;
this.view.getTipsToggle().isChecked = !autoShow;
this.startTimeTicker();
}
/**
* 开启可关闭定时器
*/
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);
}
}
/**
* 检查“今日不再提示”单选框的选择状态
*/
checkTipsToggleState() {
let isChecked = this.view.getTipsToggle().isChecked;
GameModelManager.setUrgentNoticeInfo({ readed: true, autoShow: !isChecked });
}
/**关闭界面按钮的点击事件 */
onCloseButtonClickCalback = () => {
if (this._canClose) {
this.checkTipsToggleState();
clearTimeout(this._closeTimeTicker);
this.view.close();
}
}
}