123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { UIButton } from "../../gcommon/UIButton";
- import { GameMng } from "../../GameMng";
- import CanjuModel from "./CanjuModel";
- import CellCanJuSel from "./CellCanJuSel";
- import { _decorator ,Component,Label,Node,instantiate} from "cc";
- const {ccclass, property} = _decorator;
- @ccclass
- export default class UICanJuSel extends Component {
- @property({ type: Node })
- public content: Node | null = null;
- private maxGridNum=12;
- private allPageNum=0;
- private curPage:number=1;
- @property(Node)
- btnNext: Node = null;
- @property(Node)
- btnUp: Node = null;
- start(){
-
- UIButton.BindClick(this.btnNext,()=>{
- this.nextPage();
- },this);
- UIButton.BindClick(this.btnUp,()=>{
- this.upPage();
- },this);
- this.initUI();
- }
- initUI(){
- for(let i=0;i<CanjuModel.Instance.canjuDataArr.length;i++){
- let gnode=instantiate(GameMng.Instance.canjuCell);
- gnode.getComponent(CellCanJuSel).setData(i);
- this.content.addChild(gnode);
-
- }
- let getcurpage=Math.floor(CanjuModel.Instance.getCurMaxLevel()/this.maxGridNum);
- if(CanjuModel.Instance.getCurMaxLevel()%this.maxGridNum!=0)
- getcurpage+=1;
- this.curPage=getcurpage;
- this.getallpage();
- this.selectPage(this.curPage);
- }
- private getallpage(){
- let allnum=CanjuModel.Instance.canjuDataArr.length;
- this.allPageNum=Math.floor(allnum/this.maxGridNum);
- let count=allnum%this.maxGridNum;
- if(count!=0)
- this.allPageNum+=1;
- return this.allPageNum;
- }
- nextPage(){
- if(this.curPage<this.allPageNum)
- this.curPage++;
- this.selectPage(this.curPage);
- }
- upPage(){
- if(this.curPage>1)
- this.curPage--;
- this.selectPage(this.curPage);
- }
- selectPage(pagenum:number){
- this.btnUp.active=pagenum!=1;
-
- if(pagenum>this.allPageNum)return;
- let count=this.maxGridNum;
- if(pagenum==this.allPageNum){
- let yushu=CanjuModel.Instance.canjuDataArr.length%this.maxGridNum;
- if(yushu!=0)
- count=yushu;
- }
- this.content.removeAllChildren();
- //
- let startIndex=(pagenum-1)*this.maxGridNum;
- if(pagenum>=this.allPageNum){
- this.btnNext.active=false;
- }
- else{
- this.btnNext.active=true;
- }
-
- for(let i=0;i<count;i++)
- {
- let cellNode = instantiate(GameMng.Instance.canjuCell);
- this.content.addChild(cellNode);
- cellNode.getComponent(CellCanJuSel).setData(startIndex+i);
- }
- }
- }
|