Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Core = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
- local Module = Core:NewModule("Unitframes", "AceEvent-3.0")
- ----------------
- -- Unitframes --
- ----------------
- local CUSTOM_FACTION_BAR_COLORS = {
- [1] = {r = 1, g = 0, b = 0},
- [2] = {r = 1, g = 0, b = 0},
- [3] = {r = 1, g = 1, b = 0},
- [4] = {r = 1, g = 1, b = 0},
- [5] = {r = 0, g = 1, b = 0},
- [6] = {r = 0, g = 1, b = 0},
- [7] = {r = 0, g = 1, b = 0},
- [8] = {r = 0, g = 1, b = 0},
- }
- -- Font Style
- local shorts = {
- { 1e10, 1e9, "%.0fB" }, -- 10b+ as 12b
- { 1e9, 1e9, "%.1fB" }, -- 1b+ as 8.3b
- { 1e7, 1e6, "%.0fM" }, -- 10m+ as 14m
- { 1e6, 1e6, "%.1fM" }, -- 1m+ as 7.4m
- { 1e5, 1e3, "%.0fK" }, -- 100k+ as 840k
- { 1e3, 1e3, "%.1fK" }, -- 1k+ as 2.5k
- { 0, 1, "%d" }, -- < 1k as 974
- }
- for i = 1, #shorts do
- shorts[i][4] = shorts[i][3] .. " (%.0f%%)"
- end
- ------------------------------------------------------------------------
- local db, enabled
- function Module:OnEnable()
- if InCombatLockdown() then
- return self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEnable")
- end
- self:UnregisterEvent("PLAYER_REGEN_ENABLED")
- db = Core.db.profile
- if enabled or not db.unitframes.enable then return end
- enabled = true -- since most of this stuff is non-undoable (eg. hooksecurefunc)
- -- Update Unit Frames
- self:RunUnitFunctions("OnEnable")
- -- Change other frames' name backgrounds to match player frame
- for _, region in pairs({
- TargetFrameNameBackground,
- FocusFrameNameBackground,
- Boss1TargetFrameNameBackground,
- Boss2TargetFrameNameBackground,
- Boss3TargetFrameNameBackground,
- Boss4TargetFrameNameBackground,
- }) do
- region:SetTexture(0, 0, 0, 0.5)
- end
- -- Font Style / Color thanks to Phanx from WoWinterface.
- hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
- if value == 0 then
- return fontString:SetText("")
- end
- local style = GetCVar("statusTextDisplay")
- if style == "PERCENT" then
- return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
- end
- for i = 1, #shorts do
- local t = shorts[i]
- if value >= t[1] then
- if style == "BOTH" then
- return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100)
- else
- if value < valueMax then
- for j = 1, #shorts do
- local v = shorts[j]
- if valueMax >= v[1] then
- return fontString:SetFormattedText(t[3] .. " / " .. v[3], value / t[2], valueMax / v[2])
- end
- end
- end
- return fontString:SetFormattedText(t[3], value / t[2])
- end
- end
- end
- end)
- -- Font Color
- hooksecurefunc("UnitFrame_Update", function(self, isParty)
- if not self.name or not self:IsShown() then return end
- local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }
- local unit, color = self.unit
- if UnitPlayerControlled(unit) then
- if UnitIsPlayer(unit) then
- local _, class = UnitClass(unit)
- color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
- else
- color = PET_COLOR
- end
- elseif UnitIsDeadOrGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
- color = GRAY_FONT_COLOR
- else
- color = CUSTOM_FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
- end
- if not color then
- color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
- end
- self.name:SetTextColor(color.r, color.g, color.b)
- if isParty then
- self.name:SetText(GetUnitName(self.overrideName or unit))
- end
- end)
- end
- function Module:RunUnitFunctions(event, addon)
- if not InCombatLockdown() then
- for unit, func in pairs(self.UnitFunctions) do
- if db.unitframes[unit].enable then
- if not func(self) then
- self.UnitFunctions[unit] = nil
- end
- end
- end
- end
- if next(self.UnitFunctions) then
- -- Something wasn't able to run, try again later.
- self:RegisterEvent("ADDON_LOADED", "RunUnitFunctions")
- else
- -- All done.
- self:UnregisterEvent("ADDON_LOADED")
- end
- end
- ------------------------------------------------------------------------
- Module.UnitFunctions = {
- player = function(self)
- PlayerFrame:SetScale(db.unitframes.player.scale)
- PlayerFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize,"THINOUTLINE")
- PlayerFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE")
- PlayerFrameAlternateManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE")
- PetFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet,"THINOUTLINE")
- PetFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet, "THINOUTLINE")
- -- Disable healing/damage spam over player/pet frame:
- PlayerHitIndicator:SetText(nil)
- PlayerHitIndicator.SetText = function() end
- PetHitIndicator:SetText(nil)
- PetHitIndicator.SetText = function() end
- end,
- target = function(self)
- TargetFrame:SetScale(db.unitframes.target.scale)
- TargetFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE")
- TargetFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE")
- end,
- focus = function(self)
- FocusFrame:SetScale(db.unitframes.focus.scale)
- FocusFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE")
- FocusFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE")
- end,
- party = function(self)
- for i = 1, MAX_PARTY_MEMBERS do
- local partyFrame = "PartyMemberFrame"..i
- _G[partyFrame]:SetScale(db.unitframes.party.scale)
- _G[partyFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE")
- _G[partyFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE")
- end
- end,
- arena = function(self)
- if not ArenaEnemyFrame1 then
- return true
- end
- for i = 1, MAX_ARENA_ENEMIES do
- local prepFrame = "ArenaPrepFrame"..i
- _G[prepFrame]:SetScale(db.unitframes.arena.scale)
- _G[prepFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE")
- _G[prepFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE")
- local arenaFrame = "ArenaEnemyFrame"..i
- _G[arenaFrame]:SetScale(db.unitframes.arena.scale)
- _G[arenaFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE")
- _G[arenaFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE")
- end
- end,
- boss = function(self)
- for i = 1, MAX_BOSS_FRAMES do
- local bossFrame = "Boss"..i.."TargetFrame"
- _G[bossFrame]:SetScale(db.unitframes.boss.scale)
- end
- end,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement