GameResultUI.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. ccUtils.playAni(isWin ? 'win' : 'lose', 0, isWin ? this.victory : this.lose)
  46. this.btnStrongNode.active = !isWin
  47. this.rewards = args.rewardsNty ? Mgr.goods.getGoodsListByRewardNty(args.rewardsNty) : []
  48. this.goodsList.numItems = this.rewards.length
  49. this.rewardsNode.active = this.rewards.length > 0
  50. this.timeNode.active = !this.rewardsNode.active
  51. ccUtils.setLabel(
  52. Mgr.i18n.getTimeLabel(Data.main.serverTime - args.startTime, LANGUAGE_TYPE.m, LANGUAGE_TYPE.s),
  53. this.timeNode,
  54. 'time',
  55. )
  56. this.btnDouble.active = GAME_TYPE.normal == Data.game.gameType && isWin
  57. let doubleOpen = Mgr.global.checkModOpen(MOD.doubleADGameReward)
  58. cc.find('adTip', this.node).active = this.btnDouble.active && doubleOpen
  59. cc.find('lock', this.btnDouble).active = !doubleOpen
  60. ccUtils.setAllGray(!doubleOpen, this.btnDouble)
  61. if (!doubleOpen) {
  62. ccUtils.setLabel(Mgr.global.getModLockTip(MOD.doubleADGameReward), this.btnDouble, 'lock/lb_notGray')
  63. }
  64. cc.find('guide', this.node).active = Mgr.global.tryShowUserGuide(['2013_1'])
  65. }
  66. onHide(): any {
  67. Mgr.event.removeAll(this)
  68. }
  69. //UI或者其他函数=======================================
  70. initGoodsItem(node: cc.Node, index: number) {
  71. Mgr.goods.initGoods([this.rewards[index]], [cc.find('goods', node)], this)
  72. }
  73. // 点击事件=======================================
  74. onStrongClick() {
  75. Mgr.ui.closeAll()
  76. Mgr.ui.show(UI.MainUI)
  77. Mgr.ui.show(UI.TeamUI)
  78. }
  79. onSureClick() {
  80. if (Data.game.gameType == GAME_TYPE.normal) {
  81. Mgr.net.send(msgCmd.cmd_role_get_data)
  82. } else {
  83. Mgr.game.exitGame(this.result)
  84. }
  85. }
  86. onDoubleClick() {
  87. Mgr.platform.playVideoAD(AD_ID.firstpass, () => {
  88. Mgr.net.send(msgCmd.cmd_adventure_ad_award)
  89. })
  90. }
  91. onDoubleRsp(data: adventureAdAwardRsp, rewardsNty: IRewardNty) {
  92. Mgr.ui.showReward(rewardsNty)
  93. this.btnDouble.active = false
  94. }
  95. onRoleGetDataRsp(data: roleGetDataRsp) {
  96. Data.user.level = data.level
  97. Data.user.exp = data.exp
  98. if (RanksLevelConfig[Data.user.level + 1] && data.exp >= RanksLevelConfig[Data.user.level + 1].exp) {
  99. Data.main.exitGame = true
  100. //返回主界面升级
  101. Data.main.exitGameLv = true
  102. Mgr.ui.closeAll()
  103. Mgr.ui.show(UI.MainUI)
  104. } else {
  105. Mgr.game.exitGame(this.result)
  106. }
  107. }
  108. }