PlotStopViewImpl.ts 2.72 KB
import { SDK } from "simba-sdk";
import SVButton from "simba-sdk-ccsvbutton";
import { DummyNode } from "../../../../common/CCDummyObjects";
import { CCPureView } from "../../../../common/classbase/CCViewBase";
import { GameConstData } from "../../../../common/gameplay/gamedata/GameConstData";
import { GetRewardType } from "../../../../common/gameplay/gamedata/GameEnumData";
import { ShowType } from "../../../Enums";
import { RegView } from "../../PresenterCCViewFactory";
import { PlotStopView, PlotStopViewProps, PlotStopViewType } from "../type/PlotStopView";

const { ccclass, property } = cc._decorator;

@ccclass
@RegView(PlotStopViewType, "prefab/ui/PlotStopView")
export default class PlotStopViewImpl extends CCPureView<PlotStopViewProps> implements PlotStopView {
    @property(cc.Node)
    banner: cc.Node = DummyNode;

    @property({ type: SVButton })
    adButton: SVButton = undefined as unknown as SVButton;

    svType: GetRewardType = GetRewardType.Ad;

    onLoad() {
        this.adButton.onResult = (type, ret) => {
            if (ret) {
                this._props.onAddRes(type);
            } else {
                this._props.onCancelAdCallback(this.svType);
            }
            this._props.onAdBtnOption(ShowType.FINISH, type, ret);
        }
    }

    closeView() {
        this.isShowViewBanner(false);
        this.close();
    }


    onEnable() {
        this.isShowViewBanner(true);
        this.adButton.loadSVConfig();

    }

    isShowViewBanner = (isShow: boolean) => {
        if (isShow) {
            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);
        } else {
            SDK.hideBannerAd();
        }
    }

    unlockPlotCallback(event) {
        this._props.unlockPlotCallbackFunc();
    }

    onAdClick() {
        let t = this.getSvBtnType();
        if (t && t === "share" || t === "video") {
            this._props.onAdBtnOption(ShowType.CLICK, t);
        }
    }

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

}