BuyItemLayer.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { _decorator, Component, Node, Sprite, spriteAssembler, SpriteFrame } 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. import i18n from '../core/i18n/runtime-scripts/LanguageData';
  10. import platformSystem from '../platform/platformSystem';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('BuyItemLayer')
  13. export class BuyItemLayer extends BasePanel {
  14. @property({type:Node,tooltip:"金币节点"})
  15. public gold_n: Node = null!;
  16. @property({type:Node,tooltip:"视频节点"})
  17. public video_n: Node = null!;
  18. private type: ITEM_TYPE;
  19. setItemType(type: ITEM_TYPE) {
  20. this.type = type;
  21. this.GetGameObject("Magnet").active = type == ITEM_TYPE.Magnet;
  22. this.GetGameObject("Hint").active = type == ITEM_TYPE.Hint;
  23. this.GetGameObject("Frozen").active = type == ITEM_TYPE.Frozen;
  24. this.GetGameObject("Time").active = type == ITEM_TYPE.Time;
  25. this.SetText("lbl_name", GameConst.getItemName(type))
  26. Main.I._GameUI.pasue = true;
  27. }
  28. onLoad(): void {
  29. if(Data.user.coin <= 0){
  30. this.gold_n.active = false;
  31. this.video_n.active = true;
  32. }else{
  33. this.gold_n.active = true;
  34. this.video_n.active = false;
  35. }
  36. }
  37. onDestroy() {
  38. super.onDestroy();
  39. Main.I._GameUI.pasue = false;
  40. }
  41. onBtnClicked(event: any, customEventData: any) {
  42. audioMgr.playOneShot(GameConst.audios.btnclick);
  43. var btnName = event.target.name;
  44. switch (btnName) {
  45. case "btn_close":
  46. this.close();
  47. break;
  48. case "btn_buy":
  49. if(Data.user.coin <= 0){
  50. platformSystem.platform.showRewardVideo((b) => {
  51. if(b){
  52. MsgHints.show(i18n("main.购买成功!"))
  53. Data.user.coin -= 90;
  54. Data.user.addItem(this.type, 3);
  55. Data.save();
  56. this.close();
  57. }
  58. })
  59. }else{
  60. if (Data.user.coin < 90) {
  61. WindowManager.ins.open("BuyCoinLayer");
  62. }else {
  63. MsgHints.show(i18n("main.购买成功!"))
  64. Data.user.coin -= 90;
  65. Data.user.addItem(this.type, 3);
  66. Data.save();
  67. this.close();
  68. }
  69. break;
  70. }
  71. }
  72. }
  73. }