TaskPage1.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import SoundMgr from "../base/SoundMgr";
  2. import Tool from "../base/Tool";
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. logoSpArr: [cc.SpriteFrame],
  7. propSpArr: [cc.SpriteFrame],
  8. itemPrefab: cc.Node,
  9. conNode: cc.Node,
  10. },
  11. // LIFE-CYCLE CALLBACKS:
  12. // onLoad () {},
  13. start () {
  14. },
  15. initData(index){
  16. this.type = index;
  17. this.data = [1,2,3,4,5,6, 7,8,9,10, 11];
  18. if(this.type == 0){
  19. this.data = [1,2];
  20. }
  21. this.conNode.removeAllChildren();
  22. for(let i=0; i < this.data.length; i++){
  23. let temp = cc.instantiate(this.itemPrefab);
  24. temp.setParent(this.conNode);
  25. temp.name = `${i}`;
  26. temp.active = true;
  27. temp.data = this.data[i];
  28. this.setItems(temp);
  29. }
  30. },
  31. setItems(tnode){
  32. tnode.getChildByName('logosp').getComponent(cc.Sprite).spriteFrame = this.logoSpArr[0];
  33. tnode.getChildByName('name').getComponent(cc.Label).string = '飓风行动';
  34. tnode.getChildByName('bar').getComponent(cc.Sprite).fillRange = 0.5;
  35. tnode.getChildByName('labPro').getComponent(cc.Label).string = `${3}/${4}`;
  36. tnode.getChildByName('rewardsp').getComponent(cc.Sprite).spriteFrame = this.propSpArr[0];
  37. tnode.getChildByName('labAmount').getComponent(cc.Label).string = `x${20}`;
  38. let gonode = tnode.getChildByName('go');
  39. gonode.active = true;
  40. Tool.addBtnListener(gonode, this.node, 'TaskPage1', 'onClickGo', tnode.data);
  41. let getnode = tnode.getChildByName('get');
  42. getnode.active = false;
  43. Tool.addBtnListener(getnode, this.node, 'TaskPage1', 'onClickGet', tnode.data);
  44. },
  45. onClickGo(event, customEventData){
  46. SoundMgr.playClick();
  47. console.log('go: ', customEventData);
  48. },
  49. onClickGet(event, customEventData){
  50. SoundMgr.playClick();
  51. console.log('get: ', customEventData);
  52. },
  53. });