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.
 
 
 

178 line
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. 'workbench',
  45. 'middleHud',
  46. 'options'
  47. ];
  48. return {
  49. uis: [],
  50. root: '',
  51. init: function (root, uiList = []) {
  52. if (root)
  53. this.root = root + '/';
  54. startupUis.push(...uiList);
  55. events.on('onEnterGame', this.onEnterGame.bind(this));
  56. events.on('onUiKeyDown', this.onUiKeyDown.bind(this));
  57. events.on('onResize', this.onResize.bind(this));
  58. },
  59. onEnterGame: function () {
  60. events.clearQueue();
  61. startupUis.forEach(function (u) {
  62. if (u.path)
  63. this.buildModUi(u);
  64. else
  65. this.build(u);
  66. }, this);
  67. },
  68. buildModUi: function (config) {
  69. const type = config.path.split('/').pop();
  70. this.build(type, {
  71. path: config.path
  72. });
  73. },
  74. build: function (type, options) {
  75. let className = 'ui' + type[0].toUpperCase() + type.substr(1);
  76. let el = $('.' + className);
  77. if (el.length > 0)
  78. return;
  79. this.getTemplate(type, options);
  80. },
  81. getTemplate: function (type, options) {
  82. let path = null;
  83. if (options && options.path)
  84. path = options.path + `\\${type}.js`;
  85. else
  86. path = this.root + 'ui/templates/' + type + '/' + type;
  87. require([path], this.onGetTemplate.bind(this, options));
  88. },
  89. onGetTemplate: function (options, template) {
  90. let ui = $.extend(true, {}, uiBase, template);
  91. ui.setOptions(options);
  92. requestAnimationFrame(this.renderUi.bind(this, ui));
  93. },
  94. renderUi: function (ui) {
  95. ui.render();
  96. ui.el.data('ui', ui);
  97. this.uis.push(ui);
  98. },
  99. onResize: function () {
  100. this.uis.forEach(function (ui) {
  101. if (ui.centered)
  102. ui.center();
  103. else if ((ui.centeredX) || (ui.centeredY))
  104. ui.center(ui.centeredX, ui.centeredY);
  105. }, this);
  106. },
  107. onUiKeyDown: function (keyEvent) {
  108. if (keyEvent.key === 'esc') {
  109. this.uis.forEach(u => {
  110. if (!u.modal || !u.shown)
  111. return;
  112. keyEvent.consumed = true;
  113. u.hide();
  114. });
  115. $('.uiOverlay').hide();
  116. events.emit('onHideContextMenu');
  117. } else if (['o', 'j', 'h', 'i'].indexOf(keyEvent.key) > -1)
  118. $('.uiOverlay').hide();
  119. },
  120. preload: function () {
  121. require([
  122. 'death',
  123. 'dialogue',
  124. 'equipment',
  125. 'events',
  126. 'hud',
  127. 'inventory',
  128. 'overlay',
  129. 'passives',
  130. 'quests',
  131. 'reputation',
  132. 'stash'
  133. ].map(m => 'ui/templates/' + m + '/' + m), this.afterPreload.bind(this));
  134. },
  135. afterPreload: function () {
  136. if (!globals.clientConfig.tos.required || tosAcceptanceValid()) {
  137. this.build('characters');
  138. return;
  139. }
  140. this.build('terms');
  141. },
  142. update: function () {
  143. let uis = this.uis;
  144. let uLen = uis.length;
  145. for (let i = 0; i < uLen; i++) {
  146. let u = uis[i];
  147. if (u.update)
  148. u.update();
  149. }
  150. }
  151. };
  152. });