/Tukui/modules/unitframes/plugins/oUF_Reputation/oUF_Reputation.lua

http://github.com/Asphyxia/Tukui · Lua · 75 lines · 49 code · 12 blank · 14 comment · 14 complexity · e226f1be4594bd1567e30537926d874d MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. if C.unitframes.enable ~= true then return end
  3. --[[
  4. Elements handled:
  5. .Reputation [statusbar]
  6. .Reputation.Text [fontstring] (optional)
  7. Booleans:
  8. - Tooltip
  9. Functions that can be overridden from within a layout:
  10. - PostUpdate(self, event, unit, bar, min, max, value, name, id)
  11. - OverrideText(bar, min, max, value, name, id)
  12. --]]
  13. local _, ns = ...
  14. local oUF = ns.oUF or oUF
  15. if not oUF then return end
  16. local function tooltip(self)
  17. local name, id, min, max, value = GetWatchedFactionInfo()
  18. GameTooltip:SetOwner(self, 'ANCHOR_BOTTOM', 0, -5)
  19. GameTooltip:AddLine(string.format('%s (%s)', name, _G['FACTION_STANDING_LABEL'..id]))
  20. GameTooltip:AddLine(string.format('%d / %d (%d%%)', value - min, max - min, (value - min) / (max - min) * 100))
  21. GameTooltip:Show()
  22. end
  23. local function update(self, event, unit)
  24. local bar = self.Reputation
  25. if(not GetWatchedFactionInfo()) then return bar:Hide() end
  26. local name, id, min, max, value = GetWatchedFactionInfo()
  27. bar:SetMinMaxValues(min, max)
  28. bar:SetValue(value)
  29. bar:Show()
  30. if(bar.Text) then
  31. if(bar.OverrideText) then
  32. bar:OverrideText(min, max, value, name, id)
  33. else
  34. bar.Text:SetFormattedText('%d / %d - %s', value - min, max - min, name)
  35. end
  36. end
  37. if(bar.PostUpdate) then bar.PostUpdate(self, event, unit, bar, min, max, value, name, id) end
  38. end
  39. local function enable(self, unit)
  40. local bar = self.Reputation
  41. if(bar and unit == 'player') then
  42. if(not bar:GetStatusBarTexture()) then
  43. bar:SetStatusBarTexture([=[Interface\TargetingFrame\UI-StatusBar]=])
  44. end
  45. self:RegisterEvent('UPDATE_FACTION', update)
  46. if(bar.Tooltip) then
  47. bar:EnableMouse()
  48. bar:HookScript('OnLeave', GameTooltip_Hide)
  49. bar:HookScript('OnEnter', tooltip)
  50. end
  51. return true
  52. end
  53. end
  54. local function disable(self)
  55. if(self.Reputation) then
  56. self:UnregisterEvent('UPDATE_FACTION', update)
  57. end
  58. end
  59. oUF:AddElement('Reputation', update, enable, disable)