221 lines
8.0 KiB
TypeScript
221 lines
8.0 KiB
TypeScript
/**
|
||
* 开始界面
|
||
*/
|
||
|
||
import AudioManager from "../Tools/AudioManager";
|
||
import Define, { GameType } from "../Tools/Define";
|
||
import GameResMgr, { soundName, uiPreName } from "../Tools/GameResMgr";
|
||
import PlayData from "../Tools/PlayData";
|
||
import AdsApiMgr from "../Tools/Sdk/ads/AdsApiMgr";
|
||
import Utils from "../Tools/Utils";
|
||
import gameStorage from "../Tools/gameStorage";
|
||
import ChallengeGameSc from "./LevelUpGame/ChallengeGameSc";
|
||
import TopTiLiSc from "./LevelUpGame/TopTiLiSc";
|
||
import setPanelSc from "./LevelUpGame/setPanelSc";
|
||
|
||
|
||
const {ccclass, property} = cc._decorator;
|
||
|
||
@ccclass
|
||
export default class StartSceneSc extends cc.Component {
|
||
|
||
@property(cc.Node)
|
||
uinode:cc.Node = null
|
||
|
||
@property(cc.Node)
|
||
cebianbtn:cc.Node = null
|
||
|
||
@property(cc.Node)
|
||
addicon:cc.Node = null
|
||
|
||
onLoad () {
|
||
AudioManager.playMusic(soundName.bgSound0)
|
||
|
||
if(PlayData.Instance.enterStartSceneIndex == 0){
|
||
cc.game.on('opencebian', ()=>{
|
||
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.cebianPanel])
|
||
newnode.parent = this.node
|
||
})
|
||
|
||
cc.director.on('updateengry', ()=>{
|
||
if(cc.find('Canvas/uiNode/top_tili')){
|
||
let sc = cc.find('Canvas/uiNode/top_tili').getComponent(TopTiLiSc)
|
||
sc.setTiLi()
|
||
gameStorage.Instance.setoffLineTime()
|
||
}
|
||
})
|
||
|
||
if(gameStorage.Instance.getoffLineTime() > 0){
|
||
let nowtime = Number(new Date().getTime())
|
||
let offtime = gameStorage.Instance.getoffLineTime()
|
||
let _chatime = Math.floor((nowtime - offtime)/1000)
|
||
let addtili = Math.floor(_chatime/Define.eneryTime)
|
||
if(gameStorage.Instance.getEnergy() < Define.maxEnery){
|
||
if((addtili+gameStorage.Instance.getEnergy()) >= Define.maxEnery){
|
||
gameStorage.Instance.setEnergy(Define.maxEnery)
|
||
cc.director.emit('updateengry')
|
||
}else{
|
||
if(addtili+gameStorage.Instance.getEnergy() < 1){
|
||
gameStorage.Instance.setEnergy(1)
|
||
}else{
|
||
gameStorage.Instance.setEnergy(addtili+gameStorage.Instance.getEnergy())
|
||
}
|
||
cc.director.emit('updateengry')
|
||
}
|
||
}
|
||
}
|
||
|
||
if(cc.sys.platform == cc.sys.BYTEDANCE_GAME){
|
||
//@ts-ignore
|
||
tt.onHide(()=>{
|
||
let node = cc.find('Canvas/gameNode/challengeGameNode')
|
||
if(node){
|
||
let sc = node.getComponent(ChallengeGameSc)
|
||
if(sc){
|
||
sc.storageCheckOutData()
|
||
}
|
||
}
|
||
})
|
||
}else if(cc.sys.platform == cc.sys.WECHAT_GAME){
|
||
//@ts-ignore
|
||
wx.onHide(()=>{
|
||
let node = cc.find('Canvas/gameNode/challengeGameNode')
|
||
if(node){
|
||
let sc = node.getComponent(ChallengeGameSc)
|
||
if(sc){
|
||
sc.storageCheckOutData()
|
||
}
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
// 字符串加密
|
||
//var str = "3.1415926";
|
||
//var encodedStr = btoa(str); //
|
||
//console.log("Encoded String:", encodedStr);
|
||
// 字符串解密
|
||
//var decodedStr = atob(encodedStr); // 输出:Hello World!
|
||
//console.log("Decoded String:", decodedStr);
|
||
}
|
||
|
||
start () {
|
||
PlayData.Instance.enterStartSceneIndex ++
|
||
//this.goldstr.string = ''
|
||
this.initUi()
|
||
}
|
||
|
||
/**
|
||
* 初始化ui
|
||
*/
|
||
initUi(){
|
||
let newtili = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.top_tili])
|
||
newtili.parent = this.uinode
|
||
|
||
if(cc.sys.platform == cc.sys.BYTEDANCE_GAME){
|
||
this.addicon.active = !1
|
||
//@ts-ignore
|
||
const sysinfo = tt.getSystemInfoSync()
|
||
const sdkversion = sysinfo.SDKVersion
|
||
let appname = sysinfo.appName
|
||
let appVersion = sysinfo.version
|
||
var self= this
|
||
//console.log('系统信息', sysinfo)
|
||
//console.log('打印判断sdk', Utils.compareVersion(sdkversion, '2.92.0.0'))
|
||
if (Utils.compareVersion(sdkversion, '2.92.0.0') >= 0 && (appname == 'Douyin' || appname == 'douyin_lite' || appname == 'devtools')){
|
||
this.cebianbtn.active = !0
|
||
}else{
|
||
this.cebianbtn.active = !1
|
||
}
|
||
|
||
if (Utils.compareVersion(sdkversion, '2.70.0') >= 0
|
||
&& (appname == 'Douyin' || appname == 'douyin_lite')
|
||
&& Utils.compareVersion(appVersion, '23.2.0') >= 0) {
|
||
cc.find('uiNode/paihang', this.node).active = !0
|
||
}else{
|
||
cc.find('uiNode/paihang', this.node).active = !1
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 开始按钮点击
|
||
*/
|
||
startBtnClick(){
|
||
if(gameStorage.Instance.getEnergy()>0){
|
||
gameStorage.Instance.setoffLineTime()
|
||
gameStorage.Instance.setEnergy(gameStorage.Instance.getEnergy()-1)
|
||
PlayData.Instance.gameType = GameType.normal
|
||
cc.director.loadScene('LevelUpGameScene')
|
||
}else{ //体力不足
|
||
gameStorage.Instance.setoffLineTime()
|
||
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.addEnery])
|
||
newnode.parent = cc.director.getScene()
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 挑战模式
|
||
*/
|
||
challengeBtnClick(){
|
||
gameStorage.Instance.setoffLineTime()
|
||
|
||
//let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.challengeCheckOutPanel])
|
||
//newnode.parent = this.node
|
||
|
||
// PlayData.Instance.gameType = GameType.challenge
|
||
// cc.director.loadScene('LevelUpGameScene')
|
||
|
||
|
||
if(gameStorage.Instance.getEnergy()>0){
|
||
gameStorage.Instance.setEnergy(gameStorage.Instance.getEnergy()-1)
|
||
//console.log('打印关卡id', guan)
|
||
//PlayData.Instance.guanqia = 0 //guan
|
||
PlayData.Instance.gameType = GameType.challenge
|
||
cc.director.loadScene('LevelUpGameScene')
|
||
}else{ //体力不足
|
||
gameStorage.Instance.setoffLineTime()
|
||
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.addEnery])
|
||
newnode.parent = cc.director.getScene()
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 按钮点击事件
|
||
* @param t
|
||
* @param e
|
||
*/
|
||
uiBtnClickCallBack(t, e){
|
||
if(e == 'set'){
|
||
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.setPanel])
|
||
newnode.parent = this.uinode
|
||
let sc = newnode.getComponent(setPanelSc)
|
||
sc.showType(0)
|
||
}else if(e == 'rank'){
|
||
AdsApiMgr.Instance.getImRankList_Num()
|
||
}else if(e == 'share'){
|
||
AdsApiMgr.Instance.shareGameToFriend(()=>{})
|
||
}else if(e == 'cebian'){
|
||
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.cebianPanel])
|
||
newnode.parent = this.node
|
||
}else if(e == 'addicon'){
|
||
if(cc.sys.platform == cc.sys.BYTEDANCE_GAME){
|
||
//@ts-ignore
|
||
const sysinfo = tt.getSystemInfoSync()
|
||
let appname = sysinfo.appName
|
||
if (appname == 'Douyin' || appname == 'douyin_lite') {
|
||
console.log('触发添加桌面')
|
||
AdsApiMgr.Instance.addShortcut(()=>{}, ()=>{})
|
||
}else{
|
||
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.addiconTips])
|
||
newnode.parent = cc.director.getScene()
|
||
}
|
||
}else{
|
||
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.addiconTips])
|
||
newnode.parent = cc.director.getScene()
|
||
}
|
||
}
|
||
}
|
||
// update (dt) {}
|
||
}
|