BuyItemLayer.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { _decorator, Component, Node } from 'cc';
  2. import BasePanel from '../core/component/BasePanel';
  3. import { audioMgr } from '../core/manager/AudioManager';
  4. import Data from '../core/manager/Data';
  5. import WindowManager from '../core/manager/WindowManager';
  6. import MsgHints from '../core/utils/MsgHints';
  7. import { Main } from '../game/Main';
  8. import { ITEM_TYPE, GameConst } from '../core/common/GameConst';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('BuyItemLayer')
  11. export class BuyItemLayer extends BasePanel {
  12. private type: ITEM_TYPE;
  13. setItemType(type: ITEM_TYPE) {
  14. this.type = type;
  15. this.GetGameObject("Magnet").active = type == ITEM_TYPE.Magnet;
  16. this.GetGameObject("Hint").active = type == ITEM_TYPE.Hint;
  17. this.GetGameObject("Frozen").active = type == ITEM_TYPE.Frozen;
  18. this.GetGameObject("Time").active = type == ITEM_TYPE.Time;
  19. this.SetText("lbl_name", GameConst.getItemName(type))
  20. Main.I._GameUI.pasue = true;
  21. }
  22. onDestroy() {
  23. super.onDestroy();
  24. Main.I._GameUI.pasue = false;
  25. }
  26. onBtnClicked(event: any, customEventData: any) {
  27. audioMgr.playOneShot(GameConst.audios.btnclick);
  28. var btnName = event.target.name;
  29. switch (btnName) {
  30. case "btn_close":
  31. this.close();
  32. break;
  33. case "btn_buy":
  34. if (Data.user.coin < 90) {
  35. WindowManager.ins.open("BuyCoinLayer");
  36. }
  37. else {
  38. MsgHints.show("购买成功!");
  39. Data.user.coin -= 90;
  40. Data.user.addItem(this.type, 3);
  41. Data.save();
  42. this.close();
  43. }
  44. break;
  45. }
  46. }
  47. }