SHOW:
|
|
- or go back to the newest paste.
| 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 | - | for unit, func in pairs(self.UnitFunctions) do |
| 49 | + | self:RunUnitFunctions("OnEnable")
|
| 50 | - | if db.unitframes[unit].enable then |
| 50 | + | |
| 51 | - | func(self) |
| 51 | + | |
| 52 | for _, region in pairs({
| |
| 53 | TargetFrameNameBackground, | |
| 54 | FocusFrameNameBackground, | |
| 55 | Boss1TargetFrameNameBackground, | |
| 56 | Boss2TargetFrameNameBackground, | |
| 57 | Boss3TargetFrameNameBackground, | |
| 58 | Boss4TargetFrameNameBackground, | |
| 59 | }) do | |
| 60 | region:SetTexture(0, 0, 0, 0.5) | |
| 61 | end | |
| 62 | ||
| 63 | -- Font Style / Color thanks to Phanx from WoWinterface. | |
| 64 | hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
| |
| 65 | if value == 0 then | |
| 66 | return fontString:SetText("")
| |
| 67 | end | |
| 68 | ||
| 69 | local style = GetCVar("statusTextDisplay")
| |
| 70 | if style == "PERCENT" then | |
| 71 | return fontString:SetFormattedText("%.0f%%", value / valueMax * 100)
| |
| 72 | end | |
| 73 | for i = 1, #shorts do | |
| 74 | local t = shorts[i] | |
| 75 | if value >= t[1] then | |
| 76 | if style == "BOTH" then | |
| 77 | return fontString:SetFormattedText(t[4], value / t[2], value / valueMax * 100) | |
| 78 | else | |
| 79 | if value < valueMax then | |
| 80 | for j = 1, #shorts do | |
| 81 | local v = shorts[j] | |
| 82 | if valueMax >= v[1] then | |
| 83 | return fontString:SetFormattedText(t[3] .. " / " .. v[3], value / t[2], valueMax / v[2]) | |
| 84 | end | |
| 85 | end | |
| 86 | end | |
| 87 | return fontString:SetFormattedText(t[3], value / t[2]) | |
| 88 | end | |
| 89 | end | |
| 90 | end | |
| 91 | end) | |
| 92 | ||
| 93 | -- Font Color | |
| 94 | hooksecurefunc("UnitFrame_Update", function(self, isParty)
| |
| 95 | if not self.name or not self:IsShown() then return end | |
| 96 | ||
| 97 | local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }
| |
| 98 | local unit, color = self.unit | |
| 99 | if UnitPlayerControlled(unit) then | |
| 100 | if UnitIsPlayer(unit) then | |
| 101 | local _, class = UnitClass(unit) | |
| 102 | color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class] | |
| 103 | else | |
| 104 | color = PET_COLOR | |
| 105 | end | |
| 106 | elseif UnitIsDeadOrGhost(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then | |
| 107 | color = GRAY_FONT_COLOR | |
| 108 | else | |
| 109 | color = CUSTOM_FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5] | |
| 110 | end | |
| 111 | ||
| 112 | if not color then | |
| 113 | color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"] | |
| 114 | end | |
| 115 | ||
| 116 | self.name:SetTextColor(color.r, color.g, color.b) | |
| 117 | if isParty then | |
| 118 | self.name:SetText(GetUnitName(self.overrideName or unit)) | |
| 119 | end | |
| 120 | end) | |
| 121 | end | |
| 122 | ||
| 123 | function Module:RunUnitFunctions(event, addon) | |
| 124 | if not InCombatLockdown() then | |
| 125 | for unit, func in pairs(self.UnitFunctions) do | |
| 126 | if db.unitframes[unit].enable then | |
| 127 | if not func(self) then | |
| 128 | self.UnitFunctions[unit] = nil | |
| 129 | end | |
| 130 | end | |
| 131 | end | |
| 132 | end | |
| 133 | if next(self.UnitFunctions) then | |
| 134 | -- Something wasn't able to run, try again later. | |
| 135 | self:RegisterEvent("ADDON_LOADED", "RunUnitFunctions")
| |
| 136 | else | |
| 137 | -- All done. | |
| 138 | self:UnregisterEvent("ADDON_LOADED")
| |
| 139 | end | |
| 140 | end | |
| 141 | ||
| 142 | ------------------------------------------------------------------------ | |
| 143 | ||
| 144 | Module.UnitFunctions = {
| |
| 145 | ||
| 146 | player = function(self) | |
| 147 | PlayerFrame:SetScale(db.unitframes.player.scale) | |
| 148 | PlayerFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize,"THINOUTLINE") | |
| 149 | PlayerFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE") | |
| 150 | PlayerFrameAlternateManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSize, "THINOUTLINE") | |
| 151 | ||
| 152 | PetFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet,"THINOUTLINE") | |
| 153 | PetFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.player.fontSizepet, "THINOUTLINE") | |
| 154 | ||
| 155 | -- Disable healing/damage spam over player/pet frame: | |
| 156 | PlayerHitIndicator:SetText(nil) | |
| 157 | PlayerHitIndicator.SetText = function() end | |
| 158 | PetHitIndicator:SetText(nil) | |
| 159 | PetHitIndicator.SetText = function() end | |
| 160 | end, | |
| 161 | ||
| 162 | target = function(self) | |
| 163 | TargetFrame:SetScale(db.unitframes.target.scale) | |
| 164 | TargetFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE") | |
| 165 | TargetFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.target.fontSize, "THINOUTLINE") | |
| 166 | end, | |
| 167 | ||
| 168 | focus = function(self) | |
| 169 | FocusFrame:SetScale(db.unitframes.focus.scale) | |
| 170 | FocusFrameTextureFrameHealthBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE") | |
| 171 | FocusFrameTextureFrameManaBarText:SetFont(db.media.fontNormal, db.unitframes.focus.fontSize,"THINOUTLINE") | |
| 172 | end, | |
| 173 | ||
| 174 | party = function(self) | |
| 175 | for i = 1, MAX_PARTY_MEMBERS do | |
| 176 | local partyFrame = "PartyMemberFrame"..i | |
| 177 | _G[partyFrame]:SetScale(db.unitframes.party.scale) | |
| 178 | _G[partyFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE") | |
| 179 | _G[partyFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE") | |
| 180 | end | |
| 181 | end, | |
| 182 | ||
| 183 | arena = function(self) | |
| 184 | if not ArenaEnemyFrame1 then | |
| 185 | return true | |
| 186 | end | |
| 187 | ||
| 188 | for i = 1, MAX_ARENA_ENEMIES do | |
| 189 | local prepFrame = "ArenaPrepFrame"..i | |
| 190 | _G[prepFrame]:SetScale(db.unitframes.arena.scale) | |
| 191 | _G[prepFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE") | |
| 192 | _G[prepFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE") | |
| 193 | ||
| 194 | local arenaFrame = "ArenaEnemyFrame"..i | |
| 195 | _G[arenaFrame]:SetScale(db.unitframes.arena.scale) | |
| 196 | _G[arenaFrame.."HealthBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize,"THINOUTLINE") | |
| 197 | _G[arenaFrame.."ManaBarText"]:SetFont(db.media.fontNormal, db.unitframes.arena.fontSize, "THINOUTLINE") | |
| 198 | end | |
| 199 | end, | |
| 200 | ||
| 201 | boss = function(self) | |
| 202 | for i = 1, MAX_BOSS_FRAMES do | |
| 203 | local bossFrame = "Boss"..i.."TargetFrame" | |
| 204 | _G[bossFrame]:SetScale(db.unitframes.boss.scale) | |
| 205 | end | |
| 206 | end, | |
| 207 | ||
| 208 | } |