itemMoney.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. },
  5. onLoad() {
  6. this.node.on("click", this._click, this)
  7. this.iconSprite = this.node.getComponent(cc.Sprite);
  8. // this.itemLabel_1 = this.node.children[0].children[0].getComponent(cc.Label);
  9. this.btn = this.node.getComponent(cc.Button);
  10. },
  11. init(src,id){
  12. this.id = id;
  13. this.src = src;
  14. //分平台展示
  15. if (id == 0 && AppConst.CHANNEL != AppConst.channel.QQMiniGame) {
  16. // 自动选中第一个
  17. this.src.selectedId = 1;
  18. this.node.active = false;
  19. let src = this.node.parent.children[1].getComponent("itemMoney");
  20. src.iconSprite.spriteFrame = this.src.iconSpriteFrame[1];
  21. return;
  22. }
  23. // TODO 新手判断
  24. if (id == 0) {
  25. if (window.newPlayer) {
  26. // 自动选中第零个
  27. this.src.selectedId = 0;
  28. this.node.active = true;
  29. this.iconSprite.spriteFrame = this.src.iconSpriteFrame[1];
  30. } else {
  31. // 自动选中第一个
  32. this.src.selectedId = 1;
  33. this.node.active = false;
  34. let src = this.node.parent.children[1].getComponent("itemMoney");
  35. src.iconSprite.spriteFrame = this.src.iconSpriteFrame[1];
  36. }
  37. }
  38. },
  39. _click(){
  40. this.src.selectedId = this.id;
  41. let parent = this.node.parent;
  42. for (let i = 0; i < parent.childrenCount; i++) {
  43. let itemMoney = parent.children[i].getComponent("itemMoney");
  44. if(i == this.id){
  45. itemMoney.iconSprite.spriteFrame = this.src.iconSpriteFrame[1];
  46. }else{
  47. itemMoney.iconSprite.spriteFrame = this.src.iconSpriteFrame[0];
  48. }
  49. }
  50. }
  51. // update (dt) {},
  52. });