GameResultUI.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 {list, node, observer} from '../mobx/observer'
  7. import List from '../uiutils/List'
  8. import {idNum} from '../proto/typedef'
  9. import {IGameResult, IRewardNty, IStageChoose} from '../interface/UIInterface'
  10. import {AD_ID, GAME_TYPE, LANGUAGE_TYPE, LOCAL, MOD} from '../enums/Enum'
  11. import {MSG} from '../enums/MSG'
  12. import {msgCmd} from '../proto/msg_cmd'
  13. import {adventureAdAward, adventureAdAwardRsp, dailyDungeonsSweep, roleGetDataRsp} from '../proto/game'
  14. import {SOUND} from '../enums/Sound'
  15. import {RanksLevelConfig} from '../config/RanksLevelConfig'
  16. const {ccclass, property} = cc._decorator
  17. @ccclass
  18. @observer
  19. export class GameResultUI extends BaseUI {
  20. @list('rewards/goodsList')
  21. goodsList: List
  22. @node('victory')
  23. victory: cc.Node
  24. @node('lose')
  25. lose: cc.Node
  26. @node('btns/btn_strong')
  27. btnStrongNode: cc.Node
  28. @node('rewards')
  29. rewardsNode: cc.Node
  30. @node('time')
  31. timeNode: cc.Node
  32. @node('btns/btn_double')
  33. btnDouble: cc.Node
  34. rewards: idNum[]
  35. result: IGameResult
  36. onShow(args: IGameResult, fromUI: number) {
  37. Mgr.net.add(msgCmd.cmd_adventure_ad_award_rsp, this, this.onDoubleRsp)
  38. Mgr.net.add(msgCmd.cmd_role_get_data_rsp, this, this.onRoleGetDataRsp)
  39. this.result = args
  40. let isWin = args.isWin
  41. Mgr.audio.stopBGM()
  42. Mgr.audio.playSFX(isWin ? SOUND.win : SOUND.lose)
  43. this.victory.active = isWin
  44. this.lose.active = !isWin
  45. //this.btnStrongNode.active = !isWin
  46. this.rewards = args.rewardsNty ? Mgr.goods.getGoodsListByRewardNty(args.rewardsNty) : []
  47. this.goodsList.numItems = this.rewards.length
  48. this.rewardsNode.active = this.rewards.length > 0
  49. // this.timeNode.active = !this.rewardsNode.active
  50. // ccUtils.setLabel(
  51. // Mgr.i18n.getTimeLabel(Data.main.serverTime - args.startTime, LANGUAGE_TYPE.m, LANGUAGE_TYPE.s),
  52. // this.timeNode,
  53. // 'time',
  54. // )
  55. // this.btnDouble.active = GAME_TYPE.normal == Data.game.gameType && isWin
  56. // let doubleOpen = Mgr.global.checkModOpen(MOD.doubleADGameReward)
  57. // cc.find('adTip', this.node).active = this.btnDouble.active && doubleOpen
  58. // cc.find('lock', this.btnDouble).active = !doubleOpen
  59. // ccUtils.setAllGray(!doubleOpen, this.btnDouble)
  60. // if (!doubleOpen) {
  61. // ccUtils.setLabel(Mgr.global.getModLockTip(MOD.doubleADGameReward), this.btnDouble, 'lock/lb_notGray')
  62. // }
  63. // cc.find('guide', this.node).active = Mgr.global.tryShowUserGuide(['2013_1'])
  64. }
  65. onHide(): any {
  66. Mgr.event.removeAll(this)
  67. }
  68. //UI或者其他函数=======================================
  69. initGoodsItem(node: cc.Node, index: number) {
  70. Mgr.goods.initGoods([this.rewards[index]], [cc.find('goods', node)], this)
  71. }
  72. // 点击事件=======================================
  73. onStrongClick() {
  74. Mgr.ui.closeAll()
  75. Mgr.ui.show(UI.MainUI)
  76. Mgr.ui.show(UI.TeamUI)
  77. }
  78. onSureClick() {
  79. if (Data.game.gameType == GAME_TYPE.normal) {
  80. Mgr.net.send(msgCmd.cmd_role_get_data)
  81. } else {
  82. Mgr.game.exitGame(this.result)
  83. }
  84. }
  85. onDoubleClick() {
  86. Mgr.platform.playVideoAD(AD_ID.firstpass, () => {
  87. Mgr.net.send(msgCmd.cmd_adventure_ad_award)
  88. })
  89. }
  90. onDoubleRsp(data: adventureAdAwardRsp, rewardsNty: IRewardNty) {
  91. Mgr.ui.showReward(rewardsNty)
  92. this.btnDouble.active = false
  93. }
  94. onRoleGetDataRsp(data: roleGetDataRsp) {
  95. Data.user.level = data.level
  96. Data.user.exp = data.exp
  97. if (RanksLevelConfig[Data.user.level + 1] && data.exp >= RanksLevelConfig[Data.user.level + 1].exp) {
  98. Data.main.exitGame = true
  99. //返回主界面升级
  100. Data.main.exitGameLv = true
  101. Mgr.ui.closeAll()
  102. Mgr.ui.show(UI.MainUI)
  103. } else {
  104. Mgr.game.exitGame(this.result)
  105. }
  106. }
  107. }