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ů.
 
 
 

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