RedGrowthLayer.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import SoundMgr from "../base/SoundMgr";
  2. import Tool from "../base/Tool";
  3. var baseLayer = require('BaseLayer');
  4. cc.Class({
  5. extends: baseLayer,
  6. properties: {
  7. labTime: cc.Label,
  8. itemPre: cc.Node,
  9. conNode: cc.Node,
  10. togNodes: [cc.Node],
  11. },
  12. // LIFE-CYCLE CALLBACKS:
  13. onLoad () {
  14. this._super();
  15. this.initData();
  16. },
  17. start () {
  18. },
  19. initData(){
  20. this.dayData = [1,2,3,4,5,6]; //每日
  21. this.weekData = [7,8,9,10,11,12]; //每周
  22. this.monthData = [111,222,333,444]; //每月
  23. this.lerpTime = 1011262;
  24. this.daoshiji();
  25. this.schedule(this.daoshiji, 1, cc.macro.REPEAT_FOREVER);
  26. this.selectToggle(null, 0);
  27. },
  28. daoshiji(){
  29. if(this.lerpTime <= 1){
  30. //TODO
  31. this.unschedule(this.daoshiji);
  32. return;
  33. }
  34. this.lerpTime -= 1;
  35. this.labTime.string = Tool.timesBySec2(this.lerpTime);
  36. },
  37. selectToggle(event, index){ // 0 1 2
  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. if(index == 2){
  47. this.curData = this.monthData;
  48. }
  49. this.initItems();
  50. },
  51. initItems(){
  52. this.conNode.removeAllChildren();
  53. for(let i=0; i < this.curData.length; i++){
  54. let temp = cc.instantiate(this.itemPre);
  55. temp.setParent(this.conNode);
  56. temp.name = `${i}`;
  57. temp.active = true;
  58. temp.getChildByName('labDes').getComponent(cc.Label).string = '打烊前的最后一杯';
  59. temp.getChildByName('bar').getComponent(cc.Sprite).fillRange = 0.1;
  60. temp.getChildByName('labBar').getComponent(cc.Label).string = `${this.curData[i]}/${25}`;
  61. temp.getChildByName('no').active = false;
  62. temp.getChildByName('done').active = false;
  63. temp.getChildByName('get').active = true;
  64. Tool.addBtnListener(temp.getChildByName('get'), this.node, 'RedGrowthLayer', 'onClickGet', this.curData[i]);
  65. }
  66. },
  67. onClickGet(event, customEventData){
  68. SoundMgr.playClick();
  69. console.log('xxx: ', customEventData);
  70. },
  71. });