MainUI.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { Color, SpriteAtlas, _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. const { ccclass, property } = _decorator;
  7. @ccclass('MainUI')
  8. export class MainUI extends BaseView {
  9. /** 菜单图集 */
  10. private _menuBottomAtlas: SpriteAtlas;
  11. /** 菜单栏 */
  12. private _menuNameArray: Array<string> = ['Welfare', 'Games', 'OpenBets', 'Me'];
  13. /** 选中 */
  14. private _selected: string = 'Games';
  15. /** 状态 */
  16. private _isLoaded: boolean = false;
  17. onLoad() {
  18. super.onLoad();
  19. }
  20. onDestroy() {
  21. super.onDestroy();
  22. Framework.event.removeEvent(this);
  23. }
  24. onOpen() {
  25. //加载菜单
  26. this.load('package', 'texture/hall/Menu_Bottom/Menu_Bottom', SpriteAtlas, (res: SpriteAtlas) => {
  27. this._menuBottomAtlas = res;
  28. this._isLoaded = true;
  29. this.updateSelectMenu();
  30. })
  31. }
  32. onClose() {
  33. }
  34. onShow() {
  35. this._ui_opacity.opacity = 255;
  36. this.node.setPosition(0, 0);
  37. }
  38. onHide() {
  39. this._ui_opacity.opacity = 0;
  40. this.node.setPosition(0, -5000);
  41. }
  42. private onTouchButton(event: Event, customStr) {
  43. // let target: any = event.target;
  44. if (!this._isLoaded) {
  45. return;
  46. }
  47. if (customStr != 'Games') {
  48. Framework.tips.setTips('Not yet available');
  49. return;
  50. }
  51. this._selected = customStr;
  52. this.updateSelectMenu();
  53. }
  54. updateSelectMenu() {
  55. for (let i = 0; i < this._menuNameArray.length; i++) {
  56. const name = this._menuNameArray[i];
  57. if (this._selected == name) {
  58. this.Sprite[name].spriteFrame = this._menuBottomAtlas.spriteFrames[name + '_' + 'Yellow'];
  59. this.Label[name].color = new Color(244, 184, 12);
  60. this.updateSelectInfo();
  61. } else {
  62. this.Sprite[name].spriteFrame = this._menuBottomAtlas.spriteFrames[name + '_' + 'Grey'];
  63. this.Label[name].color = new Color(120, 123, 130);
  64. }
  65. }
  66. }
  67. updateSelectInfo() {
  68. }
  69. }