WardrobeViewPresenter.ts
10.3 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
import { ResUtils } from "simba-cc-resutils";
import { Presenter } from "../../../../common/classbase/PresenterBase";
import { GameConstData } from "../../../../common/gameplay/gamedata/GameConstData";
import { UIManager } from "../../../../common/gameplay/managers/UIManager";
import { channel } from "../../../../GameConfig";
import { BedRoomCatModelManager, SuitStatus } from "../../../model/BedRoomCatModelManager";
import { GameModelManager } from "../../../model/GameModelManager";
import { RegPresenter } from "../../PresenterCCViewFactory";
import SuitItem from "../../SuitItem";
import { AlertDialogViewProps } from "../../view/type/AlertDialogView";
import { WardrobeViewType, WardrobeViewProps, WardrobeView } from "../../view/type/WardrobeView";
import AlertDialogViewPresenter from "../AlertDialogViewPresenter";
@RegPresenter(WardrobeViewType)
export default class WardrobeViewPresenter extends Presenter<WardrobeViewProps, WardrobeView>{
static uuid = "WardrobeViewPresenter";
private _viewProps: WardrobeViewProps;
private _suitId = 0;
private _nextStep = -1;
private _wardrobeIntroductionString = "通过完成任务,收集碎片,收集完所有碎片就可以解锁梵优的新衣服啦!";
constructor() {
super();
}
onOpen(props: WardrobeViewProps) {
super.onOpen(props);
this._viewProps = props;
this._viewProps.onWearBtnClickCallBack = this.onWearBtnClickCallBack;
this._viewProps.onShareBtnClickCallBack = this.onShareBtnClickCallBack;
this._viewProps.onTabBtnClickCallBack = this.onTabBtnClickCallBack;
this._viewProps.onBackBtnClickCallBack = this.onBackBtnClickCallBack;
this.view.setProps(this._viewProps);
this.onShow();
}
onShow() {
super.onShow();
this.setIntroductionIconTouchEvent();
this.onTabBtnClickCallBack(1);
}
onClose() {
super.onClose();
}
onEnterBackground() {
super.onEnterBackground();
}
onEnterForeground() {
super.onEnterForeground();
}
setIntroductionIconTouchEvent() {
let introductionIconNode = this.view.getIntroductionIconNode();
let introductionNode = this.view.getIntroductionNode();
introductionIconNode.on(cc.Node.EventType.TOUCH_START, function (event) {
introductionNode.active = true;
}, this);
introductionIconNode.on(cc.Node.EventType.TOUCH_END, function (event) {
introductionNode.active = false;
}, this);
introductionIconNode.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {
introductionNode.active = false;
}, this);
}
updateRedDot() {
for (let i = 1; i < 4; i++) {
let suitStatus = BedRoomCatModelManager.checkSuitStatus(i);
let suitIsClicked = BedRoomCatModelManager.getSuitIsClicked(i);
if (suitStatus !== SuitStatus.Lock && !suitIsClicked) {
this.view.getRedDotNodes()[i - 1].active = true;
} else {
this.view.getRedDotNodes()[i - 1].active = false;
}
}
}
async checkWearBtnStatus(suitId: number) {
let suitStatus = BedRoomCatModelManager.checkSuitStatus(suitId);
if (suitStatus !== SuitStatus.Lock) {
BedRoomCatModelManager.saveSuitIsClicked(suitId);
}
switch (suitStatus) {
case SuitStatus.Lock:
this.view.getWearBtn().node.active = false;
this.view.getRolePortrait().node.active = false;
this.view.getRolePortraitLock().node.active = true;
this.view.getRolePortraitLockLabel().string = "收集完所有碎片才可解锁哦";
this.view.getRolePortrait().spriteFrame = undefined as unknown as cc.SpriteFrame;
this.view.getRolePortraitLock().spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + suitId + "lock", cc.SpriteFrame);
break;
case SuitStatus.Unlock:
this.view.getWearBtn().node.active = true;
this.view.getWearBtn().interactable = true;
this.view.getRolePortrait().node.active = true;
this.view.getRolePortraitLock().node.active = false;
this.view.getRolePortrait().spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + suitId, cc.SpriteFrame);
this.view.getRolePortraitLock().spriteFrame = undefined as unknown as cc.SpriteFrame;
this.view.getWearBtn().getComponentInChildren(cc.Sprite).spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "wearBtn", cc.SpriteFrame);
break;
case SuitStatus.Wear:
this.view.getWearBtn().node.active = true;
this.view.getWearBtn().interactable = false;
this.view.getRolePortrait().node.active = true;
this.view.getRolePortraitLock().node.active = false;
this.view.getRolePortrait().spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + suitId, cc.SpriteFrame);
this.view.getRolePortraitLock().spriteFrame = undefined as unknown as cc.SpriteFrame;
this.view.getWearBtn().getComponentInChildren(cc.Sprite).spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "wearedBtn", cc.SpriteFrame);
break;
default:
break;
}
}
checkShareBtnStatus(suitId: number) {
let isShow = BedRoomCatModelManager.checkIsShowSuitShareBtnBySuitId(suitId);
this.view.getShareBtn().node.active = isShow;
}
onWearBtnClickCallBack = () => {
BedRoomCatModelManager.changeUsingSuitId(this._suitId);
this.checkWearBtnStatus(this._suitId);
UIManager.showSceneToast("已穿戴当前套装,约会人物立绘将替换为当前套装!", 0.5);
let isShow = BedRoomCatModelManager.checkIsShowSuitShareBtnBySuitId(this._suitId);
if (isShow) {
this.onShareBtnClickCallBack();
}
}
onShareBtnClickCallBack = () => {
let temp: AlertDialogViewProps = {
dataptr: { bgPath: GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "wardrobeBg", rolePath: GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + this._suitId },
titlecontent: "提示",
content: "小主穿戴了服装,快去分享给小伙伴吧,分享可得4个猫粮哦~",
ishasad: false,
istwobtn: true,
adconfig: "default",
hasBanner: false,
callback: (type, ret) => {
if (ret || channel === "dummy") {
//保存分享存档
BedRoomCatModelManager.saveSuitShareStatusBySuitId(this._suitId);
this.checkShareBtnStatus(this._suitId)
//分享奖励
BedRoomCatModelManager.addCatFoodNumberByFoodId(1, 4)
UIManager.showSceneToast("猫粮数量+4");
}
},
isShareScreen: true
};
UIManager.pushPresenter(AlertDialogViewPresenter, temp);
}
onTabBtnClickCallBack = async (suitId: number) => {
this._suitId = suitId;
this.view.getStayTunedNode().active = false;
this.view.getScrollViewContentNode().removeAllChildren();
let suitButtons = this.view.getSuitButtons();
for (let i = 0; i < suitButtons.length; i++) {
if (i == suitId - 1) {
suitButtons[i].normalSprite = this.view.getSuitButtonSprites()[1];
} else {
suitButtons[i].normalSprite = this.view.getSuitButtonSprites()[0];
}
}
for (let i = 0; i < suitButtons.length; i++) {
if (i == suitId - 1) {
suitButtons[i].getComponentInChildren(cc.Sprite).spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "tabBtn", cc.SpriteFrame);
} else {
suitButtons[i].getComponentInChildren(cc.Sprite).spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SPR_DIR + "tabBtnGray", cc.SpriteFrame);
}
}
//套装3为未开发套装,暂时特殊处理
if (suitId == 3) {
this.view.getStayTunedNode().active = true;
this.view.getWearBtn().node.active = false;
this.view.getShareBtn().node.active = false;
this.view.getRolePortrait().node.active = false;
this.view.getRolePortraitLock().node.active = true;
this.view.getRolePortraitLockLabel().string = "敬请期待";
this.view.getRolePortrait().spriteFrame = undefined as unknown as cc.SpriteFrame;
this.view.getRolePortraitLock().spriteFrame = await ResUtils.loadRes(GameConstData.GAME_CONST_BEDROOMCAT_SUIT_SPR_DIR + "3lock", cc.SpriteFrame);
return;
}
//套装1居中适配,在前后各加一个空的预制体
if (suitId == 1) {
let item = cc.instantiate(this.view.getSuitItemNull());
item.parent = this.view.getScrollViewContentNode();
}
let suitConfigs = BedRoomCatModelManager.getSuitConfigBySuitId(suitId);
for (let i = 0; i < suitConfigs.length; i++) {
let item = cc.instantiate(this.view.getSuitItem());
if (suitConfigs[i].isUnlock) {
BedRoomCatModelManager.saveUnlockClothingBySuitId(suitConfigs[i].suitId, suitConfigs[i].clothingId);
}
let unlockClothing = BedRoomCatModelManager.getUnlockClothingBySuitId(suitId);
let showLockRootNode = unlockClothing.indexOf(suitConfigs[i].clothingId) == -1;
item.getComponent(SuitItem).setData(suitConfigs[i], showLockRootNode);
item.parent = this.view.getScrollViewContentNode();
}
//套装1居中适配,在前后各加一个空的预制体
if (suitId == 1) {
let item = cc.instantiate(this.view.getSuitItemNull());
item.parent = this.view.getScrollViewContentNode();
}
this.checkWearBtnStatus(suitId);
this.checkShareBtnStatus(suitId);
this.updateRedDot();
}
onBackBtnClickCallBack = () => {
this.view.close();
}
}