var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/**
* 启动画面
*/
var view;
(function (view) {
    var Event = Laya.Event;
    var Ev = Laya.Event;
    var StartView = /** @class */ (function (_super) {
        __extends(StartView, _super);
        function StartView() {
            var _this = _super.call(this) || this;
            _this.adObj = null;
            //隐藏框架loading
            //执行登陆

            _this.visible = true;
            Laya.stage.addChild(_this);
            // wx.postMessage({
            //     type: "init", width: Laya.stage.width, height: Laya.stage.height
            // });
            // wx.showShareMenu({ withShareTicket: true });
            // sharehelper.registDefaultShare();
            // //进入游戏首页
            if (StartView.is_first) {
                StartView.is_first = false;
                var obg = {};
                mainInst.mWX.indexBpTotle("homepage_load", obg);
            }
            // this.controlViews(false);
            // 根据soundbox的位置得出对应的屏幕高度(需处理偏移)
            // var offset: number = (Laya.stage.height - 1334) / 2;
            // var referY: number = (this.soundBox.y + 100 + offset) * (wxCore.uo.screenHeight() / Laya.stage.height);
            // mainInst.mWX.initGameClub(referY);
            // this.soundBox.right = 160;
            if (mainInst.audioMgr == null)
                mainInst.audioMgr = new manager.AudioMgr();
            _this.reset();
            _this.getSound();
            // this.height = Laya.stage.height;
            // let point: Laya.Point = mainInst.mWX.getMenuButtonTop_CenterPoint();
            // this.coinBox.y = point.x + point.y / 2;
            // if (mainInst.mWX.getOnOffValueByKey1("of_guess_like1") == "1") {
            //     this.mMyLike.onUpdata();
            //     this.mMyLike.name = "startLike";
            // } else {
            _this.mMyLike.visible = false;
            return _this;
            // }
        }
        StartView.prototype.setUserInfo = function () {
            this.headimg.skin = mainInst.mWX.mUser["avatarUrl"];
            this.lblname.text = mainInst.mWX.mUser["nickName"];
            // mainInst.mWX.initMoreGame(this.btn_more, true);
        };
        StartView.prototype.onSoundClick = function () {
            if (mainInst.soundable) {
                mainInst.soundable = false;
                this.soundIcon.skin = 'pngs/sound_off.png';
                Laya.LocalStorage.setItem("sound", "0");
            }
            else {
                mainInst.soundable = true;
                this.soundIcon.skin = 'pngs/sound_on.png';
                Laya.LocalStorage.setItem("sound", "1");
            }
            // let firstEntryTime: string = Laya.LocalStorage.getItem("sound");
            // if (firstEntryTime == "") {
            //     firstEntryTime = mainInst.soundable;
            //     Laya.LocalStorage.setItem("sound", firstEntryTime);
            // }
        };
        StartView.prototype.getSound = function () {
            var sound = Laya.LocalStorage.getItem("sound");
            if (sound == "") {
                this.soundIcon.skin = 'pngs/sound_on.png';
                mainInst.soundable = true;
                return;
            }
            if (Number(sound) == 0) {
                this.soundIcon.skin = 'pngs/sound_off.png';
                mainInst.soundable = false;
            }
            else {
                this.soundIcon.skin = 'pngs/sound_on.png';
                mainInst.soundable = true;
            }
        };
        StartView.prototype.showTaskView = function () {
            var __this = this;
            // 功能未开放
            if (!mainInst.mWX.getOnOffByKey("of_task")) {
                // wx.showToast({
                //     title: "暂未开放此功能",
                //     icon: "none",
                //     image: "",
                //     duration: 2000
                // });
            }
            else {
                mainInst.mWX.getTaskRef(function (res) {
                    __this.controlBtn(false);
                    // view.TaskView.instance.builder(res["task_info"]).show();
                });
            }
        };
        StartView.prototype.showShopView = function () {
            var __this = this;
            // // 功能未开放
            // if (!mainInst.mWX.getOnOffByKey("of_shop")) {
            //     // wx.showToast({
            //     //     title: "暂未开放此功能",
            //     //     icon: "none",
            //     //     image: "",
            //     //     duration: 2000
            //     // });
            // } else {
            //     __this.controlBtn(false);
            //     view.ShopView.instance.builder().show();
            // }
            __this.controlBtn(false);
            view.ShopView.instance.builder().show();
        };
        StartView.prototype.showWelfareView = function () {
            var __this = this;
            // 功能未开放
            if (!mainInst.mWX.getOnOffByKey("of_well")) {
                // wx.showToast({
                //     title: "暂未开放此功能",
                //     icon: "none",
                //     image: "",
                //     duration: 2000
                // });
            }
            else {
                mainInst.mWX.getTaskRef(function (res) {
                    mainInst.mWX.getMyShare(function (res) {
                        __this.controlBtn(false);
                        view.WelfareView.instance.builder(res).show();
                    });
                });
            }
        };
        StartView.prototype.showDayGiftView = function () {
            var __this = this;
            // 功能未开放
            if (!mainInst.mWX.getOnOffByKey("of_gift")) {
                // wx.showToast({
                //     title: "暂未开放此功能",
                //     icon: "none",
                //     image: "",
                //     duration: 2000
                // });
            }
            else {
                mainInst.mWX.getTaskRef(function (res) {
                    __this.controlBtn(false);
                    // view.DayGiftView.instance.builder().show();
                });
            }
        };
        StartView.prototype.startGame = function () {
            mainInst.mWX.hideBannerAd();
            this.unshiftEvt();
            var obg = {
            // is_new: ConfigUtil.mIsNewUser
            };
            //点击开始游戏
            mainInst.mWX.indexBpTotle("start_button_click", obg);
            if (mainInst.gameView == null)
                mainInst.gameView = new view.GameView();
            else
                mainInst.gameView.reset();
            // mainInst.mWX.jumpToShenShouPlatform
        };
        StartView.prototype.queryWorldRank = function () {
            this.unshiftEvt();
            this.soundBox.visible = false;
            if (mainInst.mWX.gameClub != null)
                mainInst.mWX.gameClub.hide();
            mainInst.ShowWorldRank();
        };
        StartView.prototype.queryFriendRank = function () {
            this.unshiftEvt();
            this.soundBox.visible = false;
            if (mainInst.mWX.gameClub != null)
                mainInst.mWX.gameClub.hide();
            mainInst.ShowFriendRank();
        };
        StartView.prototype.showHonor = function () {
            this.unshiftEvt();
            this.soundBox.visible = false;
            if (mainInst.mWX.gameClub != null)
                mainInst.mWX.gameClub.hide();
            mainInst.ShowGlory();
        };
        StartView.prototype.shareGroup = function () {
            sharehelper.shareToGroup();
        };
        StartView.prototype.shenshouGame = function () {
            mainInst.moreGame = "startDrawer";
            mainInst.mWX.hideBannerAd();
            gameBox.showBoxPage("", mainInst.mWX.mGamesBox, "神抛高");
        };
        StartView.prototype.displayRedPoint = function () {
            // // 任务开关关闭
            // if (!mainInst.mWX.getOnOffByKey("of_task")) {
            //     this.taskRedPoint.visible = false;
            // } else {
            //     this.displayTaskRedPoint();
            // }
            // // 福利开关关闭
            // if (!mainInst.mWX.getOnOffByKey("of_well")) {
            //     this.welfareRedPoint.visible = false;
            // } else {
            //     this.displayWelfareRedPoint();
            // }
            // // 每日礼包开关关闭
            // if (!mainInst.mWX.getOnOffByKey("of_gift")) {
            //     this.dayGiftRedPoint.visible = false;
            // } else {
            //     this.displayDayGiftRedPoint();
            // }
        };
        /**
         * 如果未签到,则显示任务红点
         * 如果已签到,根据是否存在任务完成但未领取奖励的情况判读
         */
        StartView.prototype.isCheckinFinish = function () {
            for (var i = 0; i < mainInst.mWX.mTaskInfo.length; i++) {
                if (mainInst.mWX.mTaskInfo[i]["type"] != "1")
                    continue;
                if (mainInst.mWX.mTaskInfo[i]["reward"] == "")
                    continue;
                var reward = JSON.parse(mainInst.mWX.mTaskInfo[i]["reward"]);
                if (typeof reward["goto"] == "string" && reward["goto"] == "sign") {
                    var give = Number(mainInst.mWX.mTaskInfo[i]["give"]);
                    if (give == 0)
                        return true;
                    break;
                }
            }
            return false;
        };
        /**
         * 如果开关未开启,则隐藏红点
         * 任务显示规则:如果没有签到,则显示红点;如果已完成签到,则当任务完成但奖励未领取时,显示红点
         */
        StartView.prototype.displayTaskRedPoint = function () {
            // if (this.isCheckinFinish()) {
            //     this.taskRedPoint.visible = true;
            //     return;
            // }
            // this.taskRedPoint.visible = false;
            // for (var i = 0; i < mainInst.mWX.mTaskInfo.length; i++) {
            //     if (mainInst.mWX.mTaskInfo[i]["type"] != "1")
            //         continue;
            //     // 任务完成但未领取时,显示红点
            //     if (mainInst.mWX.mTaskInfo[i]["give"] == 0 &&
            //         Number(mainInst.mWX.mTaskInfo[i]["over_count"]) >= Number(mainInst.mWX.mTaskInfo[i]["count"])) {
            //         this.taskRedPoint.visible = true;
            //         break;
            //     }
            // }
        };
        /**
         * 显示福利红点
         */
        StartView.prototype.displayWelfareRedPoint = function () {
            // this.welfareRedPoint.visible = false;
            // for (var i = 0; i < mainInst.mWX.mTaskInfo.length; i++) {
            //     if (mainInst.mWX.mTaskInfo[i]["type"] != "2")
            //         continue;
            //     if (Number(mainInst.mWX.mTaskInfo[i]["give"]) == 0 &&
            //         Number(mainInst.mWX.mTaskInfo[i]["over_count"]) >= Number(mainInst.mWX.mTaskInfo[i]["count"])) {
            //         this.welfareRedPoint.visible = true;
            //         break;
            //     }
            // }
        };
        /**
         * 显示每日礼包红点
         */
        StartView.prototype.displayDayGiftRedPoint = function () {
            // this.dayGiftRedPoint.visible = false;
            // // 没有广告的用户不显示红点
            // if (!wxCore.uo.haveVideo() || mainInst.mWX.mSDKVersion < "2.0.4")
            //     return;
            // for (var i = 0; i < mainInst.mWX.mTaskInfo.length; i++) {
            //     if (mainInst.mWX.mTaskInfo[i]["type"] != "3")
            //         continue;
            //     if (Number(mainInst.mWX.mTaskInfo[i]["give"]) == 0) {
            //         this.dayGiftRedPoint.visible = true;
            //         break;
            //     }
            // }
        };
        StartView.prototype.unshiftEvt = function () {
            Laya.timer.clearAll(this);
            this.controlBtn(false);
            // if (mainInst.mWX.gameClub != null) mainInst.mWX.gameClub.hide();
            this.indexBox.visible = false;
            this.coinBox.visible = false;
        };
        StartView.prototype.reset = function () {
            var _this = this;
            Laya.timer.clearAll(this);
            Laya.timer.clear(this, this.giftAnimate);
            Laya.timer.frameLoop(3, this, this.giftAnimate);
            this.btn_more.rotation = 0;
            Laya.Tween.clearAll(this.btn_more);
            Laya.timer.clearAll(this.btn_more);
            this.rotaOtherGame();
            this.soundBox.visible = true;
            // if (mainInst.mWX.gameClub != null) mainInst.mWX.gameClub.show();
            console.log("123", this.visible);
            // let like_res = mainInst.mWX.getOnOffParamByKey("of_switch_game")
            // let lib_obj = JSON.parse(like_res);
            // Laya.timer.loop(Number(lib_obj.time), this, (() => {
            //     mainInst.mWX.initMoreGame(this.btn_more, true);
            // }))
            // mainInst.mWX.showBannerAd(mainInst.mWX.getwxadurlByid(1));
            // mainInst.mWX.adBanner.show();
            this.controlBtn(true);
            if (this.stage.contains(this)) {
                this.indexBox.visible = true;
                this.coinBox.visible = true;
            }
            else {
                // this.stage.addChild(this);
                // this.visible=true;
                Laya.stage.addChild(this);
                this.visible = true;
                this.indexBox.visible = true;
                this.coinBox.visible = true;
            }
            if (mainInst.kuanP) {
                this.indexBox.scale(mainInst.kuanPScale, mainInst.kuanPScale);
                this.indexBox.x = (this.indexBox.width - this.indexBox.width * mainInst.kuanPScale) / 2;
                this.startBtn.y = 715;
            }
            //显示原生
            Laya.timer.once(1800, this, function () {
                if(window.HideLoading){
                    window.loading = false;
                    console.log("初次登陆");
                    window['uptap'].HideLoading();
                    window.HideLoading = false;
                    window['uptap'].LoadingComplete();
                }
            });
            mainInst.adUtil.hideBannerAd();
        };
        /**
         * 控制首页view的显示、隐藏
         * @param isVisiable
         */
        StartView.prototype.controlViews = function (isVisiable) {
            // this._childs.forEach((item, index) => {
            //     if (item instanceof Laya.Component) {
            //         if (item.name != "bg1" && item.name != "hide")
            //             item.visible = isVisiable;
            //     }
            // });
        };
        StartView.prototype.controlBtn = function (isDisable) {
            if (isDisable && mainInst.loadPng) {
                this.soundBox.on(Event.CLICK, this, this.onSoundClick);
                // this.taskBox.on(Event.CLICK, this, this.showTaskView);
                this.shopBox.on(Event.CLICK, this, this.showShopView);
                // this.welfareBox.on(Event.CLICK, this, this.showWelfareView);
                // this.dayGiftBox.on(Event.CLICK, this, this.showDayGiftView);
                this.startBtn.on(Event.CLICK, this, this.startGame);
                // this.worldRank.on(Event.CLICK, this, this.queryWorldRank);
                this.friendRank.on(Event.CLICK, this, this.queryFriendRank);
                // this.honorBtn.on(Event.CLICK, this, this.showHonor);
                // this.groupRank.on(Event.CLICK, this, this.shareGroup);
                this.btn_more.on(Ev.CLICK, this, mainInst.mWX.showMoreGamePage, [this.btn_more, "startRecommend"]);
                // this.gift_item.on(Ev.CLICK, mainInst, mainInst.ShowRebirthCard, [1]);
                this.shenshouGameBtn.on(Event.CLICK, this, this.shenshouGame);
            }
            else {
                this.soundBox.off(Event.CLICK, this, this.onSoundClick);
                // this.taskBox.off(Event.CLICK, this, this.showTaskView);
                this.shopBox.off(Event.CLICK, this, this.showShopView);
                // this.welfareBox.off(Event.CLICK, this, this.showWelfareView);
                // this.dayGiftBox.off(Event.CLICK, this, this.showDayGiftView);
                this.startBtn.off(Event.CLICK, this, this.startGame);
                // this.worldRank.off(Event.CLICK, this, this.queryWorldRank);
                this.friendRank.off(Event.CLICK, this, this.queryFriendRank);
                // this.honorBtn.off(Event.CLICK, this, this.showHonor);
                // this.groupRank.off(Event.CLICK, this, this.shareGroup);
                this.btn_more.off(Ev.CLICK, this, mainInst.mWX.showMoreGamePage);
                // this.gift_item.off(Ev.CLICK, mainInst, mainInst.ShowRebirthCard);
                this.shenshouGameBtn.off(Event.CLICK, this, this.shenshouGame);
            }
        };
        // 广告动画
        StartView.prototype.rotaOtherGame = function () {
            var __this = this;
            function Tw1() {
                Laya.Tween.to(__this.btn_more, { rotation: 0 }, 200, null, new Laya.Handler(__this, Tw2));
            }
            function Tw2() {
                Laya.Tween.to(__this.btn_more, { rotation: 30 }, 200, null, new Laya.Handler(__this, Tw3), 2000);
            }
            function Tw3() {
                Laya.Tween.to(__this.btn_more, { rotation: 0 }, 200, null, new Laya.Handler(__this, Tw4));
            }
            function Tw4() {
                Laya.Tween.to(__this.btn_more, { rotation: 30 }, 200, null, new Laya.Handler(__this, Tw1));
            }
            Laya.Tween.to(__this.btn_more, { rotation: 30 }, 200, null, new Laya.Handler(__this, Tw1));
        };
        // 互助礼按钮动画
        StartView.prototype.giftAnimate = function () {
            // this.gift_item.rotation += 2;
        };
        StartView.prototype.showNativeAD = function (isDelay) {
            var _this = this;
            if (isDelay === void 0) { isDelay = false; }
            var timer = mainInst.mWX.getOnOffParamByKey('of_oppo_cp_time');
            var delayTime = Number(JSON.parse(timer)['limit']);
            console.log("时间", timer);
            //isDelay ? 1000 : 0
            var __this = this;
            Laya.timer.once(delayTime, __this, function () {
                if (_this == null) {
                    return;
                }
                if (__this.ysView == null) {
                    __this.ysView = new YuanShengView1();
                    _this.indexBox.addChild(__this.ysView);
                    __this.ysView.y = 642;
                }
                __this.ysView.showSelf(function (isShowNativeAdSuccess) {
                    if (isShowNativeAdSuccess) {
                        console.log(">>GameOverControl 原生广告显示成功");
                    }
                    else {
                        console.log(">>GameOverControl 原生广告显示失败");
                    }
                });
            });
        };
        StartView.is_first = true;
        StartView.is_play = false;
        return StartView;
    }(ui.StartPageUI));
    view.StartView = StartView;
})(view || (view = {}));
//# sourceMappingURL=StartView.js.map