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.
 
 
 

115 lines
2.2 KiB

  1. define([
  2. 'ui/uiBase',
  3. 'js/system/events'
  4. ], function (
  5. uiBase,
  6. events
  7. ) {
  8. return {
  9. uis: [],
  10. root: '',
  11. init: function (root) {
  12. if (root)
  13. this.root = root + '/';
  14. events.on('onEnterGame', this.onEnterGame.bind(this));
  15. events.on('onKeyDown', this.onKeyDown.bind(this));
  16. events.on('onResize', this.onResize.bind(this));
  17. },
  18. onEnterGame: function () {
  19. events.clearQueue();
  20. [
  21. 'inventory',
  22. 'equipment',
  23. 'hud',
  24. 'target',
  25. 'menu',
  26. 'spells',
  27. 'messages',
  28. 'online',
  29. 'options',
  30. 'context',
  31. 'party',
  32. 'help',
  33. 'dialogue',
  34. 'buffs',
  35. 'tooltips',
  36. 'tooltipInfo',
  37. 'tooltipItem',
  38. 'announcements',
  39. 'quests',
  40. 'events',
  41. 'progressBar',
  42. 'stash',
  43. 'smithing',
  44. 'talk',
  45. 'trade',
  46. 'overlay',
  47. 'death',
  48. 'leaderboard',
  49. 'reputation',
  50. 'mail',
  51. 'wardrobe',
  52. 'passives',
  53. 'workbench'
  54. ].forEach(function (u) {
  55. this.build(u);
  56. }, this);
  57. },
  58. build: function (type, options) {
  59. //Don't make doubles?
  60. let className = 'ui' + type[0].toUpperCase() + type.substr(1);
  61. let el = $('.' + className);
  62. if (el.length > 0)
  63. return;
  64. this.getTemplate(type, options);
  65. },
  66. getTemplate: function (type, options) {
  67. require([this.root + 'ui/templates/' + type + '/' + type], this.onGetTemplate.bind(this, options));
  68. },
  69. onGetTemplate: function (options, template) {
  70. let ui = _.create(uiBase, template);
  71. ui.setOptions(options);
  72. ui.render();
  73. ui.el.data('ui', ui);
  74. this.uis.push(ui);
  75. },
  76. onResize: function () {
  77. this.uis.forEach(function (ui) {
  78. if (ui.centered)
  79. ui.center();
  80. else if ((ui.centeredX) || (ui.centeredY))
  81. ui.center(ui.centeredX, ui.centeredY);
  82. }, this);
  83. },
  84. onKeyDown: function (key) {
  85. if (key == 'esc') {
  86. this.uis.forEach(function (u) {
  87. if (!u.modal)
  88. return;
  89. u.hide();
  90. });
  91. $('.uiOverlay').hide();
  92. events.emit('onHideContextMenu');
  93. } else if (['o', 'j', 'h', 'i'].indexOf(key) > -1)
  94. $('.uiOverlay').hide();
  95. },
  96. update: function () {
  97. let uis = this.uis;
  98. let uLen = uis.length;
  99. for (let i = 0; i < uLen; i++) {
  100. let u = uis[i];
  101. if (u.update)
  102. u.update();
  103. }
  104. }
  105. };
  106. });