NodeKitchen.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { App } from "../../Manager/App";
  2. import hallModel from "../../model/hallModel";
  3. import TipPanel from "../tipPanel/TipPanel";
  4. import TipPanelMediator from "../tipPanel/TipPanelMediator";
  5. const {ccclass, property} = cc._decorator;
  6. @ccclass
  7. export default class NodeKitchen extends cc.Component {
  8. @property(cc.Label)
  9. labelExp: cc.Label = null;
  10. btnList: cc.Button[] = [];
  11. LabelCoinNum: cc.Label[] = [];
  12. shengjiTishi: cc.Node[] = [];
  13. @property([cc.SpriteFrame])
  14. kitchenSpriteFrame: cc.SpriteFrame[] = [];
  15. private kitchenName: string[] = [];
  16. @property(cc.Sprite)
  17. selectSprite: cc.Sprite = null;
  18. @property(cc.Label)
  19. labelCurCount: cc.Label = null;
  20. @property(cc.Label)
  21. labelNextCount: cc.Label = null;
  22. private selectUpIndex = -1;
  23. @property(cc.Button)
  24. btnUpgrade: cc.Button = null;
  25. onLoad () {
  26. for (let i = 0; i < 3; i++) {
  27. this.btnList[i] = this.node.getChildByName("btnKitchen" + i).getComponent(cc.Button);
  28. this.btnList[i].node.on("click", this.btnClickCallBack.bind(this, i), this);
  29. this.LabelCoinNum[i] = this.btnList[i].node.getChildByName("LabelCoinNum").getComponent(cc.Label);
  30. this.shengjiTishi[i] = this.btnList[i].node.getChildByName("tip_shenji");
  31. this.shengjiTishi[i].active = false;
  32. let level = App.DataManager.kinchenLevel[i];
  33. if(level < App.DataManager.maxKitchenLevel){
  34. // 升级所需金币
  35. this.LabelCoinNum[i].string = App.DataManager.upgradeKitchenCoin[i][level] + "";
  36. if(App.DataManager.UserCoin > App.DataManager.upgradeKitchenCoin[i][level]){
  37. // 提示可以升级
  38. this.shengjiTishi[i].active = true;
  39. }
  40. }
  41. else{
  42. this.btnList[i].interactable = false;
  43. this.LabelCoinNum[i].node.active = false;
  44. }
  45. }
  46. this.btnUpgrade.node.on("click", this.clickBtnUpgrade.bind(this), this);
  47. // this.kitchenName = ["盘子", "铁板", "饮料机"];
  48. this.kitchenName = ["plate", "hot plate", "juicer"];
  49. }
  50. start() {
  51. this.findUpGrade();
  52. }
  53. findUpGrade(){
  54. this.selectUpIndex = -1;
  55. for (let i = App.DataManager.kinchenLevel.length - 1; i >= 0; i--) {
  56. let KitchenCurLevel = App.DataManager.kinchenLevel[i];
  57. if(KitchenCurLevel == App.DataManager.maxKitchenLevel){
  58. this.btnList[i].interactable = false;
  59. this.LabelCoinNum[i].node.active = false;
  60. }
  61. else{
  62. this.selectUpIndex = i;
  63. this.LabelCoinNum[i].string = App.DataManager.upgradeKitchenCoin[i][KitchenCurLevel] + "";
  64. }
  65. }
  66. console.log("aaa--------this.selectUpIndex----------", this.selectUpIndex);
  67. this.btnClickCallBack(this.selectUpIndex);
  68. }
  69. btnClickCallBack(index: number){
  70. if(index < 0){
  71. return;
  72. }
  73. this.selectUpIndex = index;
  74. this.labelExp.string = this.kitchenName[index];
  75. this.selectSprite.spriteFrame = this.kitchenSpriteFrame[index];
  76. let KitchenCurLevel = App.DataManager.kinchenLevel[index];
  77. this.labelCurCount.string = App.DataManager.kitchenNum[index][KitchenCurLevel] + "";
  78. this.labelNextCount.string = App.DataManager.kitchenNum[index][KitchenCurLevel + 1] + "";
  79. }
  80. clickBtnUpgrade(){
  81. if(this.selectUpIndex < 0){
  82. App.Facade.popView(TipPanelMediator, TipPanel, "It's the highest level", false);
  83. return;
  84. }
  85. let KitchenCurLevel = App.DataManager.kinchenLevel[this.selectUpIndex];
  86. let upgradeCoin = App.DataManager.upgradeKitchenCoin[this.selectUpIndex][KitchenCurLevel];
  87. if(App.DataManager.UserCoin < upgradeCoin){
  88. App.Facade.popView(TipPanelMediator, TipPanel, "Not enough gold coins", false);
  89. }
  90. else{
  91. App.DataManager.kinchenLevel[this.selectUpIndex]++;
  92. App.DataManager.UserCoin -= upgradeCoin;
  93. // 保存到本地
  94. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, App.DataManager.UserCoin);
  95. App.LocalStorageUtil.setJsonObj(App.LocalStorageUtil.list_kitchenLevel, App.DataManager.kinchenLevel);
  96. App.Facade.popView(TipPanelMediator, TipPanel, "update successfully", false);
  97. App.Facade.getModel(hallModel).updateCoinNumber();
  98. for (let i = 0; i < 3; i++) {
  99. let level = App.DataManager.kinchenLevel[i];
  100. this.shengjiTishi[i].active = false;
  101. if(level < App.DataManager.maxKitchenLevel){
  102. // 升级所需金币
  103. this.LabelCoinNum[i].string = App.DataManager.upgradeKitchenCoin[i][level] + "";
  104. if(App.DataManager.UserCoin > App.DataManager.upgradeKitchenCoin[i][level]){
  105. // 提示可以升级
  106. this.shengjiTishi[i].active = true;
  107. }
  108. }
  109. else{
  110. this.btnList[i].interactable = false;
  111. this.LabelCoinNum[i].node.active = false;
  112. }
  113. }
  114. this.findUpGrade();
  115. }
  116. }
  117. // update (dt) {}
  118. }