gameLoading.js 5.04 KB
var Common = require('Common');
var Network = require('Network');
var TVFocus = require('TVFocus');
var CCTVFocus = require('CCTVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var TVScrollParameter = require('TVScrollParameter');
var ListView = require('ListView');
var BusinessParameter = require('BusinessParameter');
var ListCell = require('ListCell');

cc.Class({
    extends: TVCanvas,

    properties: {

    },

    onLoad: function () {
        this._super();

        this._oSceneContext._packageName = "";
        this._oSceneContext._className = "";
        this._oSceneContext._downloadUrl = "";

        let aSceneContext = this._cApplication.getSceneContext();
        let aSceneParameter = this._cApplication.getSceneParameter();
        if (aSceneParameter.length) {
            this._oSceneContext._packageName = aSceneParameter[aSceneParameter.length - 1].packageName;
            this._oSceneContext._className = aSceneParameter[aSceneParameter.length - 1].className;
            this._oSceneContext._downloadUrl = aSceneParameter[aSceneParameter.length - 1].downloadUrl;
        } else if (aSceneParameter) {
            this._oSceneContext._packageName = aSceneParameter.packageName;
            this._oSceneContext._className = aSceneParameter.className;
            this._oSceneContext._downloadUrl = aSceneParameter.downloadUrl;
        }

        cc.log("gameLoading包名:" + this._oSceneContext._downloadUrl);

        if (!cc.sys.isNative) {
            return;
        }
        if (this._oSceneContext._downloadUrl && this._oSceneContext._downloadUrl != "undefined") { //如果有下载地址就启动奥比游戏
            jsb.reflection.callStaticMethod("org/cocos2dx/javascript/common/TopdrawSDKWrapper", "startOBiGame", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", this._oSceneContext._downloadUrl, this._oSceneContext._packageName, this._oSceneContext._className, "updateProgress");
        } else {
            jsb.reflection.callStaticMethod("org/cocos2dx/javascript/common/TopdrawSDKWrapper", "startGame", "(Ljava/lang/String;Ljava/lang/String;)V", this._oSceneContext._packageName, "updateProgress");
        }
    },

    updateProgress: function (strProgress) {
        this._cLog.screenI("gameLoading下载进度:" + strProgress);
        cc.find("ProgressLabel", this.node).getComponent(cc.Label).string = strProgress + "%";
        let progressBarWidth = cc.find("ProgressBar", this.node).width - 7;//
        let nodeBar = cc.find("ProgressBar/bar", this.node);
        nodeBar.width = strProgress / 100 * progressBarWidth;

        if (strProgress == "100") {
            this._bIsFocusInit = true;
            this.backAScene();
        }
    },

    keyDownDirection: function (Direct) {
        var fiFocusTarget = null;
        var fiCurrentFocus = this._fiCurrentFocus;
        var oScrollParameter = null;
        let aCheckResult;
        fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Direct);
        if (!fiFocusTarget) { return; }
        // aCheckResult = this.checkFocusTarget(fiFocusTarget, oScrollParameter);
        // fiFocusTarget = aCheckResult[0];
        // oScrollParameter = aCheckResult[1];
        this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
    },

    onKeyDown: function (event) {
        this._super(event);
        switch (event.keyCode) {
            case cc.macro.KEY.up:
            case Common.ANDROID_KEY.up:
                this.keyDownDirection(Common.MOVE_DIRECTION_UP);
                break;
            case cc.macro.KEY.right:
            case Common.ANDROID_KEY.right:
                this.keyDownDirection(Common.MOVE_DIRECTION_RIGHT);
                break;
            case cc.macro.KEY.down:
            case Common.ANDROID_KEY.down:
                this.keyDownDirection(Common.MOVE_DIRECTION_DOWN);
                break;
            case cc.macro.KEY.left:
            case Common.ANDROID_KEY.left:
                this.keyDownDirection(Common.MOVE_DIRECTION_LEFT);
                break;
            case cc.macro.KEY.enter:
            case cc.macro.KEY.space:
            case Common.ANDROID_KEY.enter:
                // this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
                break;
            case cc.macro.KEY.backspace:
            case Common.ANDROID_KEY.back:
                this._bIsFocusInit = true;
                if (this._oSceneContext._downloadUrl && this._oSceneContext._downloadUrl != "undefined") { //如果有下载地址就启动奥比游戏
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/common/TopdrawSDKWrapper", "closeDownloadObiApk", "()V");
                }
                this.backAScene();
                break;
        }
    },

    // hideLoadingIcon: function () {
    //     cc.log("隐藏LoadingIcon...");
    //     cc.find("Loading/LoadingIcon", this.node).getComponent(cc.Animation).pause();
    //     cc.find("Loading/LoadingIcon", this.node).opacity = 0;
    //     this.cheduleOn
    // },

});