DatingEventViewPresenter.ts
3.37 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
import { Presenter, Subpresenter } from "../../../common/classbase/PresenterBase";
import { DatingEventViewType, DatingEventView } from "../view/type/DatingEventView";
import { RegPresenter, RegSubpresenter } from "../PresenterCCViewFactory";
import { DatingEventSubviewType, DatingEventItemProps, DatingEventSubview } from "../view/type/DatingEventSubview";
import { GameModelManager } from "../../model/GameModelManager";
import { DatingEventSceneModel, DatingEventStatus } from "../../model/DatingEventSceneModel";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { DatingScenePresenter } from "./DatingScenePresenter";
@RegPresenter(DatingEventViewType)
export default class DatingEventViewPresenter extends Presenter<undefined, DatingEventView> {
static uuid = "DatingEventViewPresenter";
onOpen() {
super.onOpen(undefined);
this.checkRedDot();
}
onEnterForeground() {
super.onEnterForeground();
this.checkRedDot();
}
onShow() {
super.onShow();
this.checkRedDot();
}
private checkRedDot() {
let mainRedDot = false;
for (let model of GameModelManager.getMainDatingEventScenesModel()) {
if (model.status === DatingEventStatus.New || model.status === DatingEventStatus.InProgress) {
mainRedDot = true;
}
}
this.view.setProps({ mainEventRedDot: mainRedDot, extraEventRedDot: false });
}
}
@RegSubpresenter(DatingEventSubviewType)
export class DatingEventSubpresenter extends Subpresenter<DatingEventSubview> {
// private _items: DatingEventItemProps[];
private _lineStyle: 0 | 1 = 0;
private _modelMap: { [key: string]: DatingEventSceneModel } = {};
private sceneModelToViewModel(item: DatingEventSceneModel): DatingEventItemProps {
this._modelMap[item.id] = item;
return {
key: item.id + "",
title: item.config.name,
date: item.config.date,
time: item.config.time,
status: item.status,
coverImage: "textures/dating_event/cover/" + item.config.background,
lineStyle: this._lineStyle
}
}
refreshItems() {
// if (!this._items) {
if (this.view.name.indexOf("MainEvent") < 0) this._lineStyle = 1;
let items: DatingEventItemProps[] = [];
if (this.view.name.indexOf("MainEvent") === 0) {
items = GameModelManager.getMainDatingEventScenesModel().map(v => this.sceneModelToViewModel(v));
if (items.length) {
items[items.length - 1].lineStyle = "none";
}
}
this.view.setProps({
items, onItemClick: (key: string) => {
console.log("start dating event", key);
UIManager.pushPresenter(DatingScenePresenter, this._modelMap[key], true);
}
});
// } else {
// this.view.updateProps({ items: [...this._items] });
// }
}
onOwnerShow() {
if (!this.view.isHidden) {
this.refreshItems();
}
}
onOwnerEnterForeground() {
if (!this.view.isHidden) {
this.refreshItems();
}
}
onOpen() {
super.onOpen();
if (!this.view.isHidden) {
this.refreshItems();
}
}
onShow() {
this.refreshItems();
}
onHide() {
}
}