LevelLayer.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, director } from 'cc';
  2. import { BuyItemLayer } from './BuyItemLayer';
  3. import BasePanel from '../core/component/BasePanel';
  4. import { audioMgr } from '../core/manager/AudioManager';
  5. import Data from '../core/manager/Data';
  6. import WindowManager from '../core/manager/WindowManager';
  7. import { Main } from '../game/Main';
  8. import { ITEM_MAGENT_LV, ITEM_TIME_LV, GameConst, ITEM_TYPE } from '../core/common/GameConst';
  9. import i18n from '../core/i18n/runtime-scripts/LanguageData';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('LevelLayer')
  12. export class LevelLayer extends BasePanel {
  13. start() {
  14. this.GetGameObject("lock1").active = Data.user.lv < ITEM_MAGENT_LV;
  15. this.GetGameObject("icon1").active = Data.user.lv >= ITEM_MAGENT_LV;
  16. this.GetGameObject("lock2").active = Data.user.lv < ITEM_TIME_LV;
  17. this.GetGameObject("icon2").active = Data.user.lv >= ITEM_TIME_LV;
  18. this.SetText("lbl_item_magent_lv", i18n("main.%{value}级解锁", { value: ITEM_MAGENT_LV}));
  19. this.SetText("lbl_item_time_lv", i18n("main.%{value}级解锁", { value: ITEM_TIME_LV}));
  20. if (Data.user.magnet > 0) {
  21. this.SetText("lbl_item1_num", Data.user.magnet + "");
  22. }else {
  23. this.SetText("lbl_item1_num", "+");
  24. }
  25. if (Data.user.time > 0) {
  26. this.SetText("lbl_item2_num", Data.user.time + "");
  27. }else {
  28. this.SetText("lbl_item2_num", "+");
  29. }
  30. this.SetText("lbl_lvv", i18n("main.LV:%{value}", { value: Data.user.lv}));
  31. }
  32. onBtnClicked(event: any, customEventData: any) {
  33. audioMgr.playOneShot(GameConst.audios.btnclick);
  34. var btnName = event.target.name;
  35. switch (btnName) {
  36. case "btn_close":
  37. this.close();
  38. break;
  39. case "btn_item_1":
  40. if (Data.user.lv < ITEM_MAGENT_LV) return;
  41. if (Data.user.magnet == 0) {
  42. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  43. com.setItemType(ITEM_TYPE.Magnet);
  44. })
  45. this.close();
  46. }
  47. else {
  48. this.GetGameObject("choose_item1").active = !this.GetGameObject("choose_item1").active;
  49. }
  50. break
  51. case "btn_item_2":
  52. if (Data.user.lv < ITEM_TIME_LV) return;
  53. if (Data.user.time == 0) {
  54. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  55. com.setItemType(ITEM_TYPE.Time);
  56. })
  57. this.close();
  58. }
  59. else {
  60. this.GetGameObject("choose_item2").active = !this.GetGameObject("choose_item2").active;
  61. }
  62. break;
  63. case "btn_play":
  64. Data.user.useMagnet = this.GetGameObject("choose_item1").active;
  65. Data.user.useTime = this.GetGameObject("choose_item2").active;
  66. this.close();
  67. Main.I.play();
  68. break;
  69. case "btn_back":
  70. this.close();
  71. break;
  72. }
  73. }
  74. }