"use strict"; cc._RF.push(module, '5caa2wQgW1JM4YmG3erfxw5', 'NodeFood'); // Script/view/chooseLevel/NodeFood.ts "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var App_1 = require("../../Manager/App"); var hallModel_1 = require("../../model/hallModel"); var TipPanel_1 = require("../tipPanel/TipPanel"); var TipPanelMediator_1 = require("../tipPanel/TipPanelMediator"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var NodeFood = /** @class */ (function (_super) { __extends(NodeFood, _super); function NodeFood() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.labelExp = null; _this.btnList = []; _this.LabelCoinNum = []; _this.shengjiTishi = []; _this.foodSpriteFrame = []; _this.foodName = []; _this.selectSprite = null; _this.labelCurSoldPrice = null; _this.labelNexSoldPrice = null; _this.selectUpIndex = -1; _this.btnUpgrade = null; return _this; // update (dt) {} } NodeFood.prototype.onLoad = function () { for (var i = 0; i < 6; i++) { this.btnList[i] = this.node.getChildByName("btnFood" + i).getComponent(cc.Button); this.btnList[i].node.on("click", this.btnClickCallBack.bind(this, i), this); this.LabelCoinNum[i] = this.btnList[i].node.getChildByName("LabelCoinNum").getComponent(cc.Label); this.shengjiTishi[i] = this.btnList[i].node.getChildByName("tip_shenji"); this.shengjiTishi[i].active = false; var level = App_1.App.DataManager.foodLevel[i]; if (level < App_1.App.DataManager.maxFoodLevel) { // 升级所需金币 this.LabelCoinNum[i].string = App_1.App.DataManager.upgradeFoodCoin[i][level] + ""; if (App_1.App.DataManager.UserCoin > App_1.App.DataManager.upgradeFoodCoin[i][level]) { // 提示可以升级 this.shengjiTishi[i].active = true; } } else { this.btnList[i].interactable = false; this.LabelCoinNum[i].node.active = false; } } this.btnUpgrade.node.on("click", this.clickBtnUpgrade.bind(this), this); //this.foodName = ["牛排", "果汁", "黄瓜", "番茄", "芝士", "番茄酱"]; this.foodName = ["steak", "fruit juice", "cuke", "tomato", "cheese", "catchup"]; }; NodeFood.prototype.start = function () { this.findUpGrade(); }; // 默认选择 NodeFood.prototype.findUpGrade = function () { this.selectUpIndex = -1; for (var i = App_1.App.DataManager.foodLevel.length - 1; i >= 0; i--) { var foodCurLevel = App_1.App.DataManager.foodLevel[i]; if (foodCurLevel == App_1.App.DataManager.maxFoodLevel) { this.btnList[i].interactable = false; this.LabelCoinNum[i].node.active = false; } else { this.selectUpIndex = i; this.LabelCoinNum[i].string = App_1.App.DataManager.upgradeFoodCoin[i][foodCurLevel] + ""; } } this.btnClickCallBack(this.selectUpIndex); }; NodeFood.prototype.btnClickCallBack = function (index) { if (index < 0) { return; } this.selectUpIndex = index; this.labelExp.string = this.foodName[index]; this.selectSprite.spriteFrame = this.foodSpriteFrame[index]; var foodCurLevel = App_1.App.DataManager.foodLevel[index]; this.labelCurSoldPrice.string = App_1.App.DataManager.foodSoldCoin[index][foodCurLevel] + ""; this.labelNexSoldPrice.string = App_1.App.DataManager.foodSoldCoin[index][foodCurLevel + 1] + ""; }; NodeFood.prototype.clickBtnUpgrade = function () { if (this.selectUpIndex < 0) { App_1.App.Facade.popView(TipPanelMediator_1.default, TipPanel_1.default, "It's the highest level", false); return; } var foodCurLevel = App_1.App.DataManager.foodLevel[this.selectUpIndex]; var upgradeCoin = App_1.App.DataManager.upgradeFoodCoin[this.selectUpIndex][foodCurLevel]; if (App_1.App.DataManager.UserCoin < upgradeCoin) { App_1.App.Facade.popView(TipPanelMediator_1.default, TipPanel_1.default, "Not enough gold coins", false); //Not enough gold coins." 金币不足 } else { App_1.App.DataManager.foodLevel[this.selectUpIndex]++; App_1.App.DataManager.UserCoin -= upgradeCoin; // 保存到本地 App_1.App.LocalStorageUtil.setNumber(App_1.App.LocalStorageUtil.lst_Coin, App_1.App.DataManager.UserCoin); App_1.App.LocalStorageUtil.setJsonObj(App_1.App.LocalStorageUtil.list_foodLevel, App_1.App.DataManager.foodLevel); App_1.App.Facade.popView(TipPanelMediator_1.default, TipPanel_1.default, "update successfully", false); App_1.App.Facade.getModel(hallModel_1.default).updateCoinNumber(); for (var i = 0; i < 6; i++) { var level = App_1.App.DataManager.foodLevel[i]; this.shengjiTishi[i].active = false; if (level < App_1.App.DataManager.maxFoodLevel) { // 升级所需金币 this.LabelCoinNum[i].string = App_1.App.DataManager.upgradeFoodCoin[i][level] + ""; if (App_1.App.DataManager.UserCoin > App_1.App.DataManager.upgradeFoodCoin[i][level]) { //提示可以升级 this.shengjiTishi[i].active = true; } } else { this.btnList[i].interactable = false; this.LabelCoinNum[i].node.active = false; } } this.findUpGrade(); } }; __decorate([ property(cc.Label) ], NodeFood.prototype, "labelExp", void 0); __decorate([ property([cc.SpriteFrame]) ], NodeFood.prototype, "foodSpriteFrame", void 0); __decorate([ property(cc.Sprite) ], NodeFood.prototype, "selectSprite", void 0); __decorate([ property(cc.Label) ], NodeFood.prototype, "labelCurSoldPrice", void 0); __decorate([ property(cc.Label) ], NodeFood.prototype, "labelNexSoldPrice", void 0); __decorate([ property(cc.Button) ], NodeFood.prototype, "btnUpgrade", void 0); NodeFood = __decorate([ ccclass ], NodeFood); return NodeFood; }(cc.Component)); exports.default = NodeFood; cc._RF.pop();