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.

177 lines
3.2 KiB

  1. define([
  2. 'ui/uiBase',
  3. 'js/system/events',
  4. 'js/system/globals',
  5. 'js/misc/tosAcceptanceValid'
  6. ], function (
  7. uiBase,
  8. events,
  9. globals,
  10. tosAcceptanceValid
  11. ) {
  12. const startupUis = [
  13. 'inventory',
  14. 'equipment',
  15. 'hud',
  16. 'target',
  17. 'menu',
  18. 'spells',
  19. 'messages',
  20. 'online',
  21. 'mainMenu',
  22. 'context',
  23. 'party',
  24. 'help',
  25. 'dialogue',
  26. 'buffs',
  27. 'tooltips',
  28. 'tooltipInfo',
  29. 'tooltipItem',
  30. 'announcements',
  31. 'quests',
  32. 'events',
  33. 'progressBar',
  34. 'stash',
  35. 'talk',
  36. 'trade',
  37. 'overlay',
  38. 'death',
  39. 'leaderboard',
  40. 'reputation',
  41. 'mail',
  42. 'wardrobe',
  43. 'passives',
  44. 'middleHud',
  45. 'options'
  46. ];
  47. return {
  48. uis: [],
  49. root: '',
  50. init: function (root, uiList = []) {
  51. if (root)
  52. this.root = root + '/';
  53. startupUis.push(...uiList);
  54. events.on('onEnterGame', this.onEnterGame.bind(this));
  55. events.on('onUiKeyDown', this.onUiKeyDown.bind(this));
  56. events.on('onResize', this.onResize.bind(this));
  57. },
  58. onEnterGame: function () {
  59. events.clearQueue();
  60. startupUis.forEach(function (u) {
  61. if (u.path)
  62. this.buildModUi(u);
  63. else
  64. this.build(u);
  65. }, this);
  66. },
  67. buildModUi: function (config) {
  68. const type = config.path.split('/').pop();
  69. this.build(type, {
  70. path: config.path
  71. });
  72. },
  73. build: function (type, options) {
  74. let className = 'ui' + type[0].toUpperCase() + type.substr(1);
  75. let el = $('.' + className);
  76. if (el.length > 0)
  77. return;
  78. this.getTemplate(type, options);
  79. },
  80. getTemplate: function (type, options) {
  81. let path = null;
  82. if (options && options.path)
  83. path = options.path + `\\${type}.js`;
  84. else
  85. path = this.root + 'ui/templates/' + type + '/' + type;
  86. require([path], this.onGetTemplate.bind(this, options));
  87. },
  88. onGetTemplate: function (options, template) {
  89. let ui = $.extend(true, {}, uiBase, template);
  90. ui.setOptions(options);
  91. requestAnimationFrame(this.renderUi.bind(this, ui));
  92. },
  93. renderUi: function (ui) {
  94. ui.render();
  95. ui.el.data('ui', ui);
  96. this.uis.push(ui);
  97. },
  98. onResize: function () {
  99. this.uis.forEach(function (ui) {
  100. if (ui.centered)
  101. ui.center();
  102. else if ((ui.centeredX) || (ui.centeredY))
  103. ui.center(ui.centeredX, ui.centeredY);
  104. }, this);
  105. },
  106. onUiKeyDown: function (keyEvent) {
  107. if (keyEvent.key === 'esc') {
  108. this.uis.forEach(u => {
  109. if (!u.modal || !u.shown)
  110. return;
  111. keyEvent.consumed = true;
  112. u.hide();
  113. });
  114. $('.uiOverlay').hide();
  115. events.emit('onHideContextMenu');
  116. } else if (['o', 'j', 'h', 'i'].indexOf(keyEvent.key) > -1)
  117. $('.uiOverlay').hide();
  118. },
  119. preload: function () {
  120. require([
  121. 'death',
  122. 'dialogue',
  123. 'equipment',
  124. 'events',
  125. 'hud',
  126. 'inventory',
  127. 'overlay',
  128. 'passives',
  129. 'quests',
  130. 'reputation',
  131. 'stash'
  132. ].map(m => 'ui/templates/' + m + '/' + m), this.afterPreload.bind(this));
  133. },
  134. afterPreload: function () {
  135. if (!globals.clientConfig.tos.required || tosAcceptanceValid()) {
  136. this.build('characters');
  137. return;
  138. }
  139. this.build('terms');
  140. },
  141. update: function () {
  142. let uis = this.uis;
  143. let uLen = uis.length;
  144. for (let i = 0; i < uLen; i++) {
  145. let u = uis[i];
  146. if (u.update)
  147. u.update();
  148. }
  149. }
  150. };
  151. });