UIGoldenAim.ts 2.78 KB
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { SaveDataManager } from "../../component/SaveDataManager";
import { ADID, tMgr, WindowName } from "../../Global";

import { GamePlayTable, TableName } from "../../kernel/table/TableDefine";
import { UIBase } from "../UIBase";
import { UIManager } from "../UIManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class UIGoldenAim extends UIBase {
    @property(cc.Node)
    btn_ad: cc.Node = null;
    @property(cc.Node)
    btn_start: cc.Node = null;
    @property(cc.Node)
    btn_bonus: cc.Node = null;
    openCount: number = 0;

    protected onEnable(): void {
        let price = (tMgr.getConfig(TableName.GAME_PLAY, 15) as GamePlayTable).Value;

        this.node.getChildByName('btnDiamond').getComponentInChildren(cc.Label).string = price.toString();


        this.btn_ad.getChildByName('Background').getChildByName('UI_General_Btn_yellow_ckgg').active = true;
        this.btn_ad.getChildByName('Background').getChildByName('UI_Finish_kxsx').active = false;

        this.openCount++;
        if (this.openCount > 1) {
            this.BtnPos_Change();
        }
    }

    //按钮位置轮换
    BtnPos_Change() {
        let tempPos = this.btn_start.position;
        this.btn_start.position = this.btn_bonus.position;
        this.btn_bonus.position = this.btn_ad.position;
        this.btn_ad.position = tempPos;
    }

    onCloseClick() {
        this.close();
    }

    onBuyClick() {

        let price = (tMgr.getConfig(TableName.GAME_PLAY, 15) as GamePlayTable).Value;
        // this.node.getChildByName('btnDiamond').getComponentInChildren(cc.Label).string = price

        if (SaveDataManager.ins.adjustDiamond(-price)) {
            let sec = (tMgr.getConfig(TableName.GAME_PLAY, 31) as GamePlayTable).Value;
            let endTime = Date.now() + sec * 1000;
            SaveDataManager.ins.runtimeData.goldenAimEndTime = endTime;
            SaveDataManager.ins.saveData();

            this.close();
        }
    }

    onAdTryClick() {
        //AD 放广告,放完后调用 onTry
        // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => {
        if (true) {
            this.onTry();
        } else {
            console.log('视频播放失败');
        }
        // });
    }

    private onTry() {
        SaveDataManager.ins.runtimeData.goldenAimTry = true;
        this.close();
    }

    close(): void {
        UIManager.ins.closeWindow(WindowName.GOLDEN_AIM);
        // HeyGamePlatform.instance.hideGameNativeAd();
    }
}