Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

152 строки
3.4 KiB

  1. define([
  2. 'js/system/events',
  3. 'html!ui/templates/spells/template',
  4. 'css!ui/templates/spells/styles',
  5. 'html!ui/templates/spells/templateSpell',
  6. 'html!ui/templates/spells/templateTooltip'
  7. ], function(
  8. events,
  9. template,
  10. styles,
  11. templateSpell,
  12. templateTooltip
  13. ) {
  14. return {
  15. tpl: template,
  16. spells: null,
  17. postRender: function() {
  18. this.onEvent('onGetSpells', this.onGetSpells.bind(this));
  19. this.onEvent('onGetSpellCooldowns', this.onGetSpellCooldowns.bind(this));
  20. this.onEvent('onGetStats', this.onGetStats.bind(this));
  21. setInterval(this.update.bind(this), 100);
  22. },
  23. onGetSpells: function(spells) {
  24. this.el.empty();
  25. this.spells = spells;
  26. for (var i = 0; i < spells.length; i++) {
  27. var icon = spells[i].icon;
  28. var x = -(icon[0] * 64);
  29. var y = -(icon[1] * 64);
  30. var html = templateSpell
  31. .replace('$HOTKEY$', (i + 1));
  32. var el = $(html)
  33. .appendTo(this.el);
  34. el
  35. .on('mouseover', this.onShowTooltip.bind(this, el, spells[i]))
  36. .on('mouseleave', this.onHideTooltip.bind(this, el));
  37. var spritesheet = spells[i].spritesheet || '../../../images/abilityIcons.png';
  38. el
  39. .find('.icon').css({
  40. 'background': 'url("' + spritesheet + '") ' + x + 'px ' + y + 'px'
  41. })
  42. .next().html(i + 1);
  43. this.onGetSpellCooldowns({
  44. spell: i,
  45. cd: spells[i].cd * 350 //HACK - we don't actually know how long a tick is
  46. });
  47. }
  48. },
  49. onShowTooltip: function(el, spell) {
  50. var pos = el.offset();
  51. pos = {
  52. x: pos.left + 56,
  53. y: pos.top + el.height() + 16
  54. };
  55. var cd = ~~((spell.cdMax * 350) / 1000);
  56. var values = Object.keys(spell.values).filter(function(v) {
  57. return ((v != 'damage') && (v != 'healing'));
  58. }).map(function(v) {
  59. return v + ': ' + spell.values[v];
  60. }).join('<br />');
  61. var tooltip = templateTooltip
  62. .replace('$NAME$', spell.name)
  63. .replace('$DESCRIPTION$', spell.description)
  64. .replace('$MANA$', spell.manaCost)
  65. .replace('$CD$', cd)
  66. .replace('$VALUES$', values)
  67. .replace('$ELEMENT$', spell.element);
  68. if (spell.range) {
  69. tooltip = tooltip
  70. .replace('$RANGE$', spell.range);
  71. } else {
  72. tooltip = tooltip
  73. .replace('range', 'range hidden');
  74. }
  75. events.emit('onShowTooltip', tooltip, el[0], pos, 200, false, true, this.el.css('z-index'));
  76. },
  77. onHideTooltip: function(el) {
  78. events.emit('onHideTooltip', el[0]);
  79. },
  80. onGetSpellCooldowns: function(options) {
  81. var spell = this.spells[options.spell];
  82. spell.ttl = options.cd;
  83. spell.ttlStart = +new Date;
  84. },
  85. onGetStats: function(stats) {
  86. var mana = stats.mana;
  87. var spells = this.spells;
  88. if (!spells)
  89. return;
  90. for (var i = 0; i < spells.length; i++) {
  91. var spell = spells[i];
  92. var el = this.el.children('div').eq(i).find('.hotkey');
  93. el.removeClass('no-mana');
  94. if (spell.manaCost > mana)
  95. el.addClass('no-mana');
  96. }
  97. },
  98. update: function() {
  99. var spells = this.spells;
  100. if (!spells)
  101. return;
  102. var time = +new Date;
  103. for (var i = 0; i < spells.length; i++) {
  104. var spell = spells[i];
  105. if (!spell.ttl) {
  106. this.el.children('div').eq(i).find('.cooldown').css({
  107. width: '0%'
  108. });
  109. continue;
  110. }
  111. var elapsed = time - spell.ttlStart;
  112. var width = 1 - (elapsed / spell.ttl);
  113. if (width <= 0) {
  114. delete spell.ttl;
  115. width = 0;
  116. }
  117. width = Math.ceil((width * 100) / 4) * 4;
  118. this.el.children('div').eq(i).find('.cooldown').css({
  119. width: width + '%'
  120. });
  121. }
  122. }
  123. }
  124. });