LoadingUI.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /** @format */
  2. import {UI} from '../../enums/UI'
  3. import {BaseUI} from '../BaseUI'
  4. import {Data, GameControl, 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 {ILoading} from '../../interface/UIInterface'
  9. import {LANGUAGE_TYPE} from '../../enums/Enum'
  10. const {ccclass, property} = cc._decorator
  11. @ccclass
  12. @observer
  13. export class LoadingUI extends BaseUI {
  14. @label('lb')
  15. public tip: cc.Label
  16. @node('ani')
  17. public aniNode: cc.Node
  18. private dot = ''
  19. private str = ''
  20. public onShow(args: ILoading, fromUI: number) {
  21. this.unscheduleAllCallbacks()
  22. this.node.opacity = 0
  23. if (args.isDelay) {
  24. this.scheduleOnce(() => {
  25. if (cc.isValid(this.node)) {
  26. this.tip.string = ''
  27. this.node.opacity = 255
  28. } else {
  29. }
  30. this.playAnim()
  31. }, 3)
  32. } else {
  33. this.node.opacity = 255
  34. this.str = args.str
  35. this.playAnim()
  36. }
  37. if (args.cutNet || args.timeout) {
  38. this.scheduleOnce(() => {
  39. this.hide()
  40. if (args.cutNet) {
  41. Mgr.ui.message(
  42. LANGUAGE_TYPE.netCut,
  43. () => {
  44. GameControl.resetGame()
  45. },
  46. true,
  47. )
  48. }
  49. }, 10)
  50. }
  51. }
  52. public playAnim() {
  53. cc.tween(this.aniNode)
  54. .then(cc.tween().by(3, {angle: -360}).repeatForever())
  55. .start()
  56. this.schedule(() => {
  57. if (this.dot.length < 3) {
  58. this.dot += '.'
  59. } else {
  60. this.dot = ''
  61. }
  62. this.tip.string = `${Mgr.i18n.getLabel(this.str)}${this.dot}`
  63. }, 0.33)
  64. }
  65. public onDisable() {
  66. this.node.opacity = 0
  67. this.tip.string = ''
  68. }
  69. }