/Tukui/modules/databars/reputation.lua

http://github.com/Asphyxia/Tukui · Lua · 142 lines · 118 code · 23 blank · 1 comment · 22 complexity · 0b2ede86dbfde2960939dcf97d6c531c MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. if C["databars"].reputation == true then
  3. -- REPUTATION DATABARS
  4. local RepData = {}
  5. local db = C["databars"].reps
  6. local standing = {
  7. [-6000] = {255/255, 0, 51/255}, -- Hated :(
  8. [-3000] = {255/255, 0, 51/255}, -- Hostile
  9. [0] = {255/255, 0, 51/255}, -- Unfriendly
  10. [3000] = {255/255, 204/255, 102/255},-- Neutral
  11. [9000] = {75/255, 175/255, 76/255}, -- Friendly
  12. [21000] = {75/255, 175/255, 76/255}, -- Honored
  13. [42000] = {75/255, 175/255, 76/255}, -- Revered
  14. [43000] = {75/255, 175/255, 76/255}, -- Exalted
  15. }
  16. for i = 1, GetNumFactions() do
  17. local name, _, _, bottomValue, topValue, earnedValue, _, _, _, _, _, _, _ = GetFactionInfo(i)
  18. local min, max = earnedValue-bottomValue, topValue-bottomValue
  19. if name == db[1] or name == db[2] or name == db[3] or name == db[4] or name == db[5] then
  20. local frame = CreateFrame("Frame", "RepData"..i, UIParent)
  21. frame:CreatePanel("Transparent", TukuiMinimap:GetWidth(), 18, "CENTER", UIParent, "CENTER", 0, 0)
  22. frame:EnableMouse(true)
  23. frame:Animate(160, 0, 0.4)
  24. frame:Hide()
  25. if T.Hydra then frame:SetBorder() end
  26. frame.Status = CreateFrame("StatusBar", "RepDataStatus"..i, frame)
  27. frame.Status:SetFrameLevel(12)
  28. frame.Status:SetStatusBarTexture(C["media"].normTex)
  29. frame.Status:SetMinMaxValues(0, max)
  30. frame.Status:SetValue(min)
  31. frame.Status:SetStatusBarColor(unpack(standing[topValue]))
  32. frame.Status:Point("TOPLEFT", frame, "TOPLEFT", 2, -2)
  33. frame.Status:Point("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2)
  34. frame.Text = frame.Status:CreateFontString(nil, "OVERLAY")
  35. frame.Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  36. frame.Text:Point("LEFT", frame, "LEFT", 6, 2)
  37. frame.Text:SetShadowColor(0, 0, 0)
  38. frame.Text:SetShadowOffset(1.25, -1.25)
  39. frame.Text:SetText(format("%s / %s", min, max))
  40. frame.Text:Hide()
  41. frame.Name = frame.Status:CreateFontString(nil, "OVERLAY")
  42. frame.Name:SetFont(C.media.pixelfont, C["datatext"].fontsize+1, "MONOCHROMEOUTLINE")
  43. frame.Name:Point("LEFT", frame, "LEFT", 6, 2)
  44. frame.Name:SetShadowColor(0, 0, 0)
  45. frame.Name:SetShadowOffset(1.25, -1.25)
  46. frame.Name:SetText(name)
  47. frame:SetScript("OnEnter", function(self)
  48. self.Name:Hide()
  49. self.Text:Show()
  50. end)
  51. frame:SetScript("OnLeave", function(self)
  52. self.Name:Show()
  53. self.Text:Hide()
  54. end)
  55. frame.id = i
  56. frame.Status = frame.Status
  57. frame.Text = frame.Text
  58. tinsert(RepData, frame)
  59. end
  60. end
  61. for key, frame in ipairs(RepData) do
  62. frame:ClearAllPoints()
  63. if key == 1 then
  64. frame:Point("TOP", TukuiMinimap, "BOTTOM", 0, -3)
  65. else
  66. frame:Point("TOP", RepData[key-1], "BOTTOM", 0, -3)
  67. end
  68. end
  69. local update = function()
  70. for _, frame in ipairs(RepData) do
  71. local name, _, _, bottomValue, topValue, earnedValue, _, _, _, _, _, _, _ = GetFactionInfo(frame.id)
  72. local min, max = earnedValue-bottomValue, topValue-bottomValue
  73. frame.Status:SetValue(min)
  74. frame.Text:SetText(format("%s / %s", min, max))
  75. end
  76. end
  77. local function ModifiedBackdrop(self)
  78. local color = RAID_CLASS_COLORS[T.myclass]
  79. self:SetBackdropColor(color.r*.15, color.g*.15, color.b*.15)
  80. self:SetBackdropBorderColor(color.r, color.g, color.b)
  81. end
  82. local function OriginalBackdrop(self)
  83. self:SetTemplate("Default")
  84. end
  85. local toggle = CreateFrame("Frame", "RepToggle", TukuiChatBackgroundRight)
  86. toggle:CreatePanel(nil, 30, 15, "TOPRIGHT", TukuiChatBackgroundRight, "TOPRIGHT", -2, -52)
  87. toggle:EnableMouse(true)
  88. toggle:SetFrameStrata("MEDIUM")
  89. toggle:SetFrameLevel(10)
  90. toggle:CreateShadow("Default")
  91. toggle:CreateOverlay(toggle)
  92. toggle:SetAlpha(0)
  93. toggle:HookScript("OnEnter", ModifiedBackdrop)
  94. toggle:HookScript("OnLeave", OriginalBackdrop)
  95. toggle:SetScript("OnEnter", function()
  96. if InCombatLockdown() then return end
  97. toggle:FadeIn()
  98. end)
  99. toggle:SetScript("OnLeave", function()
  100. toggle:FadeOut()
  101. end)
  102. toggle.Text = toggle:CreateFontString(nil, "OVERLAY")
  103. toggle.Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  104. toggle.Text:Point("CENTER", toggle, "CENTER", 1, 1)
  105. toggle.Text:SetText(T.datacolor.."R")
  106. toggle:SetScript("OnMouseUp", function(self)
  107. for _, frame in pairs(RepData) do
  108. if frame and frame:IsVisible() then
  109. frame:SlideOut()
  110. else
  111. frame:SlideIn()
  112. end
  113. end
  114. end)
  115. local updater = CreateFrame("Frame")
  116. updater:RegisterEvent("PLAYER_ENTERING_WORLD")
  117. updater:RegisterEvent("UPDATE_FACTION")
  118. updater:SetScript("OnEvent", update)
  119. end