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.
 
 
 

107 lines
2.5 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. hasClose: true,
  17. list: null,
  18. postRender: function () {
  19. this.onEvent('onGetReputations', this.onGetReputations.bind(this));
  20. this.onEvent('onShowReputation', this.toggle.bind(this, true));
  21. },
  22. build: function () {
  23. let list = this.list;
  24. this.find('.info .heading-bottom').html('');
  25. this.find('.info .description').html('');
  26. this.find('.bar-outer').hide();
  27. if (!list.length)
  28. this.find('.heading-bottom').html("you haven't discovered any factions yet");
  29. else
  30. this.find('.heading-bottom').html('select a faction to see more info');
  31. let elList = this.find('.list').empty();
  32. list.forEach(l => {
  33. if (l.noGainRep)
  34. return;
  35. let html = '<div class="faction">' + l.name + '</div>';
  36. let el = $(html).appendTo(elList);
  37. el.on('click', this.onSelectFaction.bind(this, el, l));
  38. el.on('click', events.emit.bind(events, 'onClickButton'));
  39. });
  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);
  45. this.find('.info .description').html(faction.description);
  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. if (tier === tiers.length - 1)
  53. percentage = 100;
  54. this.find('.bar-outer').show();
  55. this.find('.front').css({
  56. width: percentage + '%',
  57. minWidth: percentage + '%'
  58. });
  59. let w = ~~(this.find('.front').width() / 5) * 5;
  60. this.find('.front').css({
  61. width: w
  62. });
  63. percentage = ~~(percentage * 10) / 10;
  64. this.find('.tier').html(tiers[tier].name.toLowerCase() + ' (' + percentage + '%)');
  65. },
  66. onGetReputations: function (list) {
  67. this.list = list;
  68. this.list.sort(function (a, b) {
  69. if (a.name[0] < b.name[0])
  70. return -1;
  71. return 1;
  72. });
  73. let selElement = this.find('.selected');
  74. if (this.el.is(':visible') && selElement.index() !== -1)
  75. this.onSelectFaction(selElement, list[selElement.index() + 1]);
  76. },
  77. onAfterShow: function () {
  78. this.build();
  79. }
  80. };
  81. });