LvUpBox.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. e =
  5. (this && this.__decorate) ||
  6. function (t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. };
  16. Object.defineProperty(i, "__esModule", {value: !0});
  17. const s = t("App"),
  18. o = t("HoldEvent"),
  19. a = t("PanelAni"),
  20. n = t("NotificationConst"),
  21. r = t("BagController"),
  22. l = t("MyBigLong"),
  23. h = t("MachineService"),
  24. c = t("MapService"),
  25. {ccclass: d, property: u} = cc._decorator;
  26. t = class extends cc.Component {
  27. constructor() {
  28. super(...arguments),
  29. (this.bgNode = null),
  30. (this.progressBar = null),
  31. (this.maxNode = null),
  32. (this.diamondNode = null),
  33. (this.starListNode = null),
  34. (this.lvUpBtn = null),
  35. (this.costLab = null),
  36. (this.doubleTipBg = null),
  37. (this.lvLab = null),
  38. (this.nameLab = null),
  39. (this.foodValueLab = null),
  40. (this.timeLab = null),
  41. (this.panelAni = null),
  42. (this.machineData = null);
  43. }
  44. onLoad() {
  45. (this.node.zIndex = 10), this.node.removeFromParent(!1);
  46. }
  47. onTouchLvUpBtn() {
  48. s.default.SoundManager.playEffect("clickBtn"),
  49. h.default.ins.lvUpkMachine(this.machineData.cfg.machine_num - 1),
  50. this.updateData();
  51. }
  52. updateData() {
  53. const t = this.machineData;
  54. t.attr.isMaxLevel()
  55. ? ((this.lvUpBtn.interactable = !1),
  56. (this.progressBar.progress = 1),
  57. (this.costLab.string = "MAX"),
  58. this.updateStar(!0))
  59. : ((this.lvUpBtn.interactable = t.canLevelUp()),
  60. (this.progressBar.progress = t.attr.getDoubleProgressRate()),
  61. (this.costLab.string = l.default.toString(t.attr.upgradeCost)),
  62. this.updateStar(!1)),
  63. (this.lvLab.string = "Lv." + t.attr.level),
  64. (this.foodValueLab.string = l.default.toString(t.attr.value)),
  65. (this.timeLab.string = t.attr.manufactureTime + "s"),
  66. (this.nameLab.string = t.name);
  67. }
  68. onUpdateMoney() {
  69. this.machineData.attr.isMaxLevel() || (this.lvUpBtn.interactable = this.machineData.canLevelUp());
  70. }
  71. onDisable() {
  72. s.default.NotificationCenter.removeListener(n.NotificationConst.UPDATE_MONEY, this.onUpdateMoney, this);
  73. }
  74. showBox(t) {
  75. if (t != this.machineData) {
  76. s.default.NotificationCenter.addListener(n.NotificationConst.UPDATE_MONEY, this.onUpdateMoney, this),
  77. (this.machineData = t),
  78. this.updateData(),
  79. (this.node.scale = 0);
  80. const i = t.getPos();
  81. i.y += 0;
  82. var e = 100 + this.node.width / 2,
  83. t = cc.view.getVisibleSize().width - this.node.width / 2 - 50;
  84. i.x < e ? (this.bgNode.x = 80) : i.x > t ? (this.bgNode.x = -80) : (this.bgNode.x = 0),
  85. (this.node.position = i),
  86. this.node.parent || c.default.ins.mapNode.addChild(this.node),
  87. this.panelAni.showPanel(),
  88. (this.doubleTipBg.active = !1);
  89. } else
  90. this.panelAni.hidePanel(() => {
  91. this.node.removeFromParent(!1), (this.machineData = null);
  92. });
  93. }
  94. hideBox() {
  95. this.node.parent &&
  96. this.panelAni.hidePanel(() => {
  97. this.node.removeFromParent(!1), (this.machineData = null);
  98. });
  99. }
  100. updateStar(t = !1) {
  101. var e = this.machineData.attr.getMaxStarNum(),
  102. i = this.machineData.attr.getCurStarNum(),
  103. s = Math.ceil(i / 5),
  104. o = t ? f : p[s],
  105. a = p[0 === s ? 0 : s - 1];
  106. let n = 5,
  107. r;
  108. r = e % 5 != 0 && Math.floor(e / 5) == Math.floor(i / 5) ? (n = e % 5) - e + i : i % 5;
  109. const l = this.starListNode.children;
  110. for (let t = 0; t < l.length; t++) (l[t].children[0].color = t < r ? o : a), (l[t].active = t < n);
  111. this.maxNode.active = t;
  112. }
  113. playGetDiamond() {
  114. if (this.diamondNode.active) {
  115. let t = cc.find("Canvas").getChildByName("DefaultCamera").getComponent(cc.Camera),
  116. e = this.diamondNode.convertToWorldSpaceAR(cc.Vec2.ZERO),
  117. i = t.getWorldToScreenPoint(e);
  118. s.default.NotificationCenter.dispatch(n.NotificationConst.PLAY_MONEY_ANI, r.CostType.diamond, 2, i);
  119. }
  120. this.doubleTipBg.stopAllActions(),
  121. (this.doubleTipBg.active = !0),
  122. (this.doubleTipBg.scale = 0),
  123. cc
  124. .tween(this.doubleTipBg)
  125. .to(0.2, {scale: 1})
  126. .delay(2)
  127. .call(() => {
  128. this.doubleTipBg.active = !1;
  129. })
  130. .start();
  131. }
  132. };
  133. e([u({type: cc.Node})], t.prototype, "bgNode", void 0),
  134. e([u({type: cc.ProgressBar})], t.prototype, "progressBar", void 0),
  135. e([u({type: cc.Node})], t.prototype, "maxNode", void 0),
  136. e([u({type: cc.Node})], t.prototype, "diamondNode", void 0),
  137. e([u({type: cc.Node})], t.prototype, "starListNode", void 0),
  138. e([u({type: o.default})], t.prototype, "lvUpBtn", void 0),
  139. e([u({type: cc.Label})], t.prototype, "costLab", void 0),
  140. e([u({type: cc.Node})], t.prototype, "doubleTipBg", void 0),
  141. e([u({type: cc.Label})], t.prototype, "lvLab", void 0),
  142. e([u({type: cc.Label})], t.prototype, "nameLab", void 0),
  143. e([u({type: cc.Label})], t.prototype, "foodValueLab", void 0),
  144. e([u({type: cc.Label})], t.prototype, "timeLab", void 0),
  145. e([u(a.PanelAni)], t.prototype, "panelAni", void 0),
  146. (t = e([d], t)),
  147. (i.default = t);
  148. const p = [
  149. cc.color().fromHEX("#FFFFFF"),
  150. cc.color().fromHEX("#ffc845"),
  151. cc.color().fromHEX("#8fdb52"),
  152. cc.color().fromHEX("#6be1f6"),
  153. cc.color().fromHEX("#ff6c6c")
  154. ],
  155. f = cc.color().fromHEX("#8fdb52");