ShareSuitViewPresenter.ts 4.87 KB
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;
    }
}