5caa2c10-816d-4933-8626-1b77ab7f1c39.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. "use strict";
  2. cc._RF.push(module, '5caa2wQgW1JM4YmG3erfxw5', 'NodeFood');
  3. // Script/view/chooseLevel/NodeFood.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var App_1 = require("../../Manager/App");
  26. var hallModel_1 = require("../../model/hallModel");
  27. var TipPanel_1 = require("../tipPanel/TipPanel");
  28. var TipPanelMediator_1 = require("../tipPanel/TipPanelMediator");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. var NodeFood = /** @class */ (function (_super) {
  31. __extends(NodeFood, _super);
  32. function NodeFood() {
  33. var _this = _super !== null && _super.apply(this, arguments) || this;
  34. _this.labelExp = null;
  35. _this.btnList = [];
  36. _this.LabelCoinNum = [];
  37. _this.shengjiTishi = [];
  38. _this.foodSpriteFrame = [];
  39. _this.foodName = [];
  40. _this.selectSprite = null;
  41. _this.labelCurSoldPrice = null;
  42. _this.labelNexSoldPrice = null;
  43. _this.selectUpIndex = -1;
  44. _this.btnUpgrade = null;
  45. return _this;
  46. // update (dt) {}
  47. }
  48. NodeFood.prototype.onLoad = function () {
  49. for (var i = 0; i < 6; i++) {
  50. this.btnList[i] = this.node.getChildByName("btnFood" + i).getComponent(cc.Button);
  51. this.btnList[i].node.on("click", this.btnClickCallBack.bind(this, i), this);
  52. this.LabelCoinNum[i] = this.btnList[i].node.getChildByName("LabelCoinNum").getComponent(cc.Label);
  53. this.shengjiTishi[i] = this.btnList[i].node.getChildByName("tip_shenji");
  54. this.shengjiTishi[i].active = false;
  55. var level = App_1.App.DataManager.foodLevel[i];
  56. if (level < App_1.App.DataManager.maxFoodLevel) {
  57. // 升级所需金币
  58. this.LabelCoinNum[i].string = App_1.App.DataManager.upgradeFoodCoin[i][level] + "";
  59. if (App_1.App.DataManager.UserCoin > App_1.App.DataManager.upgradeFoodCoin[i][level]) {
  60. // 提示可以升级
  61. this.shengjiTishi[i].active = true;
  62. }
  63. }
  64. else {
  65. this.btnList[i].interactable = false;
  66. this.LabelCoinNum[i].node.active = false;
  67. }
  68. }
  69. this.btnUpgrade.node.on("click", this.clickBtnUpgrade.bind(this), this);
  70. //this.foodName = ["牛排", "果汁", "黄瓜", "番茄", "芝士", "番茄酱"];
  71. this.foodName = ["steak", "fruit juice", "cuke", "tomato", "cheese", "catchup"];
  72. };
  73. NodeFood.prototype.start = function () {
  74. this.findUpGrade();
  75. };
  76. // 默认选择
  77. NodeFood.prototype.findUpGrade = function () {
  78. this.selectUpIndex = -1;
  79. for (var i = App_1.App.DataManager.foodLevel.length - 1; i >= 0; i--) {
  80. var foodCurLevel = App_1.App.DataManager.foodLevel[i];
  81. if (foodCurLevel == App_1.App.DataManager.maxFoodLevel) {
  82. this.btnList[i].interactable = false;
  83. this.LabelCoinNum[i].node.active = false;
  84. }
  85. else {
  86. this.selectUpIndex = i;
  87. this.LabelCoinNum[i].string = App_1.App.DataManager.upgradeFoodCoin[i][foodCurLevel] + "";
  88. }
  89. }
  90. this.btnClickCallBack(this.selectUpIndex);
  91. };
  92. NodeFood.prototype.btnClickCallBack = function (index) {
  93. if (index < 0) {
  94. return;
  95. }
  96. this.selectUpIndex = index;
  97. this.labelExp.string = this.foodName[index];
  98. this.selectSprite.spriteFrame = this.foodSpriteFrame[index];
  99. var foodCurLevel = App_1.App.DataManager.foodLevel[index];
  100. this.labelCurSoldPrice.string = App_1.App.DataManager.foodSoldCoin[index][foodCurLevel] + "";
  101. this.labelNexSoldPrice.string = App_1.App.DataManager.foodSoldCoin[index][foodCurLevel + 1] + "";
  102. };
  103. NodeFood.prototype.clickBtnUpgrade = function () {
  104. if (this.selectUpIndex < 0) {
  105. App_1.App.Facade.popView(TipPanelMediator_1.default, TipPanel_1.default, "It's the highest level", false);
  106. return;
  107. }
  108. var foodCurLevel = App_1.App.DataManager.foodLevel[this.selectUpIndex];
  109. var upgradeCoin = App_1.App.DataManager.upgradeFoodCoin[this.selectUpIndex][foodCurLevel];
  110. if (App_1.App.DataManager.UserCoin < upgradeCoin) {
  111. App_1.App.Facade.popView(TipPanelMediator_1.default, TipPanel_1.default, "Not enough gold coins", false); //Not enough gold coins." 金币不足
  112. }
  113. else {
  114. App_1.App.DataManager.foodLevel[this.selectUpIndex]++;
  115. App_1.App.DataManager.UserCoin -= upgradeCoin;
  116. // 保存到本地
  117. App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_Coin, App_1.App.DataManager.UserCoin);
  118. App_1.App.LocalStorageUtil.setJsonObj(App_1.App.LocalStorageUtil.list_foodLevel, App_1.App.DataManager.foodLevel);
  119. App_1.App.Facade.popView(TipPanelMediator_1.default, TipPanel_1.default, "update successfully", false);
  120. App_1.App.Facade.getModel(hallModel_1.default).updateCoinNumber();
  121. for (var i = 0; i < 6; i++) {
  122. var level = App_1.App.DataManager.foodLevel[i];
  123. this.shengjiTishi[i].active = false;
  124. if (level < App_1.App.DataManager.maxFoodLevel) {
  125. // 升级所需金币
  126. this.LabelCoinNum[i].string = App_1.App.DataManager.upgradeFoodCoin[i][level] + "";
  127. if (App_1.App.DataManager.UserCoin > App_1.App.DataManager.upgradeFoodCoin[i][level]) {
  128. //提示可以升级
  129. this.shengjiTishi[i].active = true;
  130. }
  131. }
  132. else {
  133. this.btnList[i].interactable = false;
  134. this.LabelCoinNum[i].node.active = false;
  135. }
  136. }
  137. this.findUpGrade();
  138. }
  139. };
  140. __decorate([
  141. property(cc.Label)
  142. ], NodeFood.prototype, "labelExp", void 0);
  143. __decorate([
  144. property([cc.SpriteFrame])
  145. ], NodeFood.prototype, "foodSpriteFrame", void 0);
  146. __decorate([
  147. property(cc.Sprite)
  148. ], NodeFood.prototype, "selectSprite", void 0);
  149. __decorate([
  150. property(cc.Label)
  151. ], NodeFood.prototype, "labelCurSoldPrice", void 0);
  152. __decorate([
  153. property(cc.Label)
  154. ], NodeFood.prototype, "labelNexSoldPrice", void 0);
  155. __decorate([
  156. property(cc.Button)
  157. ], NodeFood.prototype, "btnUpgrade", void 0);
  158. NodeFood = __decorate([
  159. ccclass
  160. ], NodeFood);
  161. return NodeFood;
  162. }(cc.Component));
  163. exports.default = NodeFood;
  164. cc._RF.pop();