Guest User

Untitled

a guest
Apr 21st, 2014
31
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.     db = Core.db.profile
  39.  
  40.     if enabled or not db.unitframes.enable then return end
  41.     enabled = true -- since most of this stuff is non-undoable (eg. hooksecurefunc)
  42.  
  43.     -- Update Unit Frames
  44.     for unit, func in pairs(self.UnitFunctions) do
  45.         if db.unitframes[unit].enable then
  46.             func(self)
  47.         end
  48.     end
  49.  
  50.     -- Change other frames' name backgrounds to match player frame
  51.     for _, region in pairs({
  52.         TargetFrameNameBackground,
  53.         FocusFrameNameBackground,
  54.         Boss1TargetFrameNameBackground,
  55.         Boss2TargetFrameNameBackground,
  56.         Boss3TargetFrameNameBackground,
  57.         Boss4TargetFrameNameBackground,
  58.     }) do
  59.         region:SetTexture(0, 0, 0, 0.5)
  60.     end
  61.    
  62.     -- Font Style / Color thanks to Phanx from WoWinterface.
  63.     hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
  64.         if value == 0 then
  65.             return fontString:SetText("")
  66.         end
  67.  
  68.         local style = GetCVar("statusTextDisplay")
  69.         if style == "PERCENT" then
  70.             return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
  71.         end
  72.         for i = 1, #shorts do
  73.             local t = shorts[i]
  74.             if value >= t[1] then
  75.                 if style == "BOTH" then
  76.                     return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
  77.                 else
  78.                     if value < valueMax then
  79.                         for j = 1, #shorts do
  80.                             local v = shorts[j]
  81.                             if valueMax >= v[1] then
  82.                                 return fontString:SetFormattedText(t[3] .. " / " .. v[3], value / t[2], valueMax / v[2])
  83.                             end
  84.                         end
  85.                     end
  86.                     return fontString:SetFormattedText(t[3], value / t[2])
  87.                 end
  88.             end
  89.         end
  90.     end)
  91.  
  92.     -- Font Color
  93.     hooksecurefunc("UnitFrame_Update", function(self, isParty)
  94.         if not self.name or not self:IsShown() then return end
  95.  
  96.         local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }
  97.         local unit, color = self.unit
  98.         if UnitPlayerControlled(unit) then
  99.             if UnitIsPlayer(unit) then
  100.                 local _, class = UnitClass(unit)
  101.                 color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  102.             else
  103.                 color = PET_COLOR
  104.             end
  105.         elseif UnitIsDeadOrGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
  106.             color = GRAY_FONT_COLOR
  107.         else
  108.             color = CUSTOM_FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
  109.         end
  110.  
  111.         if not color then
  112.             color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
  113.         end
  114.  
  115.         self.name:SetTextColor(color.r, color.g, color.b)
  116.         if isParty then
  117.             self.name:SetText(GetUnitName(self.overrideName or unit))
  118.         end
  119.     end)
  120. end
  121.  
  122. ------------------------------------------------------------------------
  123.  
  124. Module.UnitFunctions = {
  125.  
  126.     player = function(self)
  127.         PlayerFrame:SetScale(db.unitframes.player.scale)
  128.         PlayerFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize,"THINOUTLINE")
  129.         PlayerFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE")
  130.         PlayerFrameAlternateManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE")
  131.  
  132.         PetFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet,"THINOUTLINE")
  133.         PetFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet, "THINOUTLINE")
  134.  
  135.         -- Disable healing/damage spam over player/pet frame:
  136.         PlayerHitIndicator:SetText(nil)
  137.         PlayerHitIndicator.SetText = function() end
  138.         PetHitIndicator:SetText(nil)
  139.         PetHitIndicator.SetText = function() end
  140.     end,
  141.  
  142.     target = function(self)
  143.         TargetFrame:SetScale(db.unitframes.target.scale)
  144.         TargetFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE")
  145.         TargetFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE")
  146.     end,
  147.  
  148.     focus = function(self)
  149.         FocusFrame:SetScale(db.unitframes.focus.scale)
  150.         FocusFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE")
  151.         FocusFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE")
  152.     end,
  153.  
  154.     party = function(self)
  155.         for i = 1, MAX_PARTY_MEMBERS do
  156.             local partyFrame = "PartyMemberFrame"..i
  157.             _G[partyFrame]:SetScale(db.unitframes.party.scale)
  158.             _G[partyFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE")
  159.             _G[partyFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE")
  160.         end
  161.     end,
  162.  
  163.     arena = function(self)
  164.         for i = 1, MAX_ARENA_ENEMIES do
  165.             local prepFrame = "ArenaPrepFrame"..i
  166.             _G[prepFrame]:SetScale(db.unitframes.arena.scale)
  167.             _G[prepFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE")
  168.             _G[prepFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE")
  169.  
  170.             local arenaFrame = "ArenaEnemyFrame"..i
  171.             _G[arenaFrame]:SetScale(db.unitframes.arena.scale)
  172.             _G[arenaFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE")
  173.             _G[arenaFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE")
  174.         end
  175.     end,
  176.  
  177.     boss = function(self)
  178.         for i = 1, MAX_BOSS_FRAMES do
  179.             local bossFrame = "Boss"..i.."TargetFrame"
  180.             _G[bossFrame]:SetScale(db.unitframes.boss.scale)
  181.         end
  182.     end,
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment