LevelLayer.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. const { ccclass, property } = _decorator;
  10. @ccclass('LevelLayer')
  11. export class LevelLayer extends BasePanel {
  12. start() {
  13. this.GetGameObject("lock1").active = Data.user.lv < ITEM_MAGENT_LV;
  14. this.GetGameObject("icon1").active = Data.user.lv >= ITEM_MAGENT_LV;
  15. this.GetGameObject("lock2").active = Data.user.lv < ITEM_TIME_LV;
  16. this.GetGameObject("icon2").active = Data.user.lv >= ITEM_TIME_LV;
  17. this.SetText("lbl_item_magent_lv", ITEM_MAGENT_LV + "级解锁");
  18. this.SetText("lbl_item_time_lv", ITEM_TIME_LV + "级解锁");
  19. if (Data.user.magnet > 0) {
  20. this.SetText("lbl_item1_num", Data.user.magnet + "");
  21. }
  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. }
  28. else {
  29. this.SetText("lbl_item2_num", "+");
  30. }
  31. this.SetText("lbl_lvv", "关卡" + Data.user.lv);
  32. }
  33. onBtnClicked(event: any, customEventData: any) {
  34. audioMgr.playOneShot(GameConst.audios.btnclick);
  35. var btnName = event.target.name;
  36. switch (btnName) {
  37. case "btn_close":
  38. this.close();
  39. break;
  40. case "btn_item_1":
  41. if (Data.user.lv < ITEM_MAGENT_LV) return;
  42. if (Data.user.magnet == 0) {
  43. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  44. com.setItemType(ITEM_TYPE.Magnet);
  45. })
  46. this.close();
  47. }
  48. else {
  49. this.GetGameObject("choose_item1").active = !this.GetGameObject("choose_item1").active;
  50. }
  51. break
  52. case "btn_item_2":
  53. if (Data.user.lv < ITEM_TIME_LV) return;
  54. if (Data.user.time == 0) {
  55. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  56. com.setItemType(ITEM_TYPE.Time);
  57. })
  58. this.close();
  59. }
  60. else {
  61. this.GetGameObject("choose_item2").active = !this.GetGameObject("choose_item2").active;
  62. }
  63. break;
  64. case "btn_play":
  65. Data.user.useMagnet = this.GetGameObject("choose_item1").active;
  66. Data.user.useTime = this.GetGameObject("choose_item2").active;
  67. this.close();
  68. Main.Instance().play();
  69. break;
  70. case "btn_back":
  71. this.close();
  72. break;
  73. }
  74. }
  75. }