UICanJuSel.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { UIButton } from "../../gcommon/UIButton";
  2. import { GameMng } from "../../GameMng";
  3. import CanjuModel from "./CanjuModel";
  4. import CellCanJuSel from "./CellCanJuSel";
  5. import { _decorator ,Component,Label,Node,instantiate} from "cc";
  6. const {ccclass, property} = _decorator;
  7. @ccclass
  8. export default class UICanJuSel extends Component {
  9. @property({ type: Node })
  10. public content: Node | null = null;
  11. private maxGridNum=12;
  12. private allPageNum=0;
  13. private curPage:number=1;
  14. @property(Node)
  15. btnNext: Node = null;
  16. @property(Node)
  17. btnUp: Node = null;
  18. start(){
  19. UIButton.BindClick(this.btnNext,()=>{
  20. this.nextPage();
  21. },this);
  22. UIButton.BindClick(this.btnUp,()=>{
  23. this.upPage();
  24. },this);
  25. this.initUI();
  26. }
  27. initUI(){
  28. for(let i=0;i<CanjuModel.Instance.canjuDataArr.length;i++){
  29. let gnode=instantiate(GameMng.Instance.canjuCell);
  30. gnode.getComponent(CellCanJuSel).setData(i);
  31. this.content.addChild(gnode);
  32. }
  33. let getcurpage=Math.floor(CanjuModel.Instance.getCurMaxLevel()/this.maxGridNum);
  34. if(CanjuModel.Instance.getCurMaxLevel()%this.maxGridNum!=0)
  35. getcurpage+=1;
  36. this.curPage=getcurpage;
  37. this.getallpage();
  38. this.selectPage(this.curPage);
  39. }
  40. private getallpage(){
  41. let allnum=CanjuModel.Instance.canjuDataArr.length;
  42. this.allPageNum=Math.floor(allnum/this.maxGridNum);
  43. let count=allnum%this.maxGridNum;
  44. if(count!=0)
  45. this.allPageNum+=1;
  46. return this.allPageNum;
  47. }
  48. nextPage(){
  49. if(this.curPage<this.allPageNum)
  50. this.curPage++;
  51. this.selectPage(this.curPage);
  52. }
  53. upPage(){
  54. if(this.curPage>1)
  55. this.curPage--;
  56. this.selectPage(this.curPage);
  57. }
  58. selectPage(pagenum:number){
  59. this.btnUp.active=pagenum!=1;
  60. if(pagenum>this.allPageNum)return;
  61. let count=this.maxGridNum;
  62. if(pagenum==this.allPageNum){
  63. let yushu=CanjuModel.Instance.canjuDataArr.length%this.maxGridNum;
  64. if(yushu!=0)
  65. count=yushu;
  66. }
  67. this.content.removeAllChildren();
  68. //
  69. let startIndex=(pagenum-1)*this.maxGridNum;
  70. if(pagenum>=this.allPageNum){
  71. this.btnNext.active=false;
  72. }
  73. else{
  74. this.btnNext.active=true;
  75. }
  76. for(let i=0;i<count;i++)
  77. {
  78. let cellNode = instantiate(GameMng.Instance.canjuCell);
  79. this.content.addChild(cellNode);
  80. cellNode.getComponent(CellCanJuSel).setData(startIndex+i);
  81. }
  82. }
  83. }