GameSpeedUI.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /** @format */
  2. import {UI} from '../enums/UI'
  3. import {BaseUI} from './BaseUI'
  4. import {Data, Mgr} from '../GameControl'
  5. import {ccUtils} from '../utils/ccUtils'
  6. import {observer, render, node, label, editBox, list} from '../mobx/observer'
  7. import {msgCmd} from '../proto/msg_cmd'
  8. import {AD_ID, DIS_ID, LOCAL} from '../enums/Enum'
  9. import {i18nLabel} from '../uiutils/i18nLabel'
  10. import {DataConfig} from '../config/DataConfig'
  11. import {speedUpBuy, speedUpBuyRsp} from '../proto/game'
  12. const {ccclass, property} = cc._decorator
  13. @ccclass
  14. @observer
  15. export class GameSpeedUI extends BaseUI {
  16. onShow(args, fromUI: number) {
  17. Mgr.net.add(msgCmd.cmd_speed_up_buy_rsp, this, this.speedUpBuyRsp)
  18. let timeLb = cc.find('timeLb', this.node).getComponent(i18nLabel)
  19. timeLb.setParamByIndex(Math.floor(DataConfig[DIS_ID.gameSpeed].data2 / 60).toString(), 0)
  20. ccUtils.setLabel(DataConfig[DIS_ID.gameSpeed].data3.toString(), this.node, 'btn_yellow/lb')
  21. }
  22. onOpenAniOver() {
  23. //cc.director.pause()
  24. }
  25. onHide(): any {
  26. Mgr.event.removeAll(this)
  27. Mgr.ui.callOnShow(UI.GameUI, {isStop: false})
  28. //cc.director.resume()
  29. }
  30. speedUpBuyRsp(rsp: speedUpBuyRsp) {
  31. Data.game.gameSpeed = 2
  32. Data.game.speedUpTime = rsp.time
  33. this.hide()
  34. }
  35. //UI或者其他函数=======================================
  36. //网络事件=======================================
  37. // onXXXRsp() {}
  38. //触发事件=======================================
  39. // @render
  40. // showRender() {}
  41. // 点击事件=======================================
  42. onFreeClick() {
  43. Mgr.platform.playVideoAD(AD_ID.gamespeed, () => {
  44. let data = speedUpBuy.create()
  45. data.free = true
  46. Mgr.net.send(msgCmd.cmd_speed_up_buy, data)
  47. })
  48. }
  49. onBuyClick() {
  50. let data = speedUpBuy.create()
  51. data.free = false
  52. Mgr.net.send(msgCmd.cmd_speed_up_buy, data)
  53. }
  54. }