UIWin.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { Widget, _decorator, Node, tween, v3, Label, Vec2, v2, math, Tween } from 'cc';
  2. import { GameMgr } from '../manager/GameMgr';
  3. import { AudioMgr } from '../manager/AudioMgr';
  4. import { CoinMgr } from '../manager/CoinMgr';
  5. import { ArrayUtil } from '../util/ArrayUtil';
  6. import { InputBlock } from '../misc/InputBlock';
  7. import { TimeMgr } from '../manager/TimeMgr';
  8. import { UI } from '../enum/UI';
  9. import { UIBase } from '../scriptBase/UIBase';
  10. import { CoinItem } from '../uiItem/CoinItem';
  11. import { Global } from '../Global';
  12. import { TransMgr } from '../manager/TransMgr';
  13. import { BYTEDANCE } from 'cc/env';
  14. import { ModeName } from '../enum/Mode';
  15. import { AdMgr } from '../manager/AdMgr';
  16. const { ccclass, property, requireComponent } = _decorator;
  17. @ccclass('UI/UIWin')
  18. @requireComponent(Widget)
  19. export class UIWin extends UIBase {
  20. private pointer: Node = null
  21. private lbCoin: Label = null
  22. private coinItem: CoinItem = null
  23. private coin: number = 0
  24. public set Coin(v: number) {
  25. this.coin = Math.max(v, 0)
  26. this.lbCoin.string = `x${this.coin}`
  27. }
  28. private multi: number = 1
  29. private readonly posArr: Vec2[] = [
  30. v2(-120, -74),
  31. v2(-72, 80),
  32. v2(-17, 29),
  33. v2(32, 86),
  34. v2(90, 120),
  35. ]
  36. private readonly multiArr: number[] = [2, 3, 5, 3, 4]
  37. private tw: Tween<Node> = null
  38. protected onLoad(): void {
  39. this.pointer = this.findNode('Pointer')
  40. this.lbCoin = this.findComp('LbCoin', Label)
  41. this.coinItem = this.findComp('CoinItem', CoinItem)
  42. }
  43. public onOpen(data?: unknown): void {
  44. AudioMgr.stopBgm()
  45. AudioMgr.playSfx('通关成功')
  46. GameMgr.passGame()
  47. this.coinItem.init(CoinMgr.CurCoin)
  48. GameMgr.Pause = true
  49. const duration: number = 0.75
  50. this.tw = tween(this.pointer).sequence(
  51. tween(this.pointer).to(duration, { position: v3(120, -25) }),
  52. tween(this.pointer).to(duration, { position: v3(-120, -25) })
  53. ).repeatForever().start()
  54. this.Coin = Global.Normal_Level_Coin_Default_Cnt + (GameMgr.CurLevel - 1) * Global.Normal_Level_Coin_Add_Cnt
  55. CoinMgr.CurCoin += this.coin
  56. }
  57. public onClose(data?: unknown): void {
  58. GameMgr.Pause = false
  59. InputBlock.Active = false
  60. }
  61. protected async onBtnMultiClick() {
  62. const onSucc = async () => {
  63. this.tw.stop()
  64. const idx: number = ArrayUtil.pickItem([0, 0, 0, 0, 0, 1, 2, 3])
  65. this.multi = this.multiArr[idx]
  66. const posRange: Vec2 = this.posArr[idx]
  67. const posX: number = math.randomRangeInt(posRange.x, posRange.y)
  68. this.pointer.setPosition(posX, this.pointer.position.y)
  69. const extraCoin: number = (this.multi - 1) * this.coin
  70. this.Coin = this.multi * this.coin
  71. CoinMgr.CurCoin += extraCoin
  72. this.coinItem.updateCoin(CoinMgr.CurCoin)
  73. InputBlock.Active = true
  74. await TimeMgr.delay(2)
  75. await TransMgr.Inst.fadeIn()
  76. GameMgr.startGame()
  77. this.close()
  78. TransMgr.Inst.fadeOut()
  79. }
  80. AdMgr.showRewardedVideo(onSucc)
  81. }
  82. protected async onBtnNextClick() {
  83. this.coinItem.updateCoin(CoinMgr.CurCoin)
  84. InputBlock.Active = true
  85. await TimeMgr.delay(2)
  86. await TransMgr.Inst.fadeIn()
  87. GameMgr.startGame()
  88. this.close()
  89. TransMgr.Inst.fadeOut()
  90. }
  91. protected async onBtnCloseClick() {
  92. await TransMgr.Inst.fadeIn()
  93. this.close()
  94. GameMgr.quitGame()
  95. this.open(UI.Main)
  96. TransMgr.Inst.fadeOut()
  97. }
  98. }