我智商爆棚
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.
 
 
 
 
 
wozhishangbaopeng/assets/Scripts/levelPageScriptNew.ts

225 lines
8.5 KiB

// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import AppPlatform from "../FrameWork/Util/AppPlatform";
import Common5 from "../Platform/th/Common5";
import LevelSelectNew from "./levelSelectNew";
const {ccclass, property} = cc._decorator;
@ccclass
export default class levelPageNew extends cc.Component {
cellCount:number = 0;
pageIndex:number = 0;
typeIndex:number = 0;
@property(cc.Prefab)
levelPrefab: cc.Prefab = null;
@property(cc.Node)
levelsPage: cc.Node = null;
@property(cc.Label)
pageIndexLabel: cc.Label = null;
@property(cc.Node)
left: cc.Node = null;
@property(cc.Node)
right: cc.Node = null;
@property(cc.PageView)
levelPageView: cc.PageView = null;
onLoad() {
if (AppPlatform.is_TT_GAME_custom()){
const promise = ZYSDK.ZYSDK.getLevel()
try{
// 通过调用.then()方法来获取Promise对象的值
promise.then(value => {
console.log('Promise对象的值为', value);
if (value.length>0){
// Common5.gameConfig.GameAllType[0].Levels = value;
let tmpValue = [];
for (let i = 0; i < value.length; i++){
for (let j = 0; j < Common5.gameConfig.GameAllType[0].Levels.length; j++){
if (Common5.gameConfig.GameAllType[0].Levels[j] == value[i]){
tmpValue.push(value[i]);
break;
}
}
}
Common5.gameConfig.GameAllType[0].Levels = tmpValue;
}
this.initPage();
}).catch(error => {
console.error('发生错误', error);
this.initPage();
});
}
catch{
console.error('发生错误2');
this.initPage();
}
}
else if(AppPlatform.is_WECHAT_GAME_custom()){
const promise = ZYSDK.ZYSDK.getLevel()
try{
// 通过调用.then()方法来获取Promise对象的值
promise.then(value => {
console.log('Promise对象的值为========wx', value);
if (value.length>0){
Common5.gameConfig.GameAllType[0].Levels = value;
}
this.initPage();
}).catch(error => {
console.error('发生错误', error);
this.initPage();
});
}
catch{
console.error('发生错误2');
this.initPage();
}
}
else {
// let value=[1,2,3]
// let tmpValue = [];
// for (let i = 0; i < value.length; i++){
// for (let j = 0; j < Common5.gameConfig.GameAllType[0].Levels.length; j++){
// if (Common5.gameConfig.GameAllType[0].Levels[j] == value[i]){
// tmpValue.push(value[i]);
// break;
// }
// }
// }
// Common5.gameConfig.GameAllType[0].Levels = tmpValue;
this.initPage();
}
}
start () {
// this.initPage();
let index = 0
}
setCellCount(count){
this.cellCount = count;
}
setLevelIndex(index){
this.pageIndex = index;
}
setTypeIndex(index){
this.typeIndex = index;
// console.log("settype"+index)
}
initPage(){
let levelPage = null;
this.left.active = false;
this.pageIndexLabel.string = "1/"+ Math.ceil(Common5.gameConfig.GameAllType[Common5.curWordGameType].Levels.length/6);
for (let i = 0; i < Common5.gameConfig.GameAllType[Common5.curWordGameType].Levels.length; i++){
if (i%6 == 0){
levelPage = cc.instantiate(this.levelsPage);
levelPage.active = true;
this.levelPageView.addPage(levelPage);
}
if (i < 6){
let level = Common5.gameConfig.GameAllType[Common5.curWordGameType].Levels[i];
let levelNode = cc.instantiate(this.levelPrefab);
levelNode.getComponent(LevelSelectNew).setLevel(level,i);
levelNode.getComponent(LevelSelectNew).setType(0);
levelNode.getComponent(LevelSelectNew).updateUI()
levelPage.addChild(levelNode);
}
}
// this.levelPageView.scrollToPage(0,0.1);
this.levelPageView.setCurrentPageIndex(0);
this.node.getComponent(cc.Widget).updateAlignment();
}
protected onEnable(): void {
// console.log("enable!")
this.levelPageView.setCurrentPageIndex(this.levelPageView.getCurrentPageIndex());
}
leftClick(){
if (this.levelPageView.getCurrentPageIndex() > 0){
let allPages = this.levelPageView.getPages();
this.addLevelToPage(allPages[this.levelPageView.getCurrentPageIndex()],this.levelPageView.getCurrentPageIndex()-1)
this.levelPageView.scrollToPage(this.levelPageView.getCurrentPageIndex()-1,0.3);
allPages[this.levelPageView.getCurrentPageIndex()].children.forEach((ele)=>{
ele.active = false;
})
this.onPageClick();
}
}
rightClick(){
if (this.levelPageView.getCurrentPageIndex() < this.levelPageView.getPages().length-1){
let allPages = this.levelPageView.getPages();
this.addLevelToPage(allPages[this.levelPageView.getCurrentPageIndex()],this.levelPageView.getCurrentPageIndex()+1)
this.levelPageView.scrollToPage(this.levelPageView.getCurrentPageIndex()+1,0.3);
allPages[this.levelPageView.getCurrentPageIndex()].children.forEach((ele)=>{
ele.active = false;
})
this.onPageClick();
}
}
addLevelToPage(page,index){
if (page.childrenCount == 0){
let levelPage = page;
for (let i = index*6; i<Math.min(Common5.gameConfig.GameAllType[Common5.curWordGameType].Levels.length,(index+1)*6); i++){
let level = Common5.gameConfig.GameAllType[Common5.curWordGameType].Levels[i];
let levelNode = cc.instantiate(this.levelPrefab);
levelNode.getComponent(LevelSelectNew).setLevel(level,i);
levelNode.getComponent(LevelSelectNew).setType(0);
levelNode.getComponent(LevelSelectNew).updateUI()
levelPage.addChild(levelNode);
}
}
else {
page.children.forEach(element => {
element.active = true;
});
}
}
updateUI(){
// console.log('updateUI levelPageNew')
}
onPageClick(){
// console.log(this.levelPageView.getCurrentPageIndex())
let index = this.levelPageView.getCurrentPageIndex()
// console.log(index)
let allPages = this.levelPageView.getPages();
this.addLevelToPage(allPages[index],index)
this.pageIndexLabel.string = (this.levelPageView.getCurrentPageIndex()+1) + "/"+ Math.ceil(Common5.gameConfig.GameAllType[Common5.curWordGameType].Levels.length/6);
if (this.levelPageView.getCurrentPageIndex() <= 0){
this.left.active = false;
}
else {
this.left.active = true;
allPages[this.levelPageView.getCurrentPageIndex()-1].children.forEach((ele)=>{
ele.active = false;
})
}
console.log(this.levelPageView.getPages().length)
if (this.levelPageView.getCurrentPageIndex() >= this.levelPageView.getPages().length-1){
this.right.active = false;
}
else {
this.right.active = true;
allPages[this.levelPageView.getCurrentPageIndex()+1].children.forEach((ele)=>{
ele.active = false;
})
}
}
setGameType(wordGameTypeImg){
}
// update (dt) {}
}