DogContainer.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. work: {
  5. default: null,
  6. type: cc.SpriteFrame,
  7. serializable: true,
  8. },
  9. sleep: {
  10. default: null,
  11. type: cc.SpriteFrame,
  12. serializable: true,
  13. },
  14. dogBasinFood: {
  15. default: null,
  16. type: cc.SpriteFrame,
  17. serializable: true,
  18. },
  19. dogBasin: {
  20. default: null,
  21. type: cc.SpriteFrame,
  22. serializable: true,
  23. },
  24. DogNode: {
  25. default: null,
  26. type: cc.Node,
  27. serializable: true,
  28. },
  29. DogSliderNode: {
  30. default: null,
  31. type: cc.Node,
  32. serializable: true,
  33. },
  34. DogSliderLabel: {
  35. default: null,
  36. type: cc.Label,
  37. serializable: true,
  38. },
  39. basinNode: {
  40. default: null,
  41. type: cc.Node,
  42. serializable: true,
  43. },
  44. basinSliderNode: {
  45. default: null,
  46. type: cc.Node,
  47. serializable: true,
  48. },
  49. basinSliderLabel: {
  50. default: null,
  51. type: cc.Label,
  52. serializable: true,
  53. },
  54. },
  55. // LIFE-CYCLE CALLBACKS:
  56. // onLoad () {},
  57. start() {
  58. this.basinNode.on(cc.Node.EventType.TOUCH_START, () => {
  59. console.log("点击添加狗粮");
  60. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "添加狗粮..", 5);
  61. let data = { foodId: 1 };
  62. GlobalD.GameData.onGetAddDogFood(data, (value) => {
  63. console.log(value);
  64. if (0 === value.code) {
  65. //收成后处理相关状态
  66. this.onGetList();
  67. GlobalD.GameData.hideToast();
  68. }else {
  69. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
  70. }
  71. });
  72. })
  73. },
  74. onGetList() {
  75. //获取狗的信息
  76. GlobalD.GameData.onGetEquipmentListState((value) => {
  77. console.log(value);
  78. let _list = value.data;
  79. for (let i = 0; i < _list.length; i++) {
  80. if (0 === _list[i].mallOther.otherType) {
  81. //存在狗
  82. this.DogNode.active = true;
  83. if (0 === _list[i].remainingConsumption) {
  84. this.DogNode.getComponent(cc.Sprite).spriteFrame = this.sleep;
  85. }
  86. GlobalD.Dog = _list[i];
  87. this.DogSliderLabel.string = "剩" + _list[i].remainingDay + "天";
  88. this.basinSliderLabel.string = "剩余" + _list[i].remainingConsumption + "G";
  89. } else if (1 === _list[i].mallOther.otherType) {
  90. GlobalD.Stick = _list[i];
  91. }
  92. }
  93. })
  94. }
  95. // update (dt) {},
  96. });