選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

223 行
5.1 KiB

  1. define([
  2. 'js/system/events',
  3. 'css!ui/templates/tooltipItem/styles',
  4. 'html!ui/templates/tooltipItem/template',
  5. 'html!ui/templates/tooltipItem/templateTooltip',
  6. 'js/misc/statTranslations'
  7. ], function(
  8. events,
  9. styles,
  10. template,
  11. tplTooltip,
  12. statTranslations
  13. ) {
  14. return {
  15. tpl: template,
  16. type: 'tooltipItem',
  17. tooltip: null,
  18. item: null,
  19. postRender: function() {
  20. this.tooltip = this.el.find('.tooltip');
  21. this.onEvent('onShowItemTooltip', this.onShowItemTooltip.bind(this));
  22. this.onEvent('onHideItemTooltip', this.onHideItemTooltip.bind(this));
  23. },
  24. onHideItemTooltip: function(item) {
  25. if (this.item != item)
  26. return;
  27. this.item = null;
  28. this.tooltip.hide();
  29. },
  30. onShowItemTooltip: function(item, pos, compare, bottomAlign, shiftDown) {
  31. this.item = item;
  32. var tempStats = $.extend(true, {}, item.stats);
  33. if ((compare) && (shiftDown)) {
  34. if (!item.eq) {
  35. var compareStats = compare.stats;
  36. for (var s in tempStats) {
  37. if (compareStats[s]) {
  38. var delta = tempStats[s] - compareStats[s];
  39. if (delta > 0)
  40. tempStats[s] = '+' + delta;
  41. else if (delta < 0)
  42. tempStats[s] = delta;
  43. }
  44. else
  45. tempStats[s] = '+' + tempStats[s];
  46. }
  47. for (var s in compareStats) {
  48. if (!tempStats[s]) {
  49. tempStats[s] = -compareStats[s];
  50. }
  51. }
  52. }
  53. }
  54. stats = Object.keys(tempStats)
  55. .map(function(s) {
  56. var statName = statTranslations.translate(s);
  57. var value = tempStats[s];
  58. if (['addCritChance', 'sprintChance', 'dmgPercent', 'xpIncrease'].indexOf(s) > -1)
  59. value += '%';
  60. else if ((s.indexOf('element') == 0) && (s.indexOf('Resist') == -1))
  61. value += '%';
  62. var row = value + ' ' + statName;
  63. var rowClass = '';
  64. if (compare) {
  65. if (row.indexOf('-') > -1)
  66. rowClass = 'loseStat';
  67. else if (row.indexOf('+') > -1)
  68. rowClass = 'gainStat';
  69. }
  70. row = '<div class="' + rowClass + '">' + row + '</div>';
  71. return row;
  72. }, this)
  73. .sort(function(a, b) {
  74. return (a.length - b.length);
  75. })
  76. .join('');
  77. var name = item.name;
  78. if (item.quantity)
  79. name += ' x' + item.quantity;
  80. var html = tplTooltip
  81. .replace('$NAME$', name)
  82. .replace('$QUALITY$', item.quality)
  83. .replace('$TYPE$', item.type)
  84. .replace('$SLOT$', item.slot)
  85. .replace('$STATS$', stats)
  86. .replace('$LEVEL$', item.level);
  87. if (item.power)
  88. html = html.replace('$POWER$', ' ' + (new Array(item.power + 1)).join('+'));
  89. if ((item.spell) && (item.spell.values)) {
  90. var abilityValues = '';
  91. for (var p in item.spell.values) {
  92. abilityValues += p + ': ' + item.spell.values[p] + '<br/>';
  93. }
  94. if (!item.ability)
  95. abilityValues = abilityValues;
  96. html = html.replace('$DAMAGE$', abilityValues);
  97. }
  98. this.tooltip.html(html);
  99. if (!item.level)
  100. this.tooltip.find('.level').hide();
  101. else
  102. this.tooltip.find('.level').show();
  103. if (item.power)
  104. this.tooltip.find('.power').show();
  105. if (item.level > window.player.stats.values.level)
  106. this.tooltip.find('.level').addClass('high-level');
  107. if ((item.material) || (item.quest) || (item.ability)) {
  108. this.tooltip.find('.level').hide();
  109. this.tooltip.find('.info').hide();
  110. if (item.material)
  111. this.tooltip.find('.material').show();
  112. else if (item.quest)
  113. this.tooltip.find('.quest').show();
  114. }
  115. else if (item.eq)
  116. this.tooltip.find('.info').hide();
  117. if (!item.ability) {
  118. this.tooltip.find('.damage').hide();
  119. }
  120. else
  121. this.tooltip.find('.info').hide();
  122. if (item.spell) {
  123. this.tooltip.find('.spellName')
  124. .html('<br />' + item.spell.name)
  125. .addClass('q' + item.spell.quality)
  126. .show();
  127. this.tooltip.find('.damage')
  128. .show();
  129. if (item.ability)
  130. this.tooltip.find('.spellName').hide();
  131. }
  132. else
  133. this.tooltip.find('.spellName').hide();
  134. this.tooltip.find('.worth').html(item.worth ? ('<br />value: ' + item.worth) : '');
  135. if (item.effects) {
  136. var htmlEffects = '';
  137. item.effects.forEach(function(e, i) {
  138. htmlEffects += e.text;
  139. if (i < item.effects.length - 1)
  140. htmlEffects += '<br />';
  141. });
  142. this.find('.effects')
  143. .html(htmlEffects)
  144. .show();
  145. }
  146. else
  147. this.find('.effects').hide();
  148. if (item.factions) {
  149. var htmlFactions = '';
  150. item.factions.forEach(function(f, i) {
  151. var htmlF = f.name + ': ' + f.tierName;
  152. if (f.noEquip)
  153. htmlF = '<font class="color-red">' + htmlF + '</font>';
  154. htmlFactions += htmlF;
  155. if (i < item.factions.length - 1)
  156. htmlFactions += '<br />';
  157. });
  158. this.find('.faction')
  159. .html(htmlFactions)
  160. .show();
  161. }
  162. else
  163. this.find('.faction').hide();
  164. if ((shiftDown) || (!compare))
  165. this.tooltip.find('.info').hide();
  166. this.tooltip
  167. .show();
  168. if (pos) {
  169. if (bottomAlign)
  170. pos.y -= this.tooltip.height();
  171. this.tooltip.css({
  172. left: pos.x,
  173. top: pos.y
  174. });
  175. }
  176. events.emit('onBuiltItemTooltip', this.tooltip);
  177. },
  178. showWorth: function(canAfford) {
  179. this.tooltip.find('.worth').show();
  180. if (!canAfford)
  181. this.tooltip.find('.worth').addClass('no-afford');
  182. }
  183. };
  184. });