You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

101 line
2.0 KiB

  1. define([
  2. 'js/system/events',
  3. 'html!ui/templates/mainMenu/template',
  4. 'css!ui/templates/mainMenu/styles',
  5. 'js/rendering/renderer',
  6. 'ui/factory',
  7. 'js/objects/objects',
  8. 'js/system/client',
  9. 'js/sound/sound'
  10. ], function (
  11. events,
  12. template,
  13. styles,
  14. renderer,
  15. factory,
  16. objects,
  17. client,
  18. sound
  19. ) {
  20. return {
  21. tpl: template,
  22. modal: true,
  23. hasClose: true,
  24. postRender: function () {
  25. this.onEvent('onCloseOptions', this.show.bind(this));
  26. this.onEvent('onShowMainMenu', this.show.bind(this));
  27. this.el.find('.btnOptions').on('click', this.openOptions.bind(this));
  28. this.el.find('.btnCharSelect').on('click', this.charSelect.bind(this));
  29. this.el.find('.btnLogOut').on('click', this.logOut.bind(this));
  30. this.el.find('.btnPatreon').on('click', this.patreon.bind(this));
  31. this.onEvent('onResize', this.onResize.bind(this));
  32. },
  33. openOptions: function () {
  34. if (isMobile)
  35. this.el.removeClass('active');
  36. events.emit('onOpenOptions');
  37. },
  38. patreon: function () {
  39. window.open('https://patreon.com/bigbadwaffle', '_blank');
  40. },
  41. charSelect: function () {
  42. this.el.addClass('disabled');
  43. client.request({
  44. module: 'cons',
  45. method: 'unzone',
  46. callback: this.onCharSelect.bind(this)
  47. });
  48. },
  49. onCharSelect: function () {
  50. events.emit('destroyAllObjects');
  51. events.emit('resetRenderer');
  52. events.emit('resetPhysics');
  53. renderer.buildTitleScreen();
  54. sound.unload();
  55. events.emit('onShowCharacterSelect');
  56. factory.exitGame();
  57. factory.build('characters', {});
  58. },
  59. onResize: function () {
  60. let isFullscreen = (window.innerHeight === screen.height);
  61. if (isFullscreen)
  62. this.el.find('.btnScreen').html('Windowed');
  63. else
  64. this.el.find('.btnScreen').html('Fullscreen');
  65. },
  66. onAfterShow: function () {
  67. this.onResize();
  68. },
  69. beforeHide: function () {
  70. this.onResize();
  71. },
  72. logOut: function () {
  73. window.location = window.location;
  74. },
  75. onKeyDown: function (key) {
  76. if (key === 'esc')
  77. this.toggle();
  78. }
  79. };
  80. });