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. this.GameUI[this.openGameUI] = the
  28. });
  29. }
  30. onMiningRedDotChanged(redNum: number) {
  31. this.Node.Mining_red.active = redNum > 0;
  32. }
  33. onArena() {
  34. Framework.audio.playEffect(AudioID.Click);
  35. LoginMgr.sendPost('arena', 'get', (data) => {
  36. if (data) {
  37. //Framework.layer.open(ViewID.Arena, null, data);
  38. }
  39. })
  40. }
  41. onOpenWin(event: Event, openUI) {
  42. Framework.audio.playEffect(AudioID.Click);
  43. let target: any = event.target;
  44. if (openUI) {
  45. if (openUI == 'Legion') {
  46. if (UserData['legion'].id != 0) {
  47. //Framework.layer.open(ViewID.Legion);
  48. } else {
  49. //Framework.layer.open(ViewID.NoLegion);
  50. }
  51. } else {
  52. let open_url = Number(ViewID[openUI])
  53. Framework.layer.open(open_url);
  54. }
  55. }
  56. }
  57. onClose() {
  58. }
  59. onShow() {
  60. this._ui_opacity.opacity = 255;
  61. this.node.setPosition(0, 0);
  62. }
  63. onHide() {
  64. this._ui_opacity.opacity = 0;
  65. this.node.setPosition(0, -5000);
  66. }
  67. private onTouchButton(event: Event, openUI) {
  68. Framework.audio.playEffect(AudioID.Click);
  69. let target: any = event.target;
  70. // UserData.getNodeFullPath(target)
  71. if (openUI) {
  72. let open_url = Number(ViewID[openUI])
  73. Framework.layer.open(open_url, () => {
  74. if (openUI == 'Territory') {
  75. if (!UserData['RoomId']) {
  76. UserData['RoomId'] = UserData['_id']
  77. }
  78. }
  79. });
  80. }
  81. }
  82. private BottonBtn(e, str) {
  83. Framework.audio.playEffect(AudioID.Click);
  84. let target = e.target
  85. // UserData.getNodeFullPath(target)
  86. if (this.openGameUI != target.name) {
  87. if (str == 'Mining') {
  88. // let openState = GameUtil.checkSystemOpen(Number(ViewID.Mining));
  89. // if (!openState.state) {
  90. // Framework.tips.setTips(openState.tips);
  91. // return;
  92. // }
  93. }
  94. let openGameUI = this.openGameUI
  95. let onBgFrame = target.parent.getComponent(Sprite).spriteFrame
  96. let unBgFrame = this.Node[this.openGameUI].parent.getComponent(Sprite).spriteFrame
  97. this.Node[this.openGameUI].children[0].scale = new Vec3(0.75, 0.75)
  98. target.parent.getComponent(Sprite).spriteFrame = unBgFrame
  99. this.Node[this.openGameUI].parent.getComponent(Sprite).spriteFrame = onBgFrame
  100. target.children[0].scale = new Vec3(1, 1)
  101. if (this.GameUI[this.openGameUI]) {
  102. this.GameUI[this.openGameUI].onHide()
  103. }
  104. this.openGameUI = str;
  105. if (!this.GameUI[str]) {
  106. console.log(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. }