TeHuiLayer.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import ResMgr from "../base/ResMgr";
  2. import SoundMgr from "../base/SoundMgr";
  3. import Tool from "../base/Tool";
  4. var baseLayer = require('BaseLayer');
  5. cc.Class({
  6. extends: baseLayer,
  7. properties: {
  8. itemPre: cc.Node,
  9. conNode: cc.Node,
  10. togNodes: [cc.Node],
  11. labHaveXZ: cc.Label,
  12. labNeedXZ: cc.Label,
  13. sp1: cc.Sprite,
  14. lab1: cc.Label,
  15. sp2: cc.Sprite,
  16. lab2: cc.Label,
  17. labDes: cc.Label,
  18. arrowNode: cc.Node,
  19. itemBoxPre: cc.Node,
  20. conBoxNode: cc.Node,
  21. boxView: cc.Node,
  22. jieshao: cc.Node,
  23. },
  24. // LIFE-CYCLE CALLBACKS:
  25. // onLoad () {},
  26. start () {
  27. this.initData();
  28. },
  29. initData(){
  30. this.dayData = [1,2,3,4,5,6]; //每日
  31. this.weekData = [7,8,9,10,11,12]; //每周
  32. this.boxData = [1,2,3,4,5,6,7,8,9]; //盒子
  33. this.selectToggle(null, 0);
  34. this.setBottom();
  35. this.initBox();
  36. },
  37. selectToggle(event, index){ //0 1
  38. for(let i=0; i < this.togNodes.length; i++){
  39. this.togNodes[i].getChildByName('on').active = false;
  40. }
  41. this.togNodes[index].getChildByName('on').active = true;
  42. this.curData = this.dayData;
  43. if(index == 1){
  44. this.curData = this.weekData;
  45. }
  46. this.initItems();
  47. },
  48. initItems(){
  49. this.conNode.removeAllChildren();
  50. for(let i=0; i < this.curData.length; i++){
  51. let temp = cc.instantiate(this.itemPre);
  52. temp.setParent(this.conNode);
  53. temp.name = `${i}`;
  54. temp.active = true;
  55. // temp.data = this.curData[i];
  56. temp.getChildByName('labCoin').getComponent(cc.Label).string = `x${111}`;
  57. temp.getChildByName('labXZ').getComponent(cc.Label).string = `x${2}`;
  58. let buyNode = temp.getChildByName('btn_buy');
  59. buyNode.active = true;
  60. Tool.addBtnListener(buyNode, this.node, 'TeHuiLayer', 'onClickBuy', this.curData[i]);
  61. }
  62. },
  63. setBottom(){
  64. this.labHaveXZ.string = 128;
  65. this.labNeedXZ.string = '/1';
  66. this.lab1.string = `x${1234}`;
  67. this.lab2.string = `x${2}`;
  68. this.labDes.string = `仅需${1}个勋章即可开启`;
  69. ResMgr.loadTexture('texture/resIcon/9005', (spFrame)=>{
  70. this.sp1.spriteFrame = spFrame;
  71. });
  72. ResMgr.loadTexture('texture/resIcon/9303', (spFrame)=>{
  73. this.sp2.spriteFrame = spFrame;
  74. });
  75. },
  76. initBox(){
  77. this.conBoxNode.removeAllChildren();
  78. for(let i=0; i < this.boxData.length; i++){
  79. let temp = cc.instantiate(this.itemBoxPre);
  80. temp.setParent(this.conBoxNode);
  81. temp.name = `${i}`;
  82. temp.active = true;
  83. temp.getChildByName('labXZ').getComponent(cc.Label).string = 121;
  84. let item1 = temp.getChildByName('item1');
  85. let item2 = temp.getChildByName('item2');
  86. let item3 = temp.getChildByName('item3');
  87. item1.active = true;
  88. item2.active = true;
  89. item3.active = false;
  90. if(1){
  91. item1.getChildByName('lab').getComponent(cc.Label).string = `x${18}`;
  92. ResMgr.loadTexture('texture/resIcon/9005', (spFrame)=>{
  93. item1.getChildByName('sp').getComponent(cc.Sprite).spriteFrame = spFrame;
  94. });
  95. item2.getChildByName('lab').getComponent(cc.Label).string = `x${19}`;
  96. ResMgr.loadTexture('texture/resIcon/9003', (spFrame)=>{
  97. item2.getChildByName('sp').getComponent(cc.Sprite).spriteFrame = spFrame;
  98. });
  99. }else{
  100. item3.getChildByName('lab').getComponent(cc.Label).string = `x${20}`;
  101. ResMgr.loadTexture('texture/resIcon/9005', (spFrame)=>{
  102. item3.getChildByName('sp').getComponent(cc.Sprite).spriteFrame = spFrame;
  103. });
  104. }
  105. }
  106. },
  107. onClickBox(){
  108. SoundMgr.playClick();
  109. this.arrowNode.scaleY = this.boxView.active ? -1 : 1;
  110. this.boxView.active = !this.boxView.active;
  111. },
  112. onClickRule(){
  113. SoundMgr.playClick();
  114. this.jieshao.active = !this.jieshao.active;
  115. },
  116. onClickBuy(event, customEventData){
  117. SoundMgr.playClick();
  118. console.log('buy: ', customEventData);
  119. },
  120. });