games/ChaoJiJieYaGuan_MaJiang2/assets/Script/GameSc/GameSceneSc.ts

124 lines
3.9 KiB
TypeScript

/**
* 游戏场景
*/
import AudioManager from "../Tools/AudioManager";
import { GameType } from "../Tools/Define";
import GameResMgr, { soundName, uiPreName } from "../Tools/GameResMgr";
import PlayData from "../Tools/PlayData";
import AdsApiMgr from "../Tools/Sdk/ads/AdsApiMgr";
import ChallengeGameSc from "./LevelUpGame/ChallengeGameSc";
import setPanelSc from "./LevelUpGame/setPanelSc";
const {ccclass, property} = cc._decorator;
@ccclass
export default class GameSceneSc extends cc.Component {
@property(cc.Node)
gamenode:cc.Node = null
@property(cc.Node)
uinode:cc.Node = null
@property(cc.Sprite)
bg:cc.Sprite = null
@property(cc.Node)
addicon:cc.Node = null
// @property([cc.SpriteFrame])
// bgsp:cc.SpriteFrame[] = []
onLoad () {
var self = this
cc.game.on('addnewgame', ()=>{
let newnode = null
if(PlayData.Instance.gameType == GameType.challenge){
newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.challengeGameNode])
}else if(PlayData.Instance.gameType == GameType.normal){
newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.gameNode])
}
newnode.opacity = 0
newnode.x = 1000
newnode.parent = self.gamenode
cc.tween(newnode)
.to(0.5, {x:0,opacity:255})
.start()
})
//self.bg.spriteFrame = self.bgsp[PlayData.Instance.gameType]
cc.game.emit('addnewgame')
let newtili = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.top_tili])
let wiget = newtili.getComponent(cc.Widget)
wiget.left = -400
newtili.parent = this.uinode
if(cc.sys.platform == cc.sys.BYTEDANCE_GAME){//字节跳动平台
//@ts-ignore
const sysinfo = tt.getSystemInfoSync()
let appname = sysinfo.appName
if (appname == 'Douyin' || appname == 'douyin_lite') {
this.addicon.active = !0
}else{
this.addicon.active = !1
}
}else{
this.addicon.active = !1
}
}
start () {
AudioManager.playMusic(soundName.bgSound1)
cc.find('topnode0', this.uinode).active = PlayData.Instance.gameType == GameType.normal
cc.find('topnode1', this.uinode).active = PlayData.Instance.gameType == GameType.challenge
}
/**
* 按钮点击事件
* @param t
* @param e
*/
btnClickCallBack(t, e){
if(e == 'home'){
AdsApiMgr.Instance.recording_Video_End()
if(PlayData.Instance.gameType == GameType.challenge){
let gamesc:ChallengeGameSc = cc.find('challengeGameNode', this.gamenode).getComponent(ChallengeGameSc)
gamesc.storageCheckOutData()
}
cc.director.loadScene('StartScene')
}else if(e == 'set'){
let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.setPanel])
newnode.parent = this.uinode
let sc = newnode.getComponent(setPanelSc)
sc.showType(1)
}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('触发添加桌面')
//@ts-ignore
tt.addShortcut({
success() {
console.log("添加桌面成功");
},
fail(err) {
console.log("添加桌面失败", err.errMsg);
},
});
}
}
}
}
update (dt) {
}
}