Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

189 řádky
3.7 KiB

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