LevelLayer.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { _decorator, director } from 'cc';
  2. import { ITEM_MAGENT_LV, ITEM_TIME_LV, ITEM_TYPE } from '../../../core/common/GameConst';
  3. import BasePanel from '../../../core/component/BasePanel';
  4. import Data from '../../../core/manager/Data';
  5. import WindowManager from '../../../core/manager/WindowManager';
  6. import { Main } from '../Main';
  7. import { BuyItemLayer } from './BuyItemLayer';
  8. import audioManager from 'db://assets/manager/audioManager';
  9. import { constants } from 'db://assets/data/constants';
  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", ITEM_MAGENT_LV + "级解锁");
  19. this.SetText("lbl_item_time_lv", ITEM_TIME_LV + "级解锁");
  20. if (Data.user.magnet > 0) {
  21. this.SetText("lbl_item1_num", Data.user.magnet + "");
  22. }
  23. else {
  24. this.SetText("lbl_item1_num", "+");
  25. }
  26. if (Data.user.time > 0) {
  27. this.SetText("lbl_item2_num", Data.user.time + "");
  28. }
  29. else {
  30. this.SetText("lbl_item2_num", "+");
  31. }
  32. this.SetText("lbl_lvv", "关卡" + Data.user.lv);
  33. }
  34. onBtnClicked(event: any, customEventData: any) {
  35. audioManager.playOneShot(constants.audios.btnclick);
  36. var btnName = event.target.name;
  37. switch (btnName) {
  38. case "btn_close":
  39. this.close();
  40. break;
  41. case "btn_item_1":
  42. if (Data.user.lv < ITEM_MAGENT_LV) return;
  43. if (Data.user.magnet == 0) {
  44. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  45. com.setItemType(ITEM_TYPE.Magnet);
  46. })
  47. this.close();
  48. }
  49. else {
  50. this.GetGameObject("choose_item1").active = !this.GetGameObject("choose_item1").active;
  51. }
  52. break
  53. case "btn_item_2":
  54. if (Data.user.lv < ITEM_TIME_LV) return;
  55. if (Data.user.time == 0) {
  56. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  57. com.setItemType(ITEM_TYPE.Time);
  58. })
  59. this.close();
  60. }
  61. else {
  62. this.GetGameObject("choose_item2").active = !this.GetGameObject("choose_item2").active;
  63. }
  64. break;
  65. case "btn_play":
  66. Data.user.useMagnet = this.GetGameObject("choose_item1").active;
  67. Data.user.useTime = this.GetGameObject("choose_item2").active;
  68. this.close();
  69. Main.Instance().play();
  70. break;
  71. case "btn_back":
  72. this.close();
  73. break;
  74. }
  75. }
  76. }