Advertisement
Guest User

Unitframes.lua

a guest
Apr 21st, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.26 KB | None | 0 0
  1. local Core = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
  2. local Module = Core:NewModule("Unitframes", "AceEvent-3.0")
  3.  
  4. ----------------
  5. -- Unitframes --
  6. ----------------
  7.  
  8. local CUSTOM_FACTION_BAR_COLORS = {
  9. [1] = {r = 1, g = 0, b = 0},
  10. [2] = {r = 1, g = 0, b = 0},
  11. [3] = {r = 1, g = 1, b = 0},
  12. [4] = {r = 1, g = 1, b = 0},
  13. [5] = {r = 0, g = 1, b = 0},
  14. [6] = {r = 0, g = 1, b = 0},
  15. [7] = {r = 0, g = 1, b = 0},
  16. [8] = {r = 0, g = 1, b = 0},
  17. }
  18.  
  19. function Module:UpdatePlayerFrame()
  20. local db = Core.db.profile
  21.  
  22. if db.unitframes.player.enable ~= true then return end
  23.  
  24. local PlayerEventFrame = CreateFrame("Frame")
  25. PlayerEventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  26. PlayerEventFrame:SetScript("OnEvent", function(self, event, ...)
  27. if UnitAffectingCombat("player") then return end
  28.  
  29. if event == "PLAYER_ENTERING_WORLD" then
  30. PlayerFrame:SetScale(db.unitframes.player.scale);
  31. PlayerFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize,"THINOUTLINE");
  32. PlayerFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE");
  33. PlayerFrameAlternateManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE");
  34. PetFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet,"THINOUTLINE");
  35. PetFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet, "THINOUTLINE");
  36. else
  37. return
  38. end
  39. end)
  40. end
  41.  
  42. function Module:UpdateTargetFrame()
  43. local db = Core.db.profile
  44.  
  45. if db.unitframes.target.enable ~= true then return end
  46.  
  47. local TargetEventFrame = CreateFrame("Frame")
  48. TargetEventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
  49. TargetEventFrame:SetScript("OnEvent", function(self, event, ...)
  50. if UnitAffectingCombat("player") then return end
  51.  
  52. if event == "PLAYER_ENTERING_WORLD" then
  53. TargetFrame:SetScale(db.unitframes.target.scale);
  54. TargetFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE");
  55. TargetFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE");
  56. else
  57. return
  58. end
  59. end)
  60. end
  61.  
  62. function Module:UpdateFocusFrame()
  63. local db = Core.db.profile
  64.  
  65. if db.unitframes.focus.enable ~= true then return end
  66.  
  67. local FocusEventFrame = CreateFrame("Frame")
  68. FocusEventFrame:RegisterEvent("PLAYER_FOCUS_CHANGED")
  69. FocusEventFrame:SetScript("OnEvent", function(self, event, ...)
  70. if UnitAffectingCombat("player") then return end
  71.  
  72. if event == "PLAYER_FOCUS_CHANGED" then
  73. FocusFrame:SetScale(db.unitframes.focus.scale);
  74. FocusFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE");
  75. FocusFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE");
  76. else
  77. return
  78. end
  79. end)
  80. end
  81.  
  82. function Module:UpdatePartyMembersFrame()
  83. local db = Core.db.profile
  84.  
  85. if db.unitframes.party.enable ~= true then return end
  86.  
  87. local PartyMembersEventFrame = CreateFrame("Frame")
  88. PartyMembersEventFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
  89. PartyMembersEventFrame:SetScript("OnEvent", function(self, event, ...)
  90. if UnitAffectingCombat("player") then return end
  91.  
  92. if event == "GROUP_ROSTER_UPDATE" then
  93. for i = 1, MAX_PARTY_MEMBERS do
  94. local partyFrame = "PartyMemberFrame"..i
  95. _G[partyFrame]:SetScale(db.unitframes.party.scale);
  96. _G[partyFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
  97. _G[partyFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
  98. end
  99. else
  100. return
  101. end
  102. end)
  103. end
  104.  
  105. function Module:UpdateArenaFrame()
  106. local db = Core.db.profile
  107.  
  108. if db.unitframes.arena.enable ~= true then return end
  109.  
  110. local ArenaEventFrame = CreateFrame("Frame")
  111. ArenaEventFrame:RegisterEvent("BATTLEFIELDS_SHOW")
  112. ArenaEventFrame:SetScript("OnEvent", function(self, event, ...)
  113. if UnitAffectingCombat("player") then return end
  114.  
  115. if event == "BATTLEFIELDS_SHOW" then
  116. for i = 1, MAX_ARENA_ENEMIES do
  117. arenaFrame = "ArenaEnemyFrame"..i
  118. _G[arenaFrame]:SetScale(db.unitframes.arena.scale);
  119. _G[arenaFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE");
  120. _G[arenaFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE");
  121. end
  122. else
  123. return
  124. end
  125. end)
  126. end
  127.  
  128. function Module:UpdateBossFrame()
  129. local db = Core.db.profile
  130.  
  131. if db.unitframes.boss.enable ~= true then return end
  132.  
  133. local BossEventFrame = CreateFrame("Frame");
  134. BossEventFrame:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT");
  135. BossEventFrame:SetScript("OnEvent", function(self, event, ...)
  136. if UnitAffectingCombat("player") then return end
  137.  
  138. if event == "INSTANCE_ENCOUNTER_ENGAGE_UNIT" then
  139. for i = 1, MAX_BOSS_FRAMES do
  140. local bossFrame = "Boss"..i.."TargetFrame"
  141. _G[bossFrame]:SetScale(db.unitframes.boss.scale);
  142. end
  143. else
  144. return
  145. end
  146. end)
  147. end
  148.  
  149. local function SetUnitFontStyle()
  150.  
  151. -- Font Style / Color thanks to Phanx from WoWinterface.
  152.  
  153. -- Font Style
  154. local shorts = {
  155. { 1e10, 1e9, "%.0fB" }, -- 10b+ as 12b
  156. { 1e9, 1e9, "%.1fB" }, -- 1b+ as 8.3b
  157. { 1e7, 1e6, "%.0fM" }, -- 10m+ as 14m
  158. { 1e6, 1e6, "%.1fM" }, -- 1m+ as 7.4m
  159. { 1e5, 1e3, "%.0fK" }, -- 100k+ as 840k
  160. { 1e3, 1e3, "%.1fK" }, -- 1k+ as 2.5k
  161. { 0, 1, "%d" }, -- < 1k as 974
  162. }
  163. for i = 1, #shorts do
  164. shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
  165. end
  166.  
  167. hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
  168. if value == 0 then
  169. return fontString:SetText("")
  170. end
  171.  
  172. local style = GetCVar("statusTextDisplay")
  173. if style == "PERCENT" then
  174. return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
  175. end
  176. for i = 1, #shorts do
  177. local t = shorts[i]
  178. if value >= t[1] then
  179. if style == "BOTH" then
  180. return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  181. else
  182. if value < valueMax then
  183. for j = 1, #shorts do
  184. local v = shorts[j]
  185. if valueMax >= v[1] then
  186. return fontString:SetFormattedText(t[3] .. " / " .. v[3], value / t[2], valueMax / v[2])
  187. end
  188. end
  189. end
  190. return fontString:SetFormattedText(t[3], value / t[2])
  191. end
  192. end
  193. end
  194. end)
  195. -- Font Color
  196. hooksecurefunc("UnitFrame_Update", function(self, isParty)
  197. if not self.name or not self:IsShown() then return end
  198.  
  199. local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }
  200. local unit, color = self.unit
  201. if UnitPlayerControlled(unit) then
  202. if UnitIsPlayer(unit) then
  203. local _, class = UnitClass(unit)
  204. color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  205. else
  206. color = PET_COLOR
  207. end
  208. elseif UnitIsDeadOrGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
  209. color = GRAY_FONT_COLOR
  210. else
  211. color = CUSTOM_FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
  212. end
  213.  
  214. if not color then
  215. color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
  216. end
  217.  
  218. self.name:SetTextColor(color.r, color.g, color.b)
  219. if isParty then
  220. self.name:SetText(GetUnitName(self.overrideName or unit))
  221. end
  222. end)
  223. end
  224.  
  225. function Module:OnEnable()
  226. local db = Core.db.profile
  227.  
  228. if db.unitframes.enable ~= true then return end
  229.  
  230. -- Update Unit Frames
  231. self:UpdatePlayerFrame();
  232. self:UpdateTargetFrame();
  233. self:UpdateFocusFrame();
  234. self:UpdatePartyMembersFrame();
  235. self:UpdateArenaFrame();
  236. self:UpdateBossFrame();
  237.  
  238. -- Set the Font for Unit Frames
  239. SetUnitFontStyle();
  240.  
  241. -- Change other Texture to match player frame
  242. for _, region in pairs({
  243. TargetFrameNameBackground,
  244. FocusFrameNameBackground,
  245. Boss1TargetFrameNameBackground,
  246. Boss2TargetFrameNameBackground,
  247. Boss3TargetFrameNameBackground,
  248. Boss4TargetFrameNameBackground,
  249. }) do
  250. region:SetTexture([[Interface\DialogFrame\UI-DialogBox-Background]])
  251. end
  252.  
  253. -- Disable healing/damage spam over player/pet frame:
  254. PlayerHitIndicator:SetText(nil)
  255. PlayerHitIndicator.SetText = function() end
  256. PetHitIndicator:SetText(nil)
  257. PetHitIndicator.SetText = function() end
  258. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement