123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import ResMgr from "../base/ResMgr";
- import SoundMgr from "../base/SoundMgr";
- import Tool from "../base/Tool";
- var baseLayer = require('BaseLayer');
- cc.Class({
- extends: baseLayer,
- properties: {
- itemPre: cc.Node,
- conNode: cc.Node,
- togNodes: [cc.Node],
- labHaveXZ: cc.Label,
- labNeedXZ: cc.Label,
- sp1: cc.Sprite,
- lab1: cc.Label,
- sp2: cc.Sprite,
- lab2: cc.Label,
- labDes: cc.Label,
- arrowNode: cc.Node,
- itemBoxPre: cc.Node,
- conBoxNode: cc.Node,
- boxView: cc.Node,
- jieshao: cc.Node,
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start () {
- this.initData();
- },
- initData(){
- this.dayData = [1,2,3,4,5,6]; //每日
- this.weekData = [7,8,9,10,11,12]; //每周
- this.boxData = [1,2,3,4,5,6,7,8,9]; //盒子
- this.selectToggle(null, 0);
- this.setBottom();
- this.initBox();
- },
- selectToggle(event, index){ //0 1
- 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;
- }
- 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.data = this.curData[i];
- temp.getChildByName('labCoin').getComponent(cc.Label).string = `x${111}`;
- temp.getChildByName('labXZ').getComponent(cc.Label).string = `x${2}`;
- let buyNode = temp.getChildByName('btn_buy');
- buyNode.active = true;
- Tool.addBtnListener(buyNode, this.node, 'TeHuiLayer', 'onClickBuy', this.curData[i]);
- }
- },
- setBottom(){
- this.labHaveXZ.string = 128;
- this.labNeedXZ.string = '/1';
- this.lab1.string = `x${1234}`;
- this.lab2.string = `x${2}`;
- this.labDes.string = `仅需${1}个勋章即可开启`;
- ResMgr.loadTexture('texture/resIcon/9005', (spFrame)=>{
- this.sp1.spriteFrame = spFrame;
- });
- ResMgr.loadTexture('texture/resIcon/9303', (spFrame)=>{
- this.sp2.spriteFrame = spFrame;
- });
- },
- initBox(){
- this.conBoxNode.removeAllChildren();
- for(let i=0; i < this.boxData.length; i++){
- let temp = cc.instantiate(this.itemBoxPre);
- temp.setParent(this.conBoxNode);
- temp.name = `${i}`;
- temp.active = true;
- temp.getChildByName('labXZ').getComponent(cc.Label).string = 121;
- let item1 = temp.getChildByName('item1');
- let item2 = temp.getChildByName('item2');
- let item3 = temp.getChildByName('item3');
- item1.active = true;
- item2.active = true;
- item3.active = false;
- if(1){
- item1.getChildByName('lab').getComponent(cc.Label).string = `x${18}`;
- ResMgr.loadTexture('texture/resIcon/9005', (spFrame)=>{
- item1.getChildByName('sp').getComponent(cc.Sprite).spriteFrame = spFrame;
- });
- item2.getChildByName('lab').getComponent(cc.Label).string = `x${19}`;
- ResMgr.loadTexture('texture/resIcon/9003', (spFrame)=>{
- item2.getChildByName('sp').getComponent(cc.Sprite).spriteFrame = spFrame;
- });
- }else{
- item3.getChildByName('lab').getComponent(cc.Label).string = `x${20}`;
- ResMgr.loadTexture('texture/resIcon/9005', (spFrame)=>{
- item3.getChildByName('sp').getComponent(cc.Sprite).spriteFrame = spFrame;
- });
- }
- }
- },
- onClickBox(){
- SoundMgr.playClick();
- this.arrowNode.scaleY = this.boxView.active ? -1 : 1;
- this.boxView.active = !this.boxView.active;
- },
- onClickRule(){
- SoundMgr.playClick();
- this.jieshao.active = !this.jieshao.active;
- },
- onClickBuy(event, customEventData){
- SoundMgr.playClick();
- console.log('buy: ', customEventData);
- },
-
- });
|