MainUI.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { Sprite, Vec3, _decorator } from 'cc';
  2. import { AudioID } from '../../../framework/config/AudioConf';
  3. import { ViewID } from '../../../framework/config/LayerConf';
  4. import { Framework } from '../../../framework/Framework';
  5. import { BaseView } from '../../../framework/layer/BaseView';
  6. import { UserData } from '../../data/UserData';
  7. import { LoginMgr } from '../../common/LoginManager';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('MainUI')
  10. export class MainUI extends BaseView {
  11. private GameUI = {}
  12. private openGameUI = 'Unpacking';
  13. private _timer_uuid = 0;
  14. onLoad() {
  15. super.onLoad();
  16. }
  17. // 所有监听事件
  18. EventAll() {
  19. }
  20. onDestroy() {
  21. Framework.event.removeEvent(this);
  22. super.onDestroy();
  23. }
  24. onOpen() {
  25. // this.mainRedDot();
  26. Framework.layer.open(ViewID.TowerUI, null, (the) => {
  27. // Framework.layer.open(ViewID.ZombieUI, null, (the) => {
  28. this.GameUI[this.openGameUI] = the
  29. });
  30. }
  31. onMiningRedDotChanged(redNum: number) {
  32. this.Node.Mining_red.active = redNum > 0;
  33. }
  34. onArena() {
  35. Framework.audio.playEffect(AudioID.Click);
  36. LoginMgr.sendPost('arena', 'get', (data) => {
  37. if (data) {
  38. //Framework.layer.open(ViewID.Arena, null, data);
  39. }
  40. })
  41. }
  42. onOpenWin(event: Event, openUI) {
  43. Framework.audio.playEffect(AudioID.Click);
  44. let target: any = event.target;
  45. if (openUI) {
  46. if (openUI == 'Legion') {
  47. if (UserData['legion'].id != 0) {
  48. //Framework.layer.open(ViewID.Legion);
  49. } else {
  50. //Framework.layer.open(ViewID.NoLegion);
  51. }
  52. } else {
  53. let open_url = Number(ViewID[openUI])
  54. Framework.layer.open(open_url);
  55. }
  56. }
  57. }
  58. onClose() {
  59. }
  60. onShow() {
  61. this._ui_opacity.opacity = 255;
  62. this.node.setPosition(0, 0);
  63. }
  64. onHide() {
  65. this._ui_opacity.opacity = 0;
  66. this.node.setPosition(0, -5000);
  67. }
  68. private onTouchButton(event: Event, openUI) {
  69. Framework.audio.playEffect(AudioID.Click);
  70. let target: any = event.target;
  71. // UserData.getNodeFullPath(target)
  72. if (openUI) {
  73. let open_url = Number(ViewID[openUI])
  74. Framework.layer.open(open_url, () => {
  75. if (openUI == 'Territory') {
  76. if (!UserData['RoomId']) {
  77. UserData['RoomId'] = UserData['_id']
  78. }
  79. }
  80. });
  81. }
  82. }
  83. private BottonBtn(e, str) {
  84. Framework.audio.playEffect(AudioID.Click);
  85. let target = e.target
  86. // UserData.getNodeFullPath(target)
  87. if (this.openGameUI != target.name) {
  88. if (str == 'Mining') {
  89. // let openState = GameUtil.checkSystemOpen(Number(ViewID.Mining));
  90. // if (!openState.state) {
  91. // Framework.tips.setTips(openState.tips);
  92. // return;
  93. // }
  94. }
  95. let openGameUI = this.openGameUI
  96. let onBgFrame = target.parent.getComponent(Sprite).spriteFrame
  97. let unBgFrame = this.Node[this.openGameUI].parent.getComponent(Sprite).spriteFrame
  98. this.Node[this.openGameUI].children[0].scale = new Vec3(0.75, 0.75)
  99. target.parent.getComponent(Sprite).spriteFrame = unBgFrame
  100. this.Node[this.openGameUI].parent.getComponent(Sprite).spriteFrame = onBgFrame
  101. target.children[0].scale = new Vec3(1, 1)
  102. if (this.GameUI[this.openGameUI]) {
  103. this.GameUI[this.openGameUI].onHide()
  104. }
  105. this.openGameUI = str;
  106. if (!this.GameUI[str]) {
  107. Framework.layer.open(Number(ViewID[str]), () => {
  108. console.log(str);
  109. // let onBgFrame = this.Node[this.openGameUI].parent.getComponent(Sprite).spriteFrame;
  110. // let unBgFrame = this.Node[openGameUI].parent.getComponent(Sprite).spriteFrame;
  111. // console.log(this.openGameUI);
  112. // this.Node[this.openGameUI].children[0].scale = new Vec3(0.75, 0.75);
  113. // this.Node[this.openGameUI].parent.getComponent(Sprite).spriteFrame = unBgFrame;
  114. // this.Node[openGameUI].parent.getComponent(Sprite).spriteFrame = onBgFrame;
  115. // this.Node[openGameUI].children[0].scale = new Vec3(1, 1);
  116. // if (this.GameUI[openGameUI]) {
  117. // this.GameUI[openGameUI].onHide();
  118. // }
  119. // this.openGameUI = openGameUI;
  120. }, (the) => {
  121. // this.GameUI[str] = the
  122. // UserData['GameUIPage'] = GameConf.GamePageType[str];
  123. });
  124. } else {
  125. this.GameUI[str].onShow()
  126. }
  127. }
  128. }
  129. private _startTimer() {
  130. (this._timer_uuid != 0) && this._unschedule(this._timer_uuid);
  131. // this._timer_uuid = this._schedule(() => {
  132. // // LoginMgr.saveData();
  133. // }, GameConf.Macro.default_update_time);
  134. }
  135. }