UI_NeedCoin.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { _decorator, Component, Node, ProgressBar, Tween, tween } from 'cc';
  2. import { UI_Dialog } from '../UI_Dialog';
  3. import { aa, UIController, UIElement } from 'db://assets/scripts/aa';
  4. import { rootMgr } from '../../../scene/RootMgr';
  5. import { Update } from 'db://assets/scripts/uitl/baseData/BaseData/DailyUpdates';
  6. import { ItemKey, ItemService } from '../../../data/Item/ItemService';
  7. import { Notify } from '../../../scene/GameConfing';
  8. const { ccclass, property } = _decorator;
  9. @UIController({ bundleName: 'dialog', path: 'needCoin/needCoin' })
  10. export class UI_NeedCoin extends UI_Dialog {
  11. @UIElement(Node)
  12. adBtn: Node
  13. // @UIElement(Node)
  14. // goMainBtn: Node
  15. @UIElement(ProgressBar)
  16. progressBar: ProgressBar
  17. @UIElement(Node)
  18. yuan: Node
  19. start(): void {
  20. this.adBtn.on(Node.EventType.TOUCH_END, this.addCoin, this)
  21. // this.goMainBtn.on(Node.EventType.TOUCH_END, this.goMain, this)
  22. this.reflash()
  23. }
  24. reflash(my?: number) {
  25. let rewardCoinTimes = rootMgr.dataControl.getCompent(Update).getDaly('rewardCoinTimes')
  26. if (my) {
  27. rewardCoinTimes = my
  28. }
  29. // 金币领取的刷新
  30. let process = rewardCoinTimes
  31. this.yuan.children.forEach((it, index) => {
  32. it.active = index < process
  33. })
  34. this.progressBar.progress = process / 3
  35. }
  36. async addCoin() {
  37. let updata = rootMgr.dataControl.getCompent(Update)
  38. let rewardCoinTimes = updata.getDaly('rewardCoinTimes')
  39. let boolean = await aa.sdk.playRewardAd('金币不足'+rewardCoinTimes)
  40. if (boolean) {
  41. this.reflash()
  42. let updata = rootMgr.dataControl.getCompent(Update)
  43. let rewardCoinTimes = updata.getDaly('rewardCoinTimes')
  44. let reward = rewardCoin[rewardCoinTimes % rewardCoin.length]
  45. updata.setDaly('rewardCoinTimes', (rewardCoinTimes + 1) % rewardCoin.length)
  46. // 播放动画
  47. rootMgr.dataControl.getCompent(ItemService).getRewarded(reward.key, reward.v)
  48. rootMgr.game.evt.emit('save')
  49. Notify("金币获取成功")
  50. // let start = Math.min(rewardCoinTimes, rewardCoin.length) / rewardCoin.length
  51. let end = Math.min(rewardCoinTimes + 1, rewardCoin.length)
  52. Tween.stopAllByTarget(this.progressBar)
  53. tween(this.progressBar).to(.2, { progress: end / rewardCoin.length }).call(() => {
  54. this.reflash(end)
  55. }).start()
  56. }
  57. }
  58. goMain() {
  59. }
  60. }
  61. export const rewardCoin = [{ v: 800, key: ItemKey.coin }, { v: 1600, key: ItemKey.coin }, { v: 2500, key: ItemKey.coin }]