
//电子邮件puhalskijsemen@gmail.com
//源码网站 开vpn全局模式打开 http://web3incubators.com/
//电报https://t.me/gamecode999
//网页客服 http://web3incubators.com/kefu.html
/**
 * @author heyuchang
 * @file 主控制器
 */


import ATSDK from "./AnyThinkAds/ATJSSDK";
import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoJSSDK";
import AAJS2 from "./ATAndroidJS2";
import AESUtil from "./AESUtil"

cc.Class({
  extends: cc.Component,
  properties: {
    musicManager: require('musicManager'), //音乐控制组件
    game: require('game'), //主游戏控制器
    pageManager: require('pageManager'), //页面控制器
    social: require('social'), //排行榜、广告控制器
    config: cc.JsonAsset,
    gameData: cc.JsonAsset,
    scoreMgr: require('score'), //分数 特效控制
    totalRank: cc.Node,
    groupRank: cc.Node,
    startPage: require('startPage'),
    navNode: cc.Node,
    illustrative: cc.Node,
    helpPage: cc.Node,
  },

  start() {
    console.log('zh:controller 00000000000000')

    this.totalRank.active = false
    this.illustrative.active = false
    this.game.init(this)
    if (this.social.node.active) {
      this.social.init(this)
    }
    this.musicManager.init()
    this.lateStart()
    this.initAdForPage()

  },

  initAdForPage() {
    console.log('zh:controller.js initAdForPage start')
    let deviceId = AAJS2.getDeviceUserId();
    console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementID()));
    var setting = {};
    setting[ATRewardedVideoSDK.userIdKey] = deviceId;
    ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementID(), setting);
  },

  lateStart() {
    if (this.social.node.active) {
      this.social.closeBannerAdv()
    }
    this.illustrative.getComponent('illustrative').init(this)
    this.startPage.bannerNode.scale = 1
    this.pageManager.onOpenPage(0)
  },
  onGameStartButton() {
    // TODO:  增加一个动画
    if (this.social.node.active) {
      this.social.openBannerAdv()
    }
    this.startPage.showAnimation().then(() => {
      this.gameStart()
    })
  },
  gameStart() {
    this.pageManager.onOpenPage(1)
    this.game.gameStart()
  },
  closeRank() {
    this.totalRank.active = false
    this.navNode.active = true
    if (this.social.node.active) {
      this.social.closeRank()
    }
  },
  openRank() {
    this.totalRank.active = true
    this.navNode.active = false
    if (this.social.node.active) {
      this.social.showRank()
    }
  },
  openGroupRank() {
    this.groupRank.active = true
    if (this.social.node.active) {
      this.social.showGroupRank()
      this.pageManager.addPage(6)
    }
  },
  closeGroupRank() {
    this.groupRank.active = false
    this.navNode.active = true
    if (this.social.node.active) {
      this.social.closeGroupRank()
      this.pageManager.removePage(6)
    }
  },
  openPictorial() {

    //ZH测试显示AD
    if (2 > 3) {
      setTimeout(() => {
        if (cc.sys.os === cc.sys.OS_ANDROID) {
          if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementID())) {
            console.log('zh:AD  ready for controller.js')
            ATRewardedVideoSDK.showAd(AAJS2.getPlacementID());
          } else {
            console.log('zh:AD not ready  for controller.js')
          }
        }
      }, 300)
    }




    this.illustrative.active = true
  },
  closePictorial() {
    this.illustrative.active = false
  },
  openHelpPage() {
    this.helpPage.active = true
  },
  closeHelpPage() {
    this.helpPage.active = false
  }
});