ReputationBar.lua

ReputationBar.lua (9.2.5.43741; unchanged since 9.1.0.39289)
  1. ReputationBarMixin = CreateFromMixins(StatusTrackingBarMixin);
  2. function ReputationBarMixin:GetPriority()
  3. return self.priority;
  4. end
  5. function ReputationBarMixin:UpdateCurrentText()
  6. if ( self.isCapped ) then
  7. self:SetBarText(self.name);
  8. else
  9. self:SetBarText(self.name:format(self.value, self.max));
  10. end
  11. end
  12. function ReputationBarMixin:ShouldBeVisible()
  13. local name, reaction, minFaction, maxFaction, value, factionID = GetWatchedFactionInfo();
  14. return name ~= nil;
  15. end
  16. function ReputationBarMixin:Update()
  17. local name, reaction, minBar, maxBar, value, factionID = GetWatchedFactionInfo();
  18. local colorIndex = reaction;
  19. local isCapped;
  20. local friendshipID = GetFriendshipReputation(factionID);
  21. if ( self.factionID ~= factionID ) then
  22. self.factionID = factionID;
  23. self.friendshipID = GetFriendshipReputation(factionID);
  24. end
  25. -- do something different for friendships
  26. local level;
  27. if ( C_Reputation.IsFactionParagon(factionID) ) then
  28. local currentValue, threshold, _, hasRewardPending = C_Reputation.GetFactionParagonInfo(factionID);
  29. minBar, maxBar = 0, threshold;
  30. value = currentValue % threshold;
  31. if ( hasRewardPending ) then
  32. value = value + threshold;
  33. end
  34. elseif ( friendshipID ) then
  35. local friendID, friendRep, friendMaxRep, friendName, friendText, friendTexture, friendTextLevel, friendThreshold, nextFriendThreshold = GetFriendshipReputation(factionID);
  36. level = GetFriendshipReputationRanks(factionID);
  37. if ( nextFriendThreshold ) then
  38. minBar, maxBar, value = friendThreshold, nextFriendThreshold, friendRep;
  39. else
  40. -- max rank, make it look like a full bar
  41. minBar, maxBar, value = 0, 1, 1;
  42. isCapped = true;
  43. end
  44. colorIndex = 5; -- always color friendships green
  45. else
  46. level = reaction;
  47. if ( reaction == MAX_REPUTATION_REACTION ) then
  48. isCapped = true;
  49. end
  50. end
  51. -- Normalize values
  52. maxBar = maxBar - minBar;
  53. value = value - minBar;
  54. if ( isCapped and maxBar == 0 ) then
  55. maxBar = 1;
  56. value = 1;
  57. end
  58. minBar = 0;
  59. self:SetBarValues(value, minBar, maxBar, level);
  60. if ( isCapped ) then
  61. self:SetBarText(name);
  62. else
  63. name = name.." %d / %d";
  64. self:SetBarText(name:format(value, maxBar));
  65. end
  66. local color = FACTION_BAR_COLORS[colorIndex];
  67. self:SetBarColor(color.r, color.g, color.b, 1);
  68. self.isCapped = isCapped;
  69. self.name = name;
  70. self.value = value;
  71. self.max = maxBar;
  72. end
  73. function ReputationBarMixin:OnLoad()
  74. self:RegisterEvent("CVAR_UPDATE");
  75. self.priority = 1;
  76. end
  77. function ReputationBarMixin:OnEvent(event, ...)
  78. if( event == "CVAR_UPDATE") then
  79. local cvar = ...;
  80. if( cvar == "XP_BAR_TEXT" ) then
  81. self:UpdateTextVisibility();
  82. end
  83. end
  84. end
  85. function ReputationBarMixin:OnEnter()
  86. self:ShowText();
  87. self:UpdateCurrentText();
  88. ReputationParagonWatchBar_OnEnter(self);
  89. end
  90. function ReputationBarMixin:OnShow()
  91. self:UpdateTextVisibility();
  92. end
  93. function ReputationBarMixin:OnLeave()
  94. self:HideText();
  95. ReputationParagonWatchBar_OnLeave(self);
  96. end