ItemIntroductionViewPresenter.ts
7.05 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
import { ResUtils } from "simba-cc-resutils";
import { ConfigManager } from "simba-config-manager";
import { SDK } from "simba-sdk";
import { DeepReadonlyObject } from "simba-utils";
import { createPresenter, Presenter } from "../../../common/classbase/PresenterBase";
import { GameConstData } from "../../../common/gameplay/gamedata/GameConstData";
import { UIManager } from "../../../common/gameplay/managers/UIManager";
import { IItemTbl, itemTbl } from "../../../config/ItemTbl";
import GameCenter from "../../../cooperation/script/GameCenter";
import { channel, GameConfig } from "../../../GameConfig";
import GameDotMgr from "../../GameDotMgr";
import { GameModelManager } from "../../model/GameModelManager";
import { UnlockItemModelManager } from "../../model/UnlockItemModelManager";
import UnlockSpecialPlotEventManager from "../../model/UnlockSpecialPlotEventManager";
import { UnlockSpecialPlotModelManager } from "../../model/UnlockSpecialPlotModelManager";
import { RegPresenter } from "../PresenterCCViewFactory";
import { ItemIntroductionView, ItemIntroductionViewProps, ItemIntroductionViewType } from "../view/type/ItemIntroductionView";
import { SpecialPlotViewProps } from "../view/type/SpecialPlotView";
import SpecialPlotViewPresenter from "./SpecialPlotViewPresenter";
@RegPresenter(ItemIntroductionViewType)
export default class ItemIntroductionViewPresenter extends Presenter<ItemIntroductionViewProps, ItemIntroductionView>
{
static uuid = "ItemIntroductionViewPresenter";
private _viewProps: ItemIntroductionViewProps;
private specialPresenter: SpecialPlotViewPresenter | undefined = undefined;
constructor() {
super();
}
onOpen(props: ItemIntroductionViewProps) {
super.onOpen(props);
this._viewProps = props;
this._viewProps.showItemSpr = this.showItemSpr;
this._viewProps.onSpecialPlotBtnClick = this.onSpecialPlotClickCallBack;
this._viewProps.onShopBtnClick = this.onShopBtnClickCallBack;
this.view.setProps(this._viewProps);
this.onShow();
createPresenter(SpecialPlotViewPresenter).then((presenter) => {
this.specialPresenter = presenter;
});
}
onShow() {
super.onShow();
this.showItemSpr(this._viewProps.itemId);
}
onEnterBackground() {
super.onEnterBackground();
}
onEnterForeground() {
super.onEnterForeground();
}
onClose() {
super.onClose();
}
showItemSpr = async (itemId: number) => {
try {
let cfg: DeepReadonlyObject<IItemTbl> | undefined = undefined;
if (itemId) {
cfg = ConfigManager.getConfig(itemTbl, itemId);
if (cfg) {
//如果没有模糊图,那么直接展示简介图
if (cfg.foggy === 0) {
UnlockItemModelManager.saveUnlockedIntroductionItemIdToGameRecord(itemId);
let path: string = GameConstData.GAME_CONST_ITEM_BIG_SPR_DIR + cfg.type;
let itemSpriteFrame = await ResUtils.loadRes(path, cc.SpriteFrame);
this.view.getItemSpriteNode().spriteFrame = itemSpriteFrame;
}
//如果有模糊图,那么就判断是否已经解锁了清晰的简介图
else {
let unlockedIntroduction = false;
let unlockedIntroductionItems = UnlockItemModelManager.unlockedIntroductionItems;
for (let i = 0; i < unlockedIntroductionItems.length; i++) {
if (itemId == unlockedIntroductionItems[i]) {
unlockedIntroduction = true;
}
}
if (!unlockedIntroduction) {
let path: string = GameConstData.GAME_CONST_ITEM_BIG_SPR_DIR + cfg.foggyPicture;
let itemSpriteFrame = await ResUtils.loadRes(path, cc.SpriteFrame);
this.view.getItemSpriteNode().spriteFrame = itemSpriteFrame;
} else {
UnlockItemModelManager.saveUnlockedIntroductionItemIdToGameRecord(itemId);
let path: string = GameConstData.GAME_CONST_ITEM_BIG_SPR_DIR + cfg.type;
let itemSpriteFrame = await ResUtils.loadRes(path, cc.SpriteFrame);
this.view.getItemSpriteNode().spriteFrame = itemSpriteFrame;
}
}
}
}
this.updateSpecialPlotBtnRedDotStatus();
} catch (error) {
console.error(error);
}
}
onSpecialPlotClickCallBack = () => {
let itemCfg: DeepReadonlyObject<IItemTbl> | undefined = undefined;
itemCfg = ConfigManager.getConfig(itemTbl, this._viewProps.itemId);
let unlockedSpecialPlots = UnlockSpecialPlotModelManager.unlockedSpecialPlotIdByItemId(this._viewProps.itemId);
if (itemCfg) {
let unlockedSpecialPlot = false;
if (unlockedSpecialPlots.length > 0) {
unlockedSpecialPlot = true;
}
if (unlockedSpecialPlot) {
this.openSpecialPlotView(this._viewProps.itemId, unlockedSpecialPlots);
} else {
UIManager.showToast(itemCfg.toastMsg);
return;
}
}
this.view.close();
}
openSpecialPlotView(itemId: number, specialPlotIds: number[]) {
if (this.specialPresenter) {
let temp: SpecialPlotViewProps = {
itemId: itemId,
specialPlotIds: specialPlotIds,
onLeftBtnClick: () => { },
onRightBtnClick: () => { },
createGameClubBtn: () => { },
onShopBtnClick: () => { },
onCloseBtnClick: () => { }
};
this.specialPresenter.open(this.view.getContainer(), temp);
}
}
onShopBtnClickCallBack = () => {
GameDotMgr.getInstance().dotClickUI("shop_btn_introduction");
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("该功能在当前平台不可使用");
}
}
updateSpecialPlotBtnRedDotStatus() {
this.view.showSpecialPlotBtnRedDot(UnlockSpecialPlotEventManager.getInstance().isShowBedRoomRedDotStatus(this._viewProps.itemId));
}
}