1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import SoundMgr from "../base/SoundMgr";
- import Tool from "../base/Tool";
- var baseLayer = require('BaseLayer');
- cc.Class({
- extends: baseLayer,
- properties: {
- labTime: cc.Label,
- itemPre: cc.Node,
- conNode: cc.Node,
- togNodes: [cc.Node],
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this._super();
- this.initData();
- },
- start () {
- },
- initData(){
- this.dayData = [1,2,3,4,5,6]; //每日
- this.weekData = [7,8,9,10,11,12]; //每周
- this.monthData = [111,222,333,444]; //每月
- this.lerpTime = 1011262;
- this.daoshiji();
- this.schedule(this.daoshiji, 1, cc.macro.REPEAT_FOREVER);
- this.selectToggle(null, 0);
- },
- daoshiji(){
- if(this.lerpTime <= 1){
- //TODO
- this.unschedule(this.daoshiji);
- return;
- }
- this.lerpTime -= 1;
- this.labTime.string = Tool.timesBySec2(this.lerpTime);
- },
- selectToggle(event, index){ // 0 1 2
- for(let i=0; i < this.togNodes.length; i++){
- this.togNodes[i].getChildByName('on').active = false;
- }
- this.togNodes[index].getChildByName('on').active = true;
-
- this.curData = this.dayData;
- if(index == 1){
- this.curData = this.weekData;
- }
- if(index == 2){
- this.curData = this.monthData;
- }
- this.initItems();
- },
- initItems(){
- this.conNode.removeAllChildren();
- for(let i=0; i < this.curData.length; i++){
- let temp = cc.instantiate(this.itemPre);
- temp.setParent(this.conNode);
- temp.name = `${i}`;
- temp.active = true;
- temp.getChildByName('labDes').getComponent(cc.Label).string = '打烊前的最后一杯';
- temp.getChildByName('bar').getComponent(cc.Sprite).fillRange = 0.1;
- temp.getChildByName('labBar').getComponent(cc.Label).string = `${this.curData[i]}/${25}`;
- temp.getChildByName('no').active = false;
- temp.getChildByName('done').active = false;
- temp.getChildByName('get').active = true;
- Tool.addBtnListener(temp.getChildByName('get'), this.node, 'RedGrowthLayer', 'onClickGet', this.curData[i]);
- }
- },
- onClickGet(event, customEventData){
- SoundMgr.playClick();
- console.log('xxx: ', customEventData);
- },
- });
|