Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. -- Font Style
  20. local shorts = {
  21.     { 1e10, 1e9, "%.0fB" }, --  10b+ as  12b
  22.     {  1e9, 1e9, "%.1fB" }, --   1b+ as 8.3b
  23.     {  1e7, 1e6, "%.0fM" }, --  10m+ as  14m
  24.     {  1e6, 1e6, "%.1fM" }, --   1m+ as 7.4m
  25.     {  1e5, 1e3, "%.0fK" }, -- 100k+ as 840k
  26.     {  1e3, 1e3, "%.1fK" }, --   1k+ as 2.5k
  27.     {    0,   1,    "%d" }, -- < 1k  as  974
  28. }
  29. for i = 1, #shorts do
  30.     shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
  31. end
  32.  
  33. ------------------------------------------------------------------------
  34.  
  35. local db, enabled
  36.  
  37. function Module:OnEnable()
  38.     if InCombatLockdown() then
  39.         return self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEnable")
  40.     end
  41.     self:UnregisterEvent("PLAYER_REGEN_ENABLED")
  42.  
  43.     db = Core.db.profile
  44.  
  45.     if enabled or not db.unitframes.enable then return end
  46.     enabled = true -- since most of this stuff is non-undoable (eg. hooksecurefunc)
  47.  
  48.     -- Update Unit Frames
  49.     self:ApplySettings()
  50.  
  51.     -- Disable healing/damage spam over player/pet frame:
  52.     PlayerHitIndicator:SetText(nil)
  53.     PlayerHitIndicator.SetText = function() end
  54.     PetHitIndicator:SetText(nil)
  55.     PetHitIndicator.SetText = function() end
  56.  
  57.     -- Change other frames' name backgrounds to match player frame
  58.     for _, region in pairs({
  59.         TargetFrameNameBackground,
  60.         FocusFrameNameBackground,
  61.         Boss1TargetFrameNameBackground,
  62.         Boss2TargetFrameNameBackground,
  63.         Boss3TargetFrameNameBackground,
  64.         Boss4TargetFrameNameBackground,
  65.     }) do
  66.         region:SetTexture(0, 0, 0, 0.5)
  67.     end
  68.    
  69.     -- Font Style / Color thanks to Phanx from WoWinterface.
  70.     hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
  71.         if value == 0 then
  72.             return fontString:SetText("")
  73.         end
  74.  
  75.         local style = GetCVar("statusTextDisplay")
  76.         if style == "PERCENT" then
  77.             return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
  78.         end
  79.         for i = 1, #shorts do
  80.             local t = shorts[i]
  81.             if value >= t[1] then
  82.                 if style == "BOTH" then
  83.                     return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  84.                 else
  85.                     if value < valueMax then
  86.                         for j = 1, #shorts do
  87.                             local v = shorts[j]
  88.                             if valueMax >= v[1] then
  89.                                 return fontString:SetFormattedText(t[3] .. " / " .. v[3], value / t[2], valueMax / v[2])
  90.                             end
  91.                         end
  92.                     end
  93.                     return fontString:SetFormattedText(t[3], value / t[2])
  94.                 end
  95.             end
  96.         end
  97.     end)
  98.  
  99.     -- Font Color
  100.     hooksecurefunc("UnitFrame_Update", function(self, isParty)
  101.         if not self.name or not self:IsShown() then return end
  102.  
  103.         local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }
  104.         local unit, color = self.unit
  105.         if UnitPlayerControlled(unit) then
  106.             if UnitIsPlayer(unit) then
  107.                 local _, class = UnitClass(unit)
  108.                 color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  109.             else
  110.                 color = PET_COLOR
  111.             end
  112.         elseif UnitIsDeadOrGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
  113.             color = GRAY_FONT_COLOR
  114.         else
  115.             color = CUSTOM_FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
  116.         end
  117.  
  118.         if not color then
  119.             color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
  120.         end
  121.  
  122.         self.name:SetTextColor(color.r, color.g, color.b)
  123.         if isParty then
  124.             self.name:SetText(GetUnitName(self.overrideName or unit))
  125.         end
  126.     end)
  127. end
  128.  
  129. function Module:ApplySettings(event)
  130.     if event then
  131.         self:UnregisterEvent(event)
  132.     end
  133.  
  134.     if InCombatLockdown() then
  135.         return self:RegisterEvent("PLAYER_REGEN_ENABLED", "ApplySettings")
  136.     end
  137.  
  138.     local failure
  139.     for unit, func in pairs(self.UnitFunctions) do
  140.         if db.unitframes[unit].enable then
  141.             if func(self) then
  142.                 failure = true
  143.             end
  144.         end
  145.     end
  146.    
  147.     if failure then
  148.         self:RegisterEvent("ADDON_LOADED", "ApplySettings")
  149.     end
  150. end
  151.  
  152. ------------------------------------------------------------------------
  153.  
  154. Module.UnitFunctions = {
  155.  
  156.     player = function(self)
  157.         PlayerFrame:SetScale(db.unitframes.player.scale)
  158.         PlayerFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize,"THINOUTLINE")
  159.         PlayerFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE")
  160.         PlayerFrameAlternateManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE")
  161.  
  162.         PetFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet,"THINOUTLINE")
  163.         PetFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet, "THINOUTLINE")
  164.     end,
  165.  
  166.     target = function(self)
  167.         TargetFrame:SetScale(db.unitframes.target.scale)
  168.         TargetFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE")
  169.         TargetFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE")
  170.     end,
  171.  
  172.     focus = function(self)
  173.         FocusFrame:SetScale(db.unitframes.focus.scale)
  174.         FocusFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE")
  175.         FocusFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE")
  176.     end,
  177.  
  178.     party = function(self)
  179.         for i = 1, MAX_PARTY_MEMBERS do
  180.             local partyFrame = "PartyMemberFrame"..i
  181.             _G[partyFrame]:SetScale(db.unitframes.party.scale)
  182.             _G[partyFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE")
  183.             _G[partyFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE")
  184.         end
  185.     end,
  186.  
  187.     arena = function(self)
  188.         if not ArenaEnemyFrame1 then
  189.             return true
  190.         end
  191.  
  192.         for i = 1, MAX_ARENA_ENEMIES do
  193.             local prepFrame = "ArenaPrepFrame"..i
  194.             _G[prepFrame]:SetScale(db.unitframes.arena.scale)
  195.             _G[prepFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE")
  196.             _G[prepFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE")
  197.  
  198.             local arenaFrame = "ArenaEnemyFrame"..i
  199.             _G[arenaFrame]:SetScale(db.unitframes.arena.scale)
  200.             _G[arenaFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE")
  201.             _G[arenaFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE")
  202.         end
  203.     end,
  204.  
  205.     boss = function(self)
  206.         for i = 1, MAX_BOSS_FRAMES do
  207.             local bossFrame = "Boss"..i.."TargetFrame"
  208.             _G[bossFrame]:SetScale(db.unitframes.boss.scale)
  209.         end
  210.     end,
  211.  
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement