SpecialPlotViewPresenter.ts
6.4 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
import { ConfigManager } from "simba-config-manager";
import { SDK } from "simba-sdk";
import { DeepReadonlyObject } from "simba-utils";
import { Presenter } from "../../../common/classbase/PresenterBase";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { IStoryTbl, storyTbl } from "../../../config/StoryTbl";
import GameCenter from "../../../cooperation/script/GameCenter";
import { channel, GameConfig } from "../../../GameConfig";
import GameDotMgr from "../../GameDotMgr";
import { GameModelManager } from "../../model/GameModelManager";
import UnlockSpecialPlotEventManager from "../../model/UnlockSpecialPlotEventManager";
import { UnlockSpecialPlotModelManager } from "../../model/UnlockSpecialPlotModelManager";
import { RegPresenter } from "../PresenterCCViewFactory";
import { SpecialPlotViewType, SpecialPlotViewProps, SpecialPlotView } from "../view/type/SpecialPlotView";
@RegPresenter(SpecialPlotViewType)
export default class SpecialPlotViewPresenter extends Presenter<SpecialPlotViewProps, SpecialPlotView>
{
static uuid = "SpecialPlotViewPresenter";
private _viewProps: SpecialPlotViewProps;
private _value: number = 0;
private _cfg: DeepReadonlyObject<IStoryTbl> | undefined = undefined;
constructor() {
super();
}
onOpen(props: SpecialPlotViewProps) {
super.onOpen(props);
this._viewProps = props;
this._viewProps.onLeftBtnClick = this.onLeftBtnClickCallBack;
this._viewProps.onRightBtnClick = this.onRightBtnClickCallBack;
this._viewProps.createGameClubBtn = this.createGameClubBtn;
this._viewProps.onShopBtnClick = this.onShopBtnClickCallBack;
this._viewProps.onCloseBtnClick = this.onCloseBtnClick;
this.view.setProps(this._viewProps);
this.onShow();
}
onShow() {
super.onShow();
this.showSpecialPlot(this._viewProps.specialPlotIds[this._value]);
this.createGameClubBtn();
this.showGameClubBtn();
}
onClose() {
super.onClose();
SDK.destroyGameClubButton();
}
onEnterBackground() {
super.onEnterBackground();
this.hideGameClubBtn();
}
onEnterForeground() {
super.onEnterForeground();
this.showGameClubBtn();
}
showGameClubBtn() {
SDK.showGameClubButton();
}
hideGameClubBtn() {
SDK.hideGameClubButton();
}
showSpecialPlot(specialPlotId: number) {
try {
if (specialPlotId) {
this._cfg = ConfigManager.getConfig(storyTbl, specialPlotId);
if (this._cfg) {
this.view.getSpecialPlotTitleNode()!.getComponent(cc.Label).string = this._cfg.title;
let cfgStr: string[] = this._cfg.content.split("%%");
let specialPlotNodeStr = "";
for (let i = 0; i < cfgStr.length; i++) {
specialPlotNodeStr = specialPlotNodeStr + cfgStr[i] + "\n";
}
this.view.getSpecialPlotNode()!.getComponent(cc.Label).string = specialPlotNodeStr;
UnlockSpecialPlotModelManager.saveClickedSpecialPlotIdByItemIdToGameRecord(specialPlotId);
}
this.updateLeftOrRightBtnStatus();
this.updateRightBtnRedDotStatus();
this.view.getSpecialPlotScrollView().scrollToTop();
}
} catch (error) {
console.error(error);
}
}
updateLeftOrRightBtnStatus() {
//处理左按钮显隐,右按钮暂不处理
if (this._value <= 0) {
this.view.showLeftBtn(false);
} else {
this.view.showLeftBtn(true);
}
}
onLeftBtnClickCallBack = () => {
if (this._value <= 0) {
return;
} else {
this._value -= 1;
this.showSpecialPlot(this._viewProps.specialPlotIds[this._value]);
}
}
onRightBtnClickCallBack = () => {
if (this._value >= this._viewProps.specialPlotIds.length - 1) {
UIManager.showToast(this._cfg!.toastMsg);
return;
} else {
this._value += 1;
this.showSpecialPlot(this._viewProps.specialPlotIds[this._value]);
}
}
createGameClubBtn = () => {
this.view.getViewNode()!.getComponent(cc.Widget).updateAlignment();
let info = SDK.systemInfo.displayInfo;
let aspect = info.windowSize.height / cc.view.getVisibleSize().height;
this.view.getViewNode()!.getComponent(cc.Widget).updateAlignment();
let pos = this.view.getForumBtnNode()!.convertToWorldSpaceAR(cc.v2(0, 0));
pos.x += cc.view.getViewportRect().x / cc.view.getScaleX();
let xPos = pos.x * aspect;
let yPos = info.windowSize.height - pos.y * aspect;
let width = this.view.getForumBtnNode()!.width * aspect;
let height = this.view.getForumBtnNode()!.height * aspect;
let left = xPos - width / 2;
let top = yPos - height / 2;
SDK.createGameClubButton({
type: "text",
text: "",
style: {
left: left,
top: top,
width: width,
height: height
},
icon: "green"
});
}
onShopBtnClickCallBack = () => {
GameDotMgr.getInstance().dotClickUI("shop_btn_specoalPlot");
let type = GameModelManager.getTypeByBedroomItemId(this._viewProps.itemId);
if (channel == "wechat") {
// GameCenter.getInstance().openSubProgram(GameConfig.youZanShopAppId);
if (type) {
let link = GameModelManager.getYouZanShopUrlByType(type);
if (link) {
SDK.openProgramV2(GameConfig.youZanShopAppId, link);
}
}
} else if (channel == "android") {
if (type) {
let link = GameModelManager.getTaoBaoShopUrlByType(type);
if (link) {
GameModelManager.jumpToTaobaoShop(link);
}
}
} else {
UIManager.showToast("该功能在当前平台不可使用");
}
}
onCloseBtnClick = () => {
this.view.close();
GameModelManager.BackToBedRoom.emit();
}
updateRightBtnRedDotStatus() {
this.view.showRedDot(UnlockSpecialPlotEventManager.getInstance().isShowBedRoomRedDotStatus(this._viewProps.itemId));
}
}