ShareSuitViewPresenter.ts
4.87 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
import { ResUtils } from "simba-cc-resutils";
import CCWechatScreenShotMgr from "../../../../common/CCWechatScreenShotMgr";
import { Presenter } from "../../../../common/classbase/PresenterBase";
import { UIManager } from "../../../../common/gameplay/managers/UIManager";
import { RegPresenter } from "../../PresenterCCViewFactory";
import { ShareSuitViewType, ShareSuitViewProps, ShareSuitView } from "../../view/type/ShareSuitView";
@RegPresenter(ShareSuitViewType)
export default class ShareSuitViewPresenter extends Presenter<ShareSuitViewProps, ShareSuitView>{
static uuid = "ShareSuitViewPresenter";
private _viewProps: ShareSuitViewProps;
private _onShow: boolean = false;
constructor() {
super();
}
onOpen(props: ShareSuitViewProps) {
super.onOpen(props);
this._viewProps = props;
this._viewProps.bgSpritePath = props.bgSpritePath;
this._viewProps.rolePortraitSpritePath = props.rolePortraitSpritePath;
this._viewProps.onCloseBtnClickCallback = this.onCloseBtnClickCallback;
this.view.setProps(this._viewProps);
this.onShow();
}
onShow() {
super.onShow();
this.showShareSuitRolePortrait();
}
onClose() {
super.onClose();
}
onEnterBackground() {
super.onEnterBackground();
}
onEnterForeground() {
super.onEnterForeground();
}
async showShareSuitRolePortrait() {
this._onShow = true;
this.view.getShareSuitViewBgSprite().spriteFrame = await ResUtils.loadRes(this._viewProps.bgSpritePath, cc.SpriteFrame);
this.view.getShareSuitViewRolePortraitSprite().spriteFrame = await ResUtils.loadRes(this._viewProps.rolePortraitSpritePath, cc.SpriteFrame);
let shareNode = this.view.getShareNode();
let shareNodeWorldSpace = shareNode.convertToWorldSpaceAR(cc.v2(0, 0));
CCWechatScreenShotMgr.getInstance().doShot(shareNodeWorldSpace, shareNode.width, shareNode.height,
() => { // successCallback
// 延迟2s退出
cc.tween(this.view.getViewNode()).delay(2).call(() => {
this.onCloseBtnClickCallback();
this._viewProps.shareSuitViewCallback(true);
console.log('ShowShareSuitRolePortrait successCallback');
}).start();
},
(): boolean => { // successCheckCallback
console.log('ShowShareSuitRolePortrait successCheckCallback: ', this._onShow);
return this._onShow;
},
() => { // shareFailCallback
console.log('ShowShareSuitRolePortrait shareFailCallback');
this._viewProps.shareSuitViewCallback(false);
UIManager.showSceneToast("自动截图失败,请升级微信哦~");
this.onCloseBtnClickCallback();
},
() => { // failCallback
console.log('ShowShareSuitRolePortrait failCallback');
this._viewProps.shareSuitViewCallback(false);
UIManager.showSceneToast("自动截图失败,请稍后重试哦~");
this.onCloseBtnClickCallback();
},
() => { // completeCallback
console.log('ShowShareSuitRolePortrait completeCallback');
}
);
// CCWechatScreenShotMgr.getInstance().shotFullScreen(
// () => { // successCallback
// // 延迟2s退出
// cc.tween(this.view.getViewNode()).delay(2).call(() => {
// this.onCloseBtnClickCallback();
// this._viewProps.shareSuitViewCallback(true);
// console.log('ShowShareSuitRolePortrait successCallback');
// }).start();
// },
// (): boolean => { // successCheckCallback
// console.log('ShowShareSuitRolePortrait successCheckCallback: ', this._onShow);
// return this._onShow;
// },
// () => { // shareFailCallback
// console.log('ShowShareSuitRolePortrait shareFailCallback');
// this._viewProps.shareSuitViewCallback(false);
// UIManager.showSceneToast("自动截图失败,请升级微信哦~");
// this.onCloseBtnClickCallback();
// },
// () => { // failCallback
// console.log('ShowShareSuitRolePortrait failCallback');
// this._viewProps.shareSuitViewCallback(false);
// UIManager.showSceneToast("自动截图失败,请稍后重试哦~");
// this.onCloseBtnClickCallback();
// },
// () => { // completeCallback
// console.log('ShowShareSuitRolePortrait completeCallback');
// }
// );
}
onCloseBtnClickCallback = () => {
this.view.close();
this._onShow = false;
}
}