LevelLayer.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { _decorator, Material, Sprite} 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. @property({type: Material,tooltip: "灰色材质"})
  14. public garyMaterial: Material = null!;
  15. start() {
  16. this.GetGameObject("lock1").active = Data.user.lv < ITEM_MAGENT_LV;
  17. this.GetGameObject("btn_item_1").getComponent(Sprite).customMaterial = Data.user.lv < ITEM_MAGENT_LV ? this.garyMaterial : null;
  18. this.GetGameObject("icon1").active = Data.user.lv >= ITEM_MAGENT_LV;
  19. this.GetGameObject("lock2").active = Data.user.lv < ITEM_TIME_LV;
  20. this.GetGameObject("btn_item_2").getComponent(Sprite).customMaterial = Data.user.lv < ITEM_TIME_LV ? this.garyMaterial : null;
  21. this.GetGameObject("icon2").active = Data.user.lv >= ITEM_TIME_LV;
  22. this.SetText("lbl_item_magent_lv", i18n("main.%{value}级解锁", { value: ITEM_MAGENT_LV}));
  23. this.SetText("lbl_item_time_lv", i18n("main.%{value}级解锁", { value: ITEM_TIME_LV}));
  24. if (Data.user.magnet > 0) {
  25. this.SetText("lbl_item1_num", Data.user.magnet + "");
  26. }else {
  27. this.SetText("lbl_item1_num", "+");
  28. }
  29. if (Data.user.time > 0) {
  30. this.SetText("lbl_item2_num", Data.user.time + "");
  31. }else {
  32. this.SetText("lbl_item2_num", "+");
  33. }
  34. this.SetText("lbl_lvv", i18n("main.LV:%{value}", { value: Data.user.lv}));
  35. }
  36. onBtnClicked(event: any, customEventData: any) {
  37. audioMgr.playOneShot(GameConst.audios.btnclick);
  38. var btnName = event.target.name;
  39. switch (btnName) {
  40. case "btn_close":
  41. this.close();
  42. break;
  43. case "btn_item_1":
  44. if (Data.user.lv < ITEM_MAGENT_LV) return;
  45. if (Data.user.magnet == 0) {
  46. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  47. com.setItemType(ITEM_TYPE.Magnet);
  48. })
  49. this.close();
  50. }
  51. else {
  52. this.GetGameObject("choose_item1").active = !this.GetGameObject("choose_item1").active;
  53. }
  54. break
  55. case "btn_item_2":
  56. if (Data.user.lv < ITEM_TIME_LV) return;
  57. if (Data.user.time == 0) {
  58. WindowManager.ins.open("BuyItemLayer").then((com: BuyItemLayer) => {
  59. com.setItemType(ITEM_TYPE.Time);
  60. })
  61. this.close();
  62. }
  63. else {
  64. this.GetGameObject("choose_item2").active = !this.GetGameObject("choose_item2").active;
  65. }
  66. break;
  67. case "btn_play":
  68. Data.user.useMagnet = this.GetGameObject("choose_item1").active;
  69. Data.user.useTime = this.GetGameObject("choose_item2").active;
  70. this.close();
  71. Main.I.play();
  72. break;
  73. case "btn_back":
  74. this.close();
  75. break;
  76. }
  77. }
  78. }