Advertisement
Guest User

Unitframes.lua

a guest
Nov 30th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. local _, ns = ...
  2.  
  3. if ns.unitframesEnable ~= true then return end
  4.  
  5. _G["PlayerName"]:SetFont([[Interface\AddOns\CokeUI\Media\Expressway_Rg _BOLD.ttf]], 16)
  6. _G["TargetFrameTextureFrameName"]:SetFont([[Interface\AddOns\CokeUI\Media\Expressway_Rg _BOLD.ttf]], 16)
  7. _G["FocusFrameTextureFrameName"]:SetFont([[Interface\AddOns\CokeUI\Media\Expressway_Rg _BOLD.ttf]], 16)
  8.  
  9. local CUSTOM_FACTION_BAR_COLORS = {
  10. [1] = {r = 1, g = 0, b = 0},
  11. [2] = {r = 1, g = 0, b = 0},
  12. [3] = {r = 1, g = 1, b = 0},
  13. [4] = {r = 1, g = 1, b = 0},
  14. [5] = {r = 0, g = 1, b = 0},
  15. [6] = {r = 0, g = 1, b = 0},
  16. [7] = {r = 0, g = 1, b = 0},
  17. [8] = {r = 0, g = 1, b = 0},
  18. }
  19.  
  20. -- Font Style
  21. local shorts = {
  22. { 1e10, 1e9, "%.0fB" }, -- 10b+ as 12B
  23. { 1e9, 1e9, "%.1fB" }, -- 1b+ as 8.3B
  24. { 1e7, 1e6, "%.0fM" }, -- 10m+ as 14M
  25. { 1e6, 1e6, "%.1fM" }, -- 1m+ as 7.4M
  26. { 1e5, 1e3, "%.0fK" }, -- 100k+ as 840K
  27. { 1e3, 1e3, "%.1fK" }, -- 1k+ as 2.5K
  28. { 0, 1, "%d" }, -- < 1k as 974
  29. }
  30. for i = 1, #shorts do
  31. shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
  32. end
  33.  
  34. -- Change other frames' name backgrounds to match player frame
  35. for _, region in pairs({
  36. TargetFrameNameBackground,
  37. FocusFrameNameBackground,
  38. Boss1TargetFrameNameBackground,
  39. Boss2TargetFrameNameBackground,
  40. Boss3TargetFrameNameBackground,
  41. Boss4TargetFrameNameBackground,
  42. Boss5TargetFrameNameBackground,
  43.  
  44. }) do
  45. region:SetTexture(0, 0, 0, 0.5)
  46. end
  47.  
  48. -- Font Style / Color thanks to Phanx from WoWinterface.
  49. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, textString, value, valueMin, valueMax)
  50. if value == 0 then
  51. return textString:SetText("")
  52. end
  53.  
  54. local style = GetCVar("statusTextDisplay")
  55. if style == "PERCENT" then
  56. return textString:SetFormattedText("%.0f%%", value / valueMax * 100)
  57. end
  58. for i = 1, #shorts do
  59. local t = shorts[i]
  60. if value >= t[1] then
  61. if style == "BOTH" then
  62. return textString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  63. else
  64. if value < valueMax then
  65. for j = 1, #shorts do
  66. local v = shorts[j]
  67. if valueMax >= v[1] then
  68. return textString:SetFormattedText(t[3] .. " / " .. v[3], value / t[2], valueMax / v[2])
  69. end
  70. end
  71. end
  72. return textString:SetFormattedText(t[3], value / t[2])
  73. end
  74. end
  75. end
  76. end)
  77.  
  78. -- Font Color
  79. hooksecurefunc("UnitFrame_Update", function(self, isParty)
  80. if not self.name or not self:IsShown() then return end
  81.  
  82. local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }
  83. local unit, color = self.unit
  84. if UnitPlayerControlled(unit) then
  85. if UnitIsPlayer(unit) then
  86. local _, class = UnitClass(unit)
  87. color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  88. else
  89. color = PET_COLOR
  90. end
  91. elseif UnitIsDeadOrGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
  92. color = GRAY_FONT_COLOR
  93. else
  94. color = CUSTOM_FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
  95. end
  96.  
  97. if not color then
  98. color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
  99. end
  100.  
  101. self.name:SetTextColor(color.r, color.g, color.b)
  102. if isParty then
  103. self.name:SetText(GetUnitName(self.overrideName or unit))
  104. end
  105. end)
  106.  
  107. -- Player Frame
  108. CastingBarFrame:SetScale(ns.unitframesCastbarScale)
  109. PlayerFrame:SetScale(ns.unitframesPlayerScale)
  110. PlayerLevelText:ClearAllPoints()
  111. PlayerLevelText:SetPoint('CENTER', PlayerFrame, -61, -16)
  112.  
  113. -- Target Frame
  114. TargetFrame:SetScale(ns.unitframesTargetScale)
  115. TargetFrameLevelText:ClearAllPoints()
  116. TargetFrameLevelText:SetPoint('CENTER', TargetFrameTextureFrame, 61, 16)
  117.  
  118. -- Focus Frame
  119. FocusFrame:SetScale(ns.unitframesFocusScale)
  120. FocusFrameLevelText:ClearAllPoints()
  121. FocusFrameLevelText:SetPoint('CENTER', FocusFrameTextureFrame, 61, 16)
  122.  
  123.  
  124. if not ArenaEnemyFrame1 then
  125. return true
  126. end
  127.  
  128. -- Arena
  129. for i = 1, MAX_ARENA_ENEMIES do
  130. _G["ArenaPrepFrame"..i]:SetScale(ns.unitframesArenaScale)
  131. _G["ArenaEnemyFrame"..i]:SetScale(ns.unitframesArenaScale)
  132. end
  133.  
  134. -- Boss
  135. SecureHandlerWrapScript(Boss1TargetFrame, 'OnShow', Boss1TargetFrame, 'self:SetScale('..ns.unitframesBossScale..')')
  136. SecureHandlerWrapScript(Boss2TargetFrame, 'OnShow', Boss2TargetFrame, 'self:SetScale('..ns.unitframesBossScale..')')
  137. SecureHandlerWrapScript(Boss3TargetFrame, 'OnShow', Boss3TargetFrame, 'self:SetScale('..ns.unitframesBossScale..')')
  138. SecureHandlerWrapScript(Boss4TargetFrame, 'OnShow', Boss4TargetFrame, 'self:SetScale('..ns.unitframesBossScale..')')
  139. SecureHandlerWrapScript(Boss5TargetFrame, 'OnShow', Boss5TargetFrame, 'self:SetScale('..ns.unitframesBossScale..')')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement