AlertDialogViewImpl.ts 8.51 KB
import { RegView } from "../../PresenterCCViewFactory";
import { AlertDialogViewType, AlertDialogViewProps, AlertDialogView } from "../type/AlertDialogView";
import { CCPureView } from "../../../../common/classbase/CCViewBase";
import { DummyLabel, DummyNode, DummyButton, DummyRichText } from "../../../../common/CCDummyObjects";
import SVButton from "simba-sdk-ccsvbutton";
import { ShowType, ShowLocationType } from "../../../Enums";
import GameDotMgr from "../../../GameDotMgr";
import { SDK } from "simba-sdk";
import { GameConstData } from "../../../../common/gameplay/gamedata/GameConstData";
import { SVPoint } from "simba-sdk/dist/SDKTypes";
import { DeepReadonly } from "simba-utils";
import { GetRewardType } from "../../../../common/gameplay/gamedata/GameEnumData";
import { channel, GameConfig } from "../../../../GameConfig";
import { UIManager } from "../../../../common/gameplay/managers/UIManager";
import { GameModelManager } from "../../../model/GameModelManager";


const { ccclass, property } = cc._decorator;

@ccclass
@RegView(AlertDialogViewType, "prefab/ui/AlertDialogView")
export default class AlertDialogViewImpl extends CCPureView<AlertDialogViewProps> implements AlertDialogView {
    //#region 
    @property(cc.Label)
    titlelabel: cc.Label = DummyLabel;

    @property(cc.RichText)
    content: cc.RichText = DummyRichText;

    @property(cc.Node)
    twobtnmode: cc.Node = DummyNode;

    @property(cc.Button)
    okbtn: cc.Button = DummyButton;

    @property(cc.Button)
    adokbtn: cc.Button = DummyButton;

    @property(SVButton)
    adsvbtn: SVButton = undefined as any;

    @property(cc.Node)
    onebtnmode: cc.Node = DummyNode;

    @property(cc.Node)
    opacityBtn: cc.Node = DummyNode;

    @property(cc.Node)
    banner: cc.Node = DummyNode;

    @property(cc.Node)
    cancelNode: cc.Node = DummyNode;
    @property(cc.Node)
    cancelNode2: cc.Node = DummyNode;
    @property(cc.Node)
    cancelNode3: cc.Node = DummyNode;
    @property(cc.Node)
    shopNode: cc.Node = DummyNode;
    @property(cc.Node)
    shareScreenNode: cc.Node = DummyNode;

    svType: GetRewardType = GetRewardType.Ad;

    onLoad() {
        this.adsvbtn.loadSVConfig();
        this.bindProp("titlecontent", (value) => {
            this.titlelabel.string = value;
        });

        this.bindProp("content", (value) => {
            this.content.string = value;
        });

        this.bindProp("ishasad", (value) => {
            if (this._props.istwobtn) {
                this.adokbtn.node.active = value;
                this.okbtn.node.active = !value;
                this.adsvbtn.enabled = true;
            }

        });

        this.bindProp("istwobtn", (value) => {
            this.twobtnmode.active = value;
            let hasad = this._props.ishasad;
            this.adokbtn.node.active = hasad;
            this.okbtn.node.active = !hasad;
            this.onebtnmode.active = !value;
        });

        this.bindProp("adconfig", (value) => {
            this.adsvbtn.enabled = (value !== "");
            if (value !== "") {
                this.adsvbtn.sharePointId = value;
                this.adsvbtn.loadSVConfig();
            }
        });

        this.bindProp("isthreebtn", (value) => {
            let three: boolean = value ? true : false;
            this.shopNode.active = three;
            this.cancelNode2.active = three;
            this.cancelNode.active = !three;
        });

        this.bindProp("isadlimit", (value) => {
            let isadlimit: boolean = value ? true : false;
            this.shopNode.active = isadlimit;
            this.cancelNode3.active = isadlimit;
            this.adokbtn.node.active = !isadlimit;
        });

        this.bindProp("isShareScreen", (value) => {
            let isShareScreen: boolean = value ? true : false;
            this.shareScreenNode.active = isShareScreen;
            this.adokbtn.node.active = !isShareScreen;
        });

        this.adsvbtn.onResult = ((type, ret) => {
            this._props.callback(type, ret, this._props.dataptr);
            if (ret && this._props.location) {
                if (type === "share") {
                    GameDotMgr.getInstance().dotShare(ShowType.FINISH, ShowLocationType.Share + this._props.location);
                }
                if (type === "video") {
                    GameDotMgr.getInstance().dotVideo(ShowType.FINISH, ShowLocationType.Video + this._props.location);
                }
            }
            this.closeView();
        });

        this.adsvbtn.onConfigLoaded = (svPoint: DeepReadonly<SVPoint>) => {
            if (svPoint.type === "share") {
                this.svType = GetRewardType.Share;
            } else {
                this.svType = GetRewardType.Ad;
            }
        }

    }

    onOkClickCallback(event) {
        this._props.callback("", true, this._props.dataptr);
        this.closeView();
    }

    onCancleClickCallback(event) {
        this._props.callback("", false, this._props.dataptr);
        this.closeView();
    }

    onGoToShopClickCallback(event) {
        this._props.callback("", false, this._props.dataptr);
        GameDotMgr.getInstance().dotClickUI("shop_btn_AlertDialogView");
        if (channel == "wechat") {
            // GameCenter.getInstance().openSubProgram(GameConfig.youZanShopAppId);
            let link = GameModelManager.getYouZanShopUrlByType(2);
            if (link) {
                SDK.openProgramV2(GameConfig.youZanShopAppId, link);
            }
        } else if (channel == "android") {
            let link = GameModelManager.getTaoBaoShopUrlByType(2);
            if (link) {
                GameModelManager.jumpToTaobaoShop(link);
            }
        } else {
            UIManager.showToast("该功能在当前平台不可使用");
        }
    }

    onShareScreenClickCallback(event) {
        
    }

    onADBtnClick() {
        let type = this.getSvBtnType();
        if (type && "" !== type.trim()) {
            if (this._props.location) {
                if (type === "share") {
                    GameDotMgr.getInstance().dotShare(ShowType.CLICK, ShowLocationType.Share + this._props.location);
                }
                if (type === "video") {
                    GameDotMgr.getInstance().dotVideo(ShowType.CLICK, ShowLocationType.Video + this._props.location);
                }
            }
        }
        this.opacityBtn.active = true;
    }

    getSvBtnType = (): string => {
        let ret = "";
        if (this.adsvbtn.svPoint) {
            ret = this.adsvbtn.svPoint.type;
        }
        return ret;
    }

    closeView() {
        SDK.hideBannerAd();
        this.close();
        this.opacityBtn.active = false;
    }

    switchAdConfig(props: AlertDialogViewProps) {
        if (props.istwobtn) {//两个按钮的
            if (props.adconfig && "" !== props.adconfig.trim()) {
                this.adsvbtn.sharePointId = props.adconfig;
                this.adsvbtn.loadSVConfig();
                let svType = this.getSvBtnType();
                if (svType && "" !== svType.trim() && props.location && props.ishasad) {
                    if (svType === "share") {
                        GameDotMgr.getInstance().dotShare(ShowType.SHOW, ShowLocationType.Share + props.location);
                    }
                    if (svType === "video") {
                        GameDotMgr.getInstance().dotVideo(ShowType.SHOW, ShowLocationType.Video + props.location);
                    }
                }
            }
        }
    }

    showView = (props: AlertDialogViewProps) => {
        this.opacityBtn.active = false;
        this.switchAdConfig(props);
        if (!props.hasBanner) {
            SDK.hideBannerAd();
            return;
        }
        let info = SDK.systemInfo.displayInfo;
        let aspect = info.windowSize.height / cc.view.getVisibleSize().height;
        this.node.getComponent(cc.Widget).updateAlignment();

        let _width = this.banner.width * aspect;
        let _height = this.banner.height * aspect;
        let _left = (info.windowSize.width - _width) * 0.5;
        let _top = info.windowSize.height - _height;

        let style = {
            left: _left,
            top: _top,
            width: _width,
            height: _height,
            anchorX: 0.5,
            anchorY: 1,
        }
        SDK.showBannerAd(style, GameConstData.GAME_CONST_BANNER_REFRESH_TIME);
    }



}