BottleSkinItem.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. goldLabel:cc.Label,
  29. nameLabel:cc.Label,
  30. lockedSprite:cc.Sprite,
  31. outlineSprite:cc.outline,
  32. position:0,
  33. store:cc.Node,
  34. },
  35. // LIFE-CYCLE CALLBACKS:
  36. onLoad () {
  37. this.goldLabel = this.node.children[1];
  38. this.nameLabel = this.node.children[2];
  39. this.lockedSprite = this.node.children[4];
  40. this.outlineSprite = this.node.children[5];
  41. this.node.on('touchend', ()=> {
  42. this.store.onItemClick(this.position);
  43. }, this);
  44. },
  45. init(bottleInfo,selected,store,position){
  46. this.position = position;
  47. this.store = store;
  48. this.goldLabel.getComponent(cc.Label).string = bottleInfo.price;
  49. this.nameLabel.getComponent(cc.Label).string = bottleInfo.name;
  50. this.lockedSprite.active = bottleInfo.isBought == 0;
  51. this.outlineSprite.active = selected;
  52. },
  53. setUnLock(){
  54. // this.outlineSprite.active = true;
  55. this.lockedSprite.active = false;
  56. },
  57. setSelected(selected){
  58. this.outlineSprite.active = selected;
  59. // this.lockedSprite.active = selected;
  60. },
  61. isUnLocked(){
  62. return this.lockedSprite.active == false;
  63. }
  64. // update (dt) {},
  65. });