ExchangeCodeViewImpl.ts 2.16 KB
import { ExchangeCodeViewType, ExchangeCodeViewProps, ExchangeCodeView } from "../type/ExChangeCodeView";
import { CCPureView } from "../../../../common/classbase/CCViewBase";
import { RegView } from "../../PresenterCCViewFactory";
import { DummyLabel, DummyNode, DymmyEditBox } from "../../../../common/CCDummyObjects";
import { SDK } from "simba-sdk";
import { GameConstData } from "../../../../common/gameplay/gamedata/GameConstData";

const { ccclass, property } = cc._decorator;

@ccclass
@RegView(ExchangeCodeViewType, "prefab/ui/ExchangeCodeView")
export class ExchangeCodeViewImpl extends CCPureView<ExchangeCodeViewProps> implements ExchangeCodeView {
    @property(cc.Label)
    titlelbl: cc.Label = DummyLabel;

    @property(cc.EditBox)
    editbox: cc.EditBox = DymmyEditBox;

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

    setContentTxt(title: string, content: string) {
        this.titlelbl.string = title;
        this.editbox.string = content;
    }

    onLoad() {
    }

    onCancleClickCallback() {
        this._props.onActionClick(false);
        this.showBanner(false);
        this.close();
    }

    onOkClickCallback() {
        this._props.onActionClick(true, this.editbox.string);
        this.showBanner(false);
        this.close();
    }

    showBanner(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();
        }

    }
}