消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

236 lines
7.9 KiB

import { _decorator, assetManager, Component, instantiate, Label, Node, PageView, Prefab, sys } from 'cc';
import { UIBase } from '../../mx/module/ui/UIBase';
import { UIID } from '../game/ConfigRes';
import { GEvent } from '../../mx/module/event/GEvent';
const { ccclass, property } = _decorator;
@ccclass('atGameChoose')
export class atGameChoose extends UIBase {
@property(PageView)
pageViewCom: PageView = null
@property(Node)
pageContent: Node = null
@property(Node)
pageNode: Node = null
@property(Node)
levelList: Node = null
curentSelectGameId: number = 0;
curentLevel: number = 0;
wzconfig = [
{ id: 0, name: '战火防线', lockChapter: 0, lockStr: '通关第5章解锁', openId: UIID.Gaoyaguo, maxLevel: 5 },
{ id: 1, name: '绝境瞄准', lockChapter: 0, lockStr: '通关第10章解锁', openId: UIID.tantantan1, maxLevel: 5 },
{ id: 2, name: '逃离危楼', lockChapter: 0, lockStr: '通关第15章解锁', openId: -1, maxLevel: 5 },
]
onLoad() {
super.onLoad();
}
protected onEnable(): void {
this.levelList.getChildByName("bg").on(Node.EventType.TOUCH_END, this.closeLevelList, this);
GEvent.Ins.on(GEvent.RestartAtTrafficGame, this.onGameRestart, this);
GEvent.Ins.on(GEvent.ExitAtTrafficGame, this.closeGame, this);
GEvent.Ins.on(GEvent.nextAtTrafficGame, this.onGameNext, this);
}
protected onDisable(): void {
this.levelList.getChildByName("bg").off(Node.EventType.TOUCH_END, this.closeLevelList, this);
GEvent.Ins.off(GEvent.RestartAtTrafficGame, this.onGameRestart, this);
GEvent.Ins.off(GEvent.ExitAtTrafficGame, this.closeGame, this);
GEvent.Ins.off(GEvent.nextAtTrafficGame, this.onGameNext, this);
}
start() {
}
onInit(): void {
this.showOpenMaskEff(1)
//wzconfig 初始化界面
// pageContent 上子节点每个节点需要6条配置信息
let index = 0
for (let i = 0; i < this.pageContent.children.length; i++) {
let node = this.pageContent.children[i]
for (let j = 0; j < node.children.length; j++) {
let itemNode = node.children[j]
let config = this.wzconfig[index]
if (config) {
itemNode.attr({ openId: config.openId, lockChapter: config.lockChapter, configId: config.id })
this.refreshItem(itemNode, config)
}
index++
}
}
this.levelList.active = false;
}
refreshItem(itemNode: Node, config: any) {
let mask = itemNode.getChildByName('mask')
let lockDec = mask.getChildByName('lockDec')
lockDec.getComponent(Label).string = '通关第' + config.lockChapter + '章解锁'//config.lockStr
let name = itemNode.getChildByName('name').getComponent(Label)
name.string = config.name
if (gg.data.doc.chapter > config.lockChapter) {
mask.active = false
} else {
mask.active = true
}
}
leftBtnClick() {
}
rightBtnClick() {
}
clickItemClick(event) {
let itemNode: Node = event.target
if (itemNode.getChildByName('mask').active) {
gg.ui.showToast('通关第' + itemNode['lockChapter'] + '章解锁')
return
}
this.curentSelectGameId = itemNode['configId'];
this.shoeSelectLevel();
}
closeView() {
this.close(1)
}
closeGame() {
if (this._currentInstance) {
this._currentInstance.destroy();
}
}
shoeSelectLevel() {
this.levelList.active = true;
let list = this.levelList.getChildByName("list");
let config = this.wzconfig[this.curentSelectGameId]
let maxLevel = config.maxLevel;
let curentLevel = sys.localStorage.getItem('minigame_tantantan_level' + config.id);
if (!curentLevel) {
curentLevel = 1;
}
for (let i = 0; i < maxLevel; i++) {
let l = i + 1;
let n: Node = null;
if (i < list.children.length) {
n = list.children[i];
} else {
n = instantiate(list.children[0]);
n.parent = list;
}
n.active = true;
let finish = n.getChildByName('finish');
let curent = n.getChildByName('curent');
let lbLevel = n.getChildByName('lbLevel').getComponent(Label);
let lock = n.getChildByName('lock');
lbLevel.string = l + "";
finish.active = i < curentLevel - 1;
lock.active = i >= curentLevel;
curent.active = i == curentLevel - 1;
//移除n的点击事件
n.off(Node.EventType.TOUCH_END);
n.on(Node.EventType.TOUCH_END, this.clickLevel.bind(this, l, n), this);
}
}
closeLevelList() {
if (this._opening) return;
this.levelList.active = false;
}
private _opening = false;
clickLevel(level: number, node: Node = null) {
if (this._opening) return;
if (node && node.getChildByName('lock').active) {
gg.ui.showToast('暂未解锁')
return;
}
let bundleName = '';
let prefabName = '';
if (this.curentSelectGameId == 0) {
bundleName = "gaoyaguo";
prefabName = 'Gaoyaguo' + level;
} else if (this.curentSelectGameId == 1) {
bundleName = "tantantan";
prefabName = 'tantantan' + level;
} else if (this.curentSelectGameId == 2) {
bundleName = "soudace";
prefabName = 'level' + level;
}
this._opening = true;
this.curentLevel = level;
let config = this.wzconfig[this.curentSelectGameId]
gg.sdk.reportDY("inLevel", `进入小游戏-小游戏[${config.name}]第${level}`);
assetManager.loadBundle(bundleName, (err, bundle) => {
if (err) {
console.log(err);
this._opening = false;
return;
}
bundle.load("prefab/" + prefabName, (err, prefab) => {
if (err) {
console.log(err);
this._opening = false;
return;
}
if (this._currentInstance) {
this._currentInstance.destroy();
}
let instance = instantiate(prefab as Prefab);
this._currentInstance = instance;
instance.parent = this.node;
this._opening = false;
this.levelList.active = false;
instance.on("_onMiniGameEnd", this.onGameOver, this);
instance.on("_onMiniGameRestart", this.onGameRestart, this);
instance.on("_onMiniGameNext", this.onGameNext, this);
instance.on("_onMiniGameClose", this.closeGame, this);
});
});
}
private _currentInstance: Node = null;
onGameOver(result: boolean) {
if (result) {
let curentLevel = sys.localStorage.getItem('minigame_tantantan_level' + this.curentSelectGameId);
if (!curentLevel) curentLevel = "1";
let nextLevel = Number(curentLevel) + 1;
if (curentLevel == this.curentLevel) {
sys.localStorage.setItem('minigame_tantantan_level' + this.curentSelectGameId, nextLevel);
}
gg.ui.openPanel(UIID.successAtGameResult, { data: 'nextGame' });
} else {
gg.ui.openPanel(UIID.failAtGameResult);
}
}
onGameRestart() {
this.clickLevel(this.curentLevel);
}
onGameNext() {
let level = this.curentLevel + 1;
let config = this.wzconfig[this.curentSelectGameId]
if (level > config.maxLevel) {
level = 1;
}
this.clickLevel(level);
}
}