消消方块阵换皮表情
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.
 
 
 

592 lines
23 KiB

import { _decorator, Asset, AssetManager, Component, find, instantiate, Label, Node, Prefab, sp, Sprite } from 'cc';
import { BattleType, ChapterDataManager, ChapterDifficulty } from '../../manager/ChapterDataManager';
import { OtherDataType } from '../../game/GameData';
import { GEvent } from 'db://assets/mx/module/event/GEvent';
import { GBundle, UIID } from '../../game/ConfigRes';
import MTools from 'db://assets/mx/tools/MTools';
import { ItemData } from '../../game/ConfigProjectData';
import { ConstEnum, ConstManager } from '../../manager/ConstManager';
import { assetManager } from 'cc';
import { v3 } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('ui_tiaozhuanItem')
export class ui_tiaozhuanItem extends Component {
spCell1: Node;
spCell2: Node;
ui_chapterNode: Node;
sp_progress:Sprite;
ui_xianguan: Node;
ui_xianguan6: Node;
putongkuangBtn: Node;
kunnankuangBtn: Node;
diyukuangBtn: Node;
zhangLab: Label
zhangName: Label
chapterId: number = 0
allList: ITableChapter[] = []
isGetArrayPT: boolean[] = []
isGetArrayKN: boolean[] = []
isGetArrayDY: boolean[] = []
start() {
if (!this.zhangLab) {
this.allList = ChapterDataManager.getAllChapterList()
this.zhangLab = find("zhangLab", this.node).getComponent(Label);
this.zhangName = find("zhangName", this.node).getComponent(Label);
this.sp_progress = find("putongkuangBtn/sp_progress", this.node).getComponent(Sprite);
this.ui_xianguan = find("ui_xianguan", this.node);
this.spCell1 = find("spCell1", this.node);
this.spCell2 = find("spCell2", this.node);
this.ui_chapterNode = find("ui_chapter", this.node);
this.ui_xianguan6 = find("ui_xianguan6", this.node);
this.putongkuangBtn = find("putongkuangBtn", this.node);
this.kunnankuangBtn = find("kunnankuangBtn", this.node);
this.diyukuangBtn = find("diyukuangBtn", this.node);
}
}
setData(index: number) {
console.log('setData==index=',index);
if (!this.zhangLab) {
this.allList = ChapterDataManager.getAllChapterList()
this.zhangLab = find("zhangLab", this.node).getComponent(Label);
this.sp_progress = find("putongkuangBtn/sp_progress", this.node).getComponent(Sprite);
this.ui_xianguan = find("ui_xianguan", this.node);
this.spCell1 = find("spCell1", this.node);
this.spCell2 = find("spCell2", this.node);
this.ui_chapterNode = find("ui_chapter", this.node);
this.ui_xianguan6 = find("ui_xianguan6", this.node);
this.putongkuangBtn = find("putongkuangBtn", this.node);
this.kunnankuangBtn = find("kunnankuangBtn", this.node);
this.diyukuangBtn = find("diyukuangBtn", this.node);
this.zhangName = find("zhangName", this.node).getComponent(Label);
}
let config = this.allList[index]
let config2 = null;
if (index < gg.sdk.levelS.length) {
config2 = ChapterDataManager.getChapterDataById(gg.sdk.levelS[index]);
}
//数字1,2,3,4,转汉字一,二,三,四
this.chapterId = index
//let zhangNum = this.numberToChinese(index+1)
this.zhangLab.string = gg.lang.get('第{1}章 {2}', [index + 1, config.name])//'第' + (index + 1) + '章'
// this.zhangName.string = config.name
// if (config2) {
// this.zhangName.string = config2.name;
// }
//let spineName = ['1教室待机', '1教室选中', '1教室选中待机']
//根据章节类型设置spine动画
// this.node.getChildByName('首页选关1_5').active = false
// this.node.getChildByName('首页选关6_9').active = false
// let curSpineNode = this.node.getChildByName(animNodeName)
// curSpineNode.active = true
// curSpineNode.getComponent(sp.Skeleton).setAnimation(0, anim3, true);
// if(config.id >= 6){
// this.ui_xianguan.active = false
// this.ui_xianguan6.active = true
// this.ui_xianguan6.getComponent(sp.Skeleton).setAnimation(0, spineName[2], true);
// }else {
// this.ui_xianguan.active = true
// this.ui_xianguan6.active = false
// this.ui_xianguan.getComponent(sp.Skeleton).setAnimation(0, spineName[2], true);
// }
//战力显示推荐
this.showPower(this.putongkuangBtn, config.power)
//普通宝箱显示
this.showBox(this.putongkuangBtn, ChapterDifficulty.Normal)
// this.showBox(this.kunnankuangBtn, ChapterDifficulty.Hard)
// this.showBox(this.diyukuangBtn, ChapterDifficulty.Hell)
// let suoding1 = find("锁定1",this.node)
// let suoding2 = find("锁定2",this.node)
// let suoding3 = find("锁定3",this.node)
// suoding1.active = false
// if(gg.data.doc.chapter<=9){
// suoding2.active = true
// suoding3.active = true
// }else if(gg.data.doc.chapter<=16){
// suoding2.active = false
// suoding3.active = true
// }
//设置框
let boxStatus1 = gg.data.project.getChapterStatus(this.chapterId+1, ChapterDifficulty.Normal, 0);
this.setChapterItem(config.id,boxStatus1);
}
async setChapterItem(chapterId: number,state : number){
//设置关卡预制体
this.ui_chapterNode.active = true;
this.ui_chapterNode.removeAllChildren();
let prefab = await this.loadPrefab(GBundle.Home,"prefab/"+"MainChapterItem"+chapterId) as Prefab;
let chapterItem = instantiate(prefab);
if (!chapterItem) {
console.warn("UIPanelHome: MainChapterItem"+chapterId+" prefab not ready", GBundle.Home);
return;
}
chapterItem.active = true;
this.setLayerMask(chapterItem, chapterItem.layer);
chapterItem.setPosition(v3(0, 0, 0));
this.ui_chapterNode.addChild(chapterItem);
//随机播放角色动画
this.randomRolePlay(chapterItem);
//未开启章节变灰
if(state == 0){
for (let i = 0; i < chapterItem.children.length; i++) {
if (chapterItem.children[i].name == "sp_chapter") {
chapterItem.children[i].getComponent(Sprite).grayscale = true;
}else{
chapterItem.children[i].active = false;
}
}
}else{
for (let i = 0; i < chapterItem.children.length; i++) {
if (chapterItem.children[i].name == "sp_chapter") {
chapterItem.children[i].getComponent(Sprite).grayscale = false;
}else{
chapterItem.children[i].active = true;
}
}
}
}
randomRolePlay(node: Node){
let role:string[] = [];
let roleName:string[] = ["role", "role-001", "role-002", "role-003", "role-004", "role-005"];
for (let i = 0; i < roleName.length; i++) {
let spine = find(roleName[i], node);
if(spine){
role.push(roleName[i]);
spine.getComponent(sp.Skeleton).setAnimation(0, '', false);
}
}
let count = role.length;
if (count === 1) {
let spine = find(role[0], node)?.getComponent(sp.Skeleton);
if (spine) {
spine.setAnimation(0, "选关页待机", true);
}
} else if (count >= 2) {
let selectCount = count - 1;
let shuffled = [...Array(count).keys()];
for (let i = shuffled.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
let selectedIndices = shuffled.slice(0, selectCount);
let si = 0;
const playNextSelected = () => {
if (si >= selectedIndices.length) return;
const idx = selectedIndices[si++];
const spine = find(role[idx], node)?.getComponent(sp.Skeleton);
if (spine) {
spine.setAnimation(0, "选关页待机", true);
}
if (si >= selectedIndices.length) return;
const gap = 0.25 + Math.random() * 1.25;
this.scheduleOnce(playNextSelected, gap);
};
this.scheduleOnce(playNextSelected, 0.5 + Math.random() * 1.5);
}
}
setLayerMask(n: Node, layerMask: number) {
n.layer = layerMask;
for (let i = 0; i < n.children.length; i++) {
if (n.children[i].isValid) {
this.setLayerMask(n.children[i], layerMask);
}
}
}
private async loadPrefab(bundleName, assetPath) {
let bundle = assetManager.getBundle(bundleName);
if (!bundle) bundle = await this.loadBundle(bundleName);
let res = await this.loadRes(bundle, assetPath);
return res;
}
private async loadBundle(bundleName) {
return new Promise<AssetManager.Bundle>((resolve, reject) => {
assetManager.loadBundle(bundleName, (err, bundle) => {
if (err) {
console.log(`加载Bundle:${bundleName}错误`, err);
resolve(null);
} else {
resolve(bundle);
}
})
})
}
private async loadRes(bundle: AssetManager.Bundle, assetPath) {
return new Promise<Asset>((resolve, reject) => {
let b = bundle.get(assetPath, Prefab);
if (b) {
resolve(b);
} else {
bundle.load(assetPath, Prefab, (err, asset) => {
if (err) {
console.log(`加载Bundle:${bundle.name},path:${assetPath}资源错误`, err);
resolve(null);
} else {
resolve(asset);
}
})
}
})
}
showBox(mainNode: Node, _battleMode: ChapterDifficulty) {
let baoxiang1 = find("宝箱开1", mainNode)
let baoxiang2 = find("宝箱开2", mainNode)
let baoxiang3 = find("宝箱开3", mainNode)
let boxBtn1 = find("boxBtn1", mainNode)
let boxBtn2 = find("boxBtn2", mainNode)
let boxBtn3 = find("boxBtn3", mainNode)
// let databattleType = OtherDataType.ChapterBoxGetData
// let strMondel = '普通'
// if (_battleMode == ChapterDifficulty.Normal) {
// databattleType = OtherDataType.ChapterBoxGetData
// strMondel = '普通'
// } else if (_battleMode == ChapterDifficulty.Hard) {
// databattleType = OtherDataType.ChapterBoxDataHard
// strMondel = '困难'
// } else if (_battleMode == ChapterDifficulty.Hell) {
// databattleType = OtherDataType.ChapterBoxDataHell
// strMondel = '地狱'
// }
let boxStatus1 = gg.data.project.getChapterStatus(this.chapterId+1, _battleMode, 0);
let boxStatus2 = gg.data.project.getChapterStatus(this.chapterId+1, _battleMode, 1);
let boxStatus3 = gg.data.project.getChapterStatus(this.chapterId+1, _battleMode, 2);
let curentProgress = 0;
let chapterProgressArr:number[] = [25,50,100];
if (boxStatus1 >= 1) curentProgress = chapterProgressArr[0];
if (boxStatus2 >= 1) curentProgress = chapterProgressArr[1];
if (boxStatus3 >= 1) curentProgress = chapterProgressArr[2];
this.sp_progress.fillRange = curentProgress;
if(boxStatus1 == 0){
//当前章节未达成
this.spCell1.active = false;
this.spCell2.active = true;
}else if(boxStatus1 == 1){
//当前章节已达成
this.spCell1.active = true;
this.spCell2.active = false;
}
console.log('boxStatus1=',this.chapterId,boxStatus1)
console.log('boxStatus2=',this.chapterId,boxStatus2)
console.log('boxStatus3=',this.chapterId,boxStatus3)
// let chapterBoxGetData = gg.data.getStringData(databattleType).split('#')
// // console.log('chapterBoxGetData=',chapterBoxGetData)
// // console.log('this.chapterId=',this.chapterId)
// let boxData = chapterBoxGetData[this.chapterId].split('&')
// console.log('boxData=',strMondel,boxData)
// let proGress = boxData[0]
let box1Status = boxStatus1 //1-已达成未领取
let box2Status = boxStatus2 //1-已达成未领取
let box3Status = boxStatus3 //1-已达成未领取
//0表示没有
//2表示已经领取
let isBoxClick = [box1Status, box2Status, box3Status]
// let showRed = false
// for (let i = 0; i < jinduArray.length; i++) {
// if (!isGetArray[i]) {
// showRed = true
// isBoxClick[i] = true
// }
// }
if (_battleMode == ChapterDifficulty.Normal) {
this.isGetArrayPT = [box1Status==1, box2Status==1, box3Status==1]
} else if (_battleMode == ChapterDifficulty.Hard) {
this.isGetArrayKN = [box1Status==1, box2Status==1, box3Status==1]
} else if (_battleMode == ChapterDifficulty.Hell) {
this.isGetArrayDY = [box1Status==1, box2Status==1, box3Status==1]
}
//console.log('this.isGetArray =',this.isGetArrayPT , this.chapterId)
// let redDot = find("dot",mainNode)
// redDot.active = showRed //表示有宝箱可以领取
baoxiang1.active = box1Status == 2
boxBtn1.active = box1Status != 2
boxBtn1.getChildByName('bg').getComponent(Sprite).grayscale = box1Status==0
boxBtn1.getChildByName('dot').active = box1Status == 1
baoxiang2.active = box2Status == 2
boxBtn2.active = box2Status != 2
boxBtn2.getChildByName('bg').getComponent(Sprite).grayscale = box2Status==0
boxBtn2.getChildByName('dot').active = box2Status == 1
baoxiang3.active = box3Status == 2
boxBtn3.active = box3Status != 2
boxBtn3.getChildByName('bg').getComponent(Sprite).grayscale = box3Status==0
boxBtn3.getChildByName('dot').active = box3Status == 1
}
showPower(btn: Node, power: number) {
let powerLab = find("zhandouli", btn).getComponent(Label);
powerLab.string = power.toString()
}
putongkuangBtnClick() {
//点击跳转到当前普通
GEvent.Ins.emit(GEvent.SelectChapter, this.chapterId + 1, ChapterDifficulty.Normal)
gg.ui.closePanel(UIID.jumpGameLevel)
}
kunnankuangBtnClick() {
//下一个等级是困难,当前是普通
GEvent.Ins.emit(GEvent.SelectChapter, this.chapterId + 1, ChapterDifficulty.Hard)
gg.ui.closePanel(UIID.jumpGameLevel)
}
diyukuangBtnClick() {
GEvent.Ins.emit(GEvent.SelectChapter, this.chapterId + 1, ChapterDifficulty.Hell)
gg.ui.closePanel(UIID.jumpGameLevel)
}
putongBoxBtnClick(event, index) {
let targetNode = event.target
let GameModel = ChapterDifficulty.Normal
let isGetArray = this.isGetArrayPT
let curChapterId = this.chapterId + 1
let nanduIndex = 0
if (targetNode) {
if (targetNode.getChildByName('bg').getComponent(Sprite).grayscale) {
//gg.ui.showToast("通关本章节领取宝箱")
} else {
let configData = this.getChapterConfig()
//this.isGetArray拿出false的box_reward
let box_reward = ''
for (let i = 0; i < isGetArray.length; i++) {
if (isGetArray[i] && i == 0) {
box_reward += configData.box_reward1.split('#')[nanduIndex]
} else if (isGetArray[i] && i == 1) {
box_reward = box_reward + "|" + configData.box_reward2.split('#')[nanduIndex]
} else if (isGetArray[i] && i == 2) {
box_reward = box_reward + "|" + configData.box_reward3.split('#')[nanduIndex]
}
}
//很多box_reward
this.showBoxReward(box_reward, 1, () => {
for (let i = 0; i < isGetArray.length; i++) {
if(isGetArray[i]){
gg.data.project.setChapterStatus(curChapterId, GameModel, i, 2);
}
}
//刷新界面
this.showBox(this.putongkuangBtn, GameModel)
})
}
}
}
kunnanoxBtnClick(event, index) {
let targetNode = event.target
let curChapterId = this.chapterId + 1
let isGetArray = this.isGetArrayKN
let nanduIndex = 1
if (targetNode) {
if (targetNode.getChildByName('宝箱关').getComponent(Sprite).grayscale) {
//gg.ui.showToast("通关本章节领取宝箱")
} else {
let configData = this.getChapterConfig()
//this.isGetArray拿出false的box_reward
//let str = ConstManager.getConstStringById(ConstEnum.DifficultyModleAddRatio);
// let arr = str.split(",");
let mt = 1//Number(arr[0])
let box_reward = '';
for (let i = 0; i < isGetArray.length; i++) {
if (isGetArray[i] && i == 0) {
box_reward += configData.box_reward1.split('#')[nanduIndex]
} else if (isGetArray[i] && i == 1) {
box_reward = box_reward + "|" + configData.box_reward2.split('#')[nanduIndex]
} else if (isGetArray[i] && i == 2) {
box_reward = box_reward + "|" + configData.box_reward3.split('#')[nanduIndex]
}
}
//很多box_reward
this.showBoxReward(box_reward, mt, () => {
//宝箱领取进度修改数据, 宝箱刷新
for (let i = 0; i < isGetArray.length; i++) {
if(isGetArray[i]){
gg.data.project.setChapterStatus(curChapterId, ChapterDifficulty.Hard, i, 2);
}
}
//刷新界面
this.showBox(this.kunnankuangBtn, ChapterDifficulty.Hard)
})
}
}
}
diyuBoxBtnClick(event, index) {
let targetNode = event.target
let isGetArray = this.isGetArrayDY
let curChapterId = this.chapterId + 1
let nanduIndex = 2
if (targetNode) {
if (targetNode.getChildByName('宝箱关').getComponent(Sprite).grayscale) {
//gg.ui.showToast("通关本章节领取宝箱")
} else {
let configData = this.getChapterConfig()
//this.isGetArray拿出false的box_reward
// let str = ConstManager.getConstStringById(ConstEnum.DifficultyModleAddRatio);
// let arr = str.split(",");
let mt = 1//Number(arr[1])
let box_reward = ''
for (let i = 0; i < isGetArray.length; i++) {
if (isGetArray[i] && i == 0) {
box_reward += configData.box_reward1.split('#')[nanduIndex]
} else if (isGetArray[i] && i == 1) {
box_reward = box_reward + "|" + configData.box_reward2.split('#')[nanduIndex]
} else if (isGetArray[i] && i == 2) {
box_reward = box_reward + "|" + configData.box_reward3.split('#')[nanduIndex]
}
}
//很多box_reward
this.showBoxReward(box_reward, mt, () => {
//宝箱领取进度修改数据, 宝箱刷新
for (let i = 0; i < isGetArray.length; i++) {
if(isGetArray[i]){
gg.data.project.setChapterStatus(curChapterId, ChapterDifficulty.Hell, i, 2);
}
}
//刷新界面
this.showBox(this.diyukuangBtn, ChapterDifficulty.Hell)
})
}
}
}
getChapterConfig() {
let curChapterId = this.chapterId + 1
let config: ITableChapter = null
// if (_battleMode == BattleMode.Easy) {
curChapterId = this.chapterId + 1
config = ChapterDataManager.getChapterDataById(curChapterId)
// } else if (_battleMode == BattleMode.Hard) {
// curChapterId = this.chapterId + 1 + 1000
// config = ChapterDataManager.getChapterDataById(curChapterId)
// } else if (_battleMode == BattleMode.Hell) {
// curChapterId = this.chapterId + 1 + 2000
// config = ChapterDataManager.getChapterDataById(curChapterId)
// }
return config
// if(index == 0){
// return config.box_reward1
// }else if(index == 1){
// return config.box_reward2
// }else if(index == 2){
// return config.box_reward3
// }
}
showBoxReward(boxRewardData, mt, callback) {
//奖励 有金币,体力和武器碎片
let list = boxRewardData.split('|')
let itemsArray = []
for (let i = 0; i < list.length; i++) {
let itemData = list[i]
if (itemData == '') {
continue
}
let itemId = Number(itemData.split(',')[0])
let itemNum = Number(itemData.split(',')[1])
if (itemId == 104 || itemId == 105 || itemId == 106 || itemId == 107) {
itemNum = Math.floor(itemNum * mt);
let boxRewardArray = gg.data.getFragmentNumArray(itemId + ',' + itemNum)
let statsArray = MTools.mergeToStatsArray(boxRewardArray)
for (let i = 0; i < statsArray.length; i++) {
let array = statsArray[i].split('|')
let item = new ItemData(Number(array[0]), Number(array[1]))
itemsArray.push(item)
}
} else {
let id = itemId//钻石
if (id != 4) {
itemNum = Math.floor(itemNum * mt);
}
let item = new ItemData(id, itemNum)
itemsArray.push(item)
}
}
gg.ui.openPanel(UIID.GetReward, {
data: itemsArray, onClose: () => {
if (callback) {
callback()
}
GEvent.Ins.emit(GEvent.jumpLayerOpenBox, this.chapterId + 1)
}
});
}
}