ShelveLocker.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { _decorator, Button, Component, Label, Node, Sprite, tween, UIOpacity, v3 } from 'cc';
  2. import { GameMgr } from '../manager/GameMgr';
  3. import { EventMgr } from '../manager/EventMgr';
  4. import { EventType } from '../enum/EventType';
  5. import { ArrayUtil } from '../util/ArrayUtil';
  6. import { UIMgr } from '../manager/UIMgr';
  7. import { UI } from '../enum/UI';
  8. import { ResMgr } from '../manager/ResMgr';
  9. import { Bundle } from '../enum/Bundle';
  10. import { AdMgr } from '../manager/AdMgr';
  11. const { ccclass, property } = _decorator;
  12. @ccclass('Game/ShelveLocker')
  13. export class ShelveLocker extends Component {
  14. @property(Node)
  15. private lbBg: Node = null
  16. @property(Label)
  17. private lbCnt: Label = null
  18. @property(Sprite)
  19. private glass: Sprite = null
  20. // @property(Button)
  21. // private btnUnlock: Button = null
  22. @property(Node)
  23. private chain: Node = null
  24. private unlockCnt: number = 0
  25. public get UnlockCnt(): number {
  26. return this.unlockCnt
  27. }
  28. public set UnlockCnt(v: number) {
  29. this.unlockCnt = Math.max(0, v)
  30. this.lbCnt.string = `${v}`
  31. const spfName: string = this.unlockCnt === 1 ? 'bl2' : 'bl1'
  32. this.glass.spriteFrame = ResMgr.getSpriteFrame(Bundle.Game, spfName, 'image/')
  33. if (this.unlockCnt > 0) return
  34. // this.btnUnlock.interactable = false
  35. this.lbBg.active = false
  36. this.lbCnt.node.active = false
  37. this.glass.node.active = false
  38. // tween(this.btnUnlock.node).by(0.5, { position: v3(0, 50, 0) }).start()
  39. // const btnOpacity: UIOpacity = this.btnUnlock.addComponent(UIOpacity)
  40. // tween(btnOpacity).to(0.5, { opacity: 0 }).start()
  41. tween(this.chain).by(0.5, { position: v3(0, -50, 0) }).start()
  42. const chainOpacity: UIOpacity = this.chain.addComponent(UIOpacity)
  43. tween(chainOpacity).to(0.5, { opacity: 0 }).start()
  44. this.scheduleOnce(() => {
  45. this.node.destroy()
  46. }, 0.5)
  47. }
  48. protected onLoad(): void {
  49. this.lbCnt = this.getComponentInChildren(Label)
  50. this.glass = this.node.getChildByName('Glass').getComponent(Sprite)
  51. GameMgr.shelveLockerArr.push(this)
  52. EventMgr.on(EventType.MergeGoods, this.onMergeGoods, this)
  53. }
  54. protected onDestroy(): void {
  55. ArrayUtil.remove(GameMgr.shelveLockerArr, this)
  56. EventMgr.off(EventType.MergeGoods, this.onMergeGoods, this)
  57. }
  58. protected onMergeGoods(): void {
  59. if (this !== GameMgr.shelveLockerArr[0]) return
  60. this.UnlockCnt--
  61. }
  62. protected onBtnUnlockClick(): void {
  63. // this.UnlockCnt = 0
  64. }
  65. }