VIPLayer.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import ResMgr from "../base/ResMgr";
  2. import SoundMgr from "../base/SoundMgr";
  3. var baseLayer = require('BaseLayer');
  4. cc.Class({
  5. extends: baseLayer,
  6. properties: {
  7. atlasVIP: cc.SpriteAtlas, //vip图集
  8. labVV: cc.Label,
  9. labV: cc.Label,
  10. labZai: cc.Label,
  11. labNextV: cc.Label,
  12. roleNode: cc.Node,
  13. daoNode: cc.Node,
  14. dao2Node: cc.Node,
  15. spCurV: cc.Sprite,
  16. spNextV: cc.Sprite,
  17. spBar: cc.Sprite,
  18. labBar: cc.Label,
  19. labDes: cc.Label,
  20. labCoin: cc.Label,
  21. labY: cc.Label,
  22. pageView:cc.PageView,
  23. pageConNodes: [cc.Node],
  24. },
  25. // LIFE-CYCLE CALLBACKS:
  26. // onLoad () {},
  27. start () {
  28. this.daoSpId = [121, 122, 123, 124, 125, 126, 127, 128, 129, 130];
  29. this.selectVIP = 6; //当前选中的VIP
  30. this.labZai.string = `${78}元`;
  31. this.labNextV.string = `VIP${8}`;
  32. this.spCurV.spriteFrame = this.atlasVIP.getSpriteFrame('VIP2');
  33. this.spNextV.spriteFrame = this.atlasVIP.getSpriteFrame('VIP3');
  34. this.spBar.fillRange = 0.3;
  35. this.labBar.string = '12/21';
  36. this.labDes.string = `VIP${21}限购礼包`;
  37. this.labCoin.string = `212万`;
  38. this.labY.string = `${121}元购买`;
  39. this.initData();
  40. },
  41. initData(){
  42. this.onSetVIPIndex();
  43. this.setPage(this.pageConNodes[1], this.selectVIP);
  44. this.pageView.scrollToPage(1, 0);
  45. this.pageView.node.on('scroll-ended', this.onScrollToPageEnd, this);
  46. },
  47. onSetVIPIndex(){
  48. this.labVV.string = `VIP${this.selectVIP}`;
  49. this.labV.string = `VIP${this.selectVIP}特权`;
  50. //人物和刀
  51. for(let i=0; i < this.roleNode.childrenCount; i++){
  52. this.roleNode.children[i].active = false;
  53. }
  54. this.roleNode.children[this.selectVIP-1].active = true;
  55. for(let i=0; i < this.daoNode.childrenCount; i++){
  56. ResMgr.loadTexture(`texture/resIcon/${this.daoSpId[this.selectVIP-1]}`, (spFrame)=>{
  57. this.daoNode.children[i].getComponent(cc.Sprite).spriteFrame = spFrame;
  58. this.dao2Node.children[i].getComponent(cc.Sprite).spriteFrame = spFrame;
  59. });
  60. }
  61. },
  62. setPage(node, vipLv){
  63. if(vipLv < 1 || vipLv > 10) return;
  64. let layout = node.getChildByName('layout');
  65. for(let i=0; i < layout.childrenCount; i++){
  66. if(i == 0){
  67. layout.children[i].getChildByName('sp').getComponent(cc.Sprite).spriteFrame = this.atlasVIP.getSpriteFrame(`VIPdi${vipLv}`);
  68. }
  69. if(i == 2){
  70. ResMgr.loadTexture(`texture/resIcon/${this.daoSpId[vipLv-1]}`, (spFrame)=>{
  71. layout.children[i].getChildByName('sp').getComponent(cc.Sprite).spriteFrame = spFrame;
  72. });
  73. }
  74. if(i == 5){
  75. layout.children[i].getChildByName('lab').getComponent(cc.Label).string = `暴击获得${vipLv}倍`;
  76. }
  77. }
  78. },
  79. onScrollToPageEnd(){
  80. this.setPage(this.pageConNodes[1], this.selectVIP);
  81. this.scheduleOnce(()=>{
  82. this.pageView.scrollToPage(1, 0);
  83. console.log('xxx: ', this.pageView.getCurrentPageIndex());
  84. }, 0);
  85. },
  86. onClickLeft(){
  87. SoundMgr.playClick();
  88. if(this.selectVIP == 1)
  89. return;
  90. this.selectVIP -= 1;
  91. this.onSetVIPIndex();
  92. this.setPage(this.pageConNodes[0], this.selectVIP);
  93. this.scheduleOnce(()=>{
  94. this.pageView.scrollToPage(0, 1);
  95. }, 0);
  96. },
  97. onClickRight(){
  98. SoundMgr.playClick();
  99. if(this.selectVIP == 10)
  100. return;
  101. this.selectVIP += 1;
  102. this.onSetVIPIndex();
  103. this.setPage(this.pageConNodes[2], this.selectVIP);
  104. this.scheduleOnce(()=>{
  105. this.pageView.scrollToPage(2, 1);
  106. }, 0);
  107. },
  108. onClickShop(){
  109. // SoundMgr.playClick();
  110. this.onClose();
  111. cc.find('Canvas').getComponent('HallScene').onClickShop();
  112. },
  113. onClickBuy(){
  114. SoundMgr.playClick();
  115. },
  116. onClose(){
  117. this.pageView.node.off('scroll-ended', this.onScrollToPageEnd, this);
  118. this._super();
  119. },
  120. });