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.
 
 
 

106 lines
2.3 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'html!ui/templates/reputation/template',
  5. 'css!ui/templates/reputation/styles'
  6. ], function (
  7. events,
  8. client,
  9. template,
  10. styles
  11. ) {
  12. return {
  13. tpl: template,
  14. centered: true,
  15. modal: true,
  16. list: null,
  17. postRender: function () {
  18. this.onEvent('onGetReputations', this.onGetReputations.bind(this));
  19. this.onEvent('onShowReputation', this.toggle.bind(this, true));
  20. },
  21. build: function () {
  22. let list = this.list;
  23. this.find('.info .heading-bottom').html('');
  24. this.find('.info .description').html('');
  25. this.find('.bar-outer').hide();
  26. if (list.length == 0)
  27. this.find('.heading-bottom').html("you haven't discovered any factions yet");
  28. else
  29. this.find('.heading-bottom').html('select a faction to see more info');
  30. let elList = this.find('.list').empty();
  31. list.forEach(function (l) {
  32. if (l.noGainRep)
  33. return;
  34. let html = '<div class="faction">' + l.name.toLowerCase() + '</div>';
  35. let el = $(html)
  36. .appendTo(elList);
  37. el
  38. .on('click', this.onSelectFaction.bind(this, el, l));
  39. }, this);
  40. },
  41. onSelectFaction: function (el, faction) {
  42. this.find('.selected').removeClass('selected');
  43. $(el).addClass('selected');
  44. this.find('.info .heading-bottom').html(faction.name.toLowerCase());
  45. this.find('.info .description').html(faction.description.toLowerCase());
  46. let rep = faction.rep;
  47. let tier = faction.tier;
  48. let tiers = faction.tiers;
  49. let prevTier = tiers[tier];
  50. let nextTier = (tier == tiers.length - 1) ? tiers[tiers.length - 1] : tiers[tier + 1];
  51. let percentage = (rep - prevTier.rep) / (nextTier.rep - prevTier.rep) * 100;
  52. this.find('.bar-outer').show();
  53. this.find('.front').css({
  54. width: percentage + '%'
  55. });
  56. let w = ~~(this.find('.front').width() / 5) * 5;
  57. this.find('.front').css({
  58. width: w + 'px'
  59. });
  60. percentage = ~~(percentage * 10) / 10;
  61. this.find('.tier').html(tiers[tier].name.toLowerCase() + ' (' + percentage + '%)');
  62. },
  63. onGetReputations: function (list) {
  64. this.list = list;
  65. this.list.sort(function (a, b) {
  66. if (a.name[0] < b.name[0])
  67. return -1;
  68. return 1;
  69. });
  70. if (this.el.is(':visible'))
  71. this.build();
  72. },
  73. toggle: function () {
  74. let shown = !this.el.is(':visible');
  75. if (shown) {
  76. this.build();
  77. this.show();
  78. } else
  79. this.hide();
  80. }
  81. };
  82. });