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.
 
 
 

110 line
2.5 KiB

  1. define([
  2. 'js/system/events',
  3. 'html!ui/templates/options/template',
  4. 'css!ui/templates/options/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. centered: true,
  23. modal: true,
  24. postRender: function () {
  25. this.onEvent('onToggleOptions', this.toggle.bind(this));
  26. //Can only toggle fullscreen directly in a listener, not deferred the way jQuery does it
  27. this.el.find('.btnScreen')[0].addEventListener('click', this.toggleScreen.bind(this));
  28. this.el.find('.btnNames').on('click', events.emit.bind(events, 'onKeyDown', 'v'));
  29. this.el.find('.btnCharSelect').on('click', this.charSelect.bind(this));
  30. this.el.find('.btnLogOut').on('click', this.logOut.bind(this));
  31. this.el.find('.btnContinue').on('click', this.toggle.bind(this));
  32. this.el.find('.btnPatreon').on('click', this.patreon.bind(this));
  33. this.el.find('.btnIssue').on('click', this.reportIssue.bind(this));
  34. this.onEvent('onResize', this.onResize.bind(this));
  35. },
  36. reportIssue: function () {
  37. window.open('https://gitlab.com/Isleward/isleward/issues/new', '_blank');
  38. },
  39. patreon: function () {
  40. window.open('https://patreon.com/bigbadwaffle', '_blank');
  41. },
  42. charSelect: function () {
  43. this.el.addClass('disabled');
  44. client.request({
  45. module: 'cons',
  46. method: 'unzone',
  47. callback: this.onCharSelect.bind(this)
  48. });
  49. },
  50. onCharSelect: function () {
  51. renderer.clean();
  52. objects.onRezone();
  53. renderer.buildTitleScreen();
  54. sound.unload();
  55. events.emit('onShowCharacterSelect');
  56. $('[class^="ui"]:not(.ui-container)').toArray().forEach(el => {
  57. let ui = $(el).data('ui');
  58. if (ui && ui.destroy)
  59. ui.destroy();
  60. });
  61. factory.build('characters', {});
  62. },
  63. toggleScreen: function () {
  64. this.el.find('.btnScreen').html(renderer.toggleScreen());
  65. },
  66. onResize: function () {
  67. let isFullscreen = (window.innerHeight === screen.height);
  68. if (isFullscreen)
  69. this.el.find('.btnScreen').html('Windowed');
  70. else
  71. this.el.find('.btnScreen').html('Fullscreen');
  72. },
  73. toggle: function () {
  74. this.onResize();
  75. this.shown = !this.el.is(':visible');
  76. if (this.shown) {
  77. this.show();
  78. events.emit('onShowOverlay', this.el);
  79. } else {
  80. this.hide();
  81. events.emit('onHideOverlay', this.el);
  82. }
  83. },
  84. logOut: function () {
  85. window.location = window.location;
  86. },
  87. onKeyDown: function (key) {
  88. if (key === 'esc')
  89. this.toggle();
  90. }
  91. };
  92. });